FFmpeg wrapper mini HowTo [audio & sub track selection]

Hi All,
I'm writing this post because i made a FFmpeg wrapper for myself in order to enable audio & sub track selection and i'd like to share it in case someone is interested.I made it because i was frustrated by the fact that i could not watch my movies the way i'd liked to => original audio track and subtitles. So firstly i'd like to thank the dev team of serviio because this software is simply great out of the box and it can be fastly greater because it's heavy customizable
; secondly i'd like to thank the community of serviio which is very active so it's easy to find a solution to a problem quickly.
Here is my FFmpeg wrapper based on those of 2 members found in this thread -> http://forum.serviio.org/viewtopic.php?f=11&t=6688
It does the job perfectly anytime on Full HD, HD Ready and SD movies
but it requires a powerfull computer ! (the input file must be transcoded otherwise the wrapper will be simply skipped by serviio)
For those who want to further investigate subtitles hardcoding using FFmpeg, you can read this article : http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20burn%20subtitles%20into%20the%20video
IMPORTANT NOTES :
- For this wrapper to work you NEED to build the git version of FFmpeg in order to have a build that implements the filter_complex argument
- Subtitles MUST be *.PGS, *.IDX/*.SUB and muxed into the input file ("picture based" subtitles)
- To install it, please follow the procedure described by patters in this thread : http://forum.serviio.org/viewtopic.php?f=11&t=6688
VoilĂ , that's it !
I'm writing this post because i made a FFmpeg wrapper for myself in order to enable audio & sub track selection and i'd like to share it in case someone is interested.I made it because i was frustrated by the fact that i could not watch my movies the way i'd liked to => original audio track and subtitles. So firstly i'd like to thank the dev team of serviio because this software is simply great out of the box and it can be fastly greater because it's heavy customizable

Here is my FFmpeg wrapper based on those of 2 members found in this thread -> http://forum.serviio.org/viewtopic.php?f=11&t=6688
- Code:
#!/bin/sh
#variables for selecting audio & sub tracks
#for each one 0 means the first of its type
#TYPE=0 selects the first track of type "TYPE"
#"TYPE" can match an audio or a sub track
AUDIO=0
SUBS=1
# for details on this loop see the thread i mentioned above -> credit goes @patters
PARAMS=""
INPUT=0
for PARAM in "$@"; do
if [ ${INPUT} = 1 ]; then
PARAMS="${PARAMS} \"${PARAM}\""
INPUT=0
else
PARAMS="${PARAMS} ${PARAM}"
fi
if [ "${PARAM}" == "-i" ]; then
INPUT=1
fi
done
#Here the wrapper substitutes a part of the FFmpeg serviio output and replaces it -> that's it's purpose
#Credit of the subtitution technique goes again @patters
#This part will have 2 effects : -to select 1 particular audio and 1 particular sub track of the input file
# -to hardcode on-the-fly a matching sub stream to the video (subs will be burned into the video)
PARAMS="`echo ${PARAMS} | sed -e "s| -map 0:0 -map 0:1| -filter_complex '[0:v:0][0:s:${SUBS}]overlay[v]' -map [v] -map '0:a:${AUDIO}'|"`"
#Here it sends back the modified arguments to FFmmpeg
#Credits of this part go to soundcheck and patters too
BIN="$(which ffmpeg)"
FOLDER="`dirname $0`"
echo "${BIN} ${PARAMS}" > ${FOLDER}/../log/ffmpeg-wrapper-tracks-selector.log
eval ${BIN} ${PARAMS}
exit $?
It does the job perfectly anytime on Full HD, HD Ready and SD movies

For those who want to further investigate subtitles hardcoding using FFmpeg, you can read this article : http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20burn%20subtitles%20into%20the%20video
IMPORTANT NOTES :
- For this wrapper to work you NEED to build the git version of FFmpeg in order to have a build that implements the filter_complex argument
- Subtitles MUST be *.PGS, *.IDX/*.SUB and muxed into the input file ("picture based" subtitles)
- To install it, please follow the procedure described by patters in this thread : http://forum.serviio.org/viewtopic.php?f=11&t=6688
VoilĂ , that's it !