====== ffprobe - Subtitles - Extract all subtitles ======
Start with getting mapping of subtitle indexes to languages:
mappings=`ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "Movie-1080p.mkv"
echo ${mappings}
returns:
2,eng
3,eng
4,spa
Then, substitute ${idx} & ${lang} with mapping values, e.g.:
ffmpeg -nostdin -hide_banner -loglevel quiet -i "Movie-1080p.mkv" -map 0:"${idx}" "Movie-1080p_${lang}_${idx}.srt"
----
===== Using Bash =====
function subs() {
movie="${1}"
filename="${1%.*}"
mappings=`ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "${movie}"`
OLDIFS=$IFS
IFS=,
( while read idx lang
do
echo "Exctracting ${lang} subtitle #${idx} from ${movie}"
ffmpeg -nostdin -hide_banner -loglevel quiet -i "${movie}" -map 0:"$idx" "${filename}_${lang}_${idx}.srt"
done <<< "${mappings}" )
IFS=$OLDIFS
}
subs "$1"
**NOTE:** Example of command:
bash subs.sh Movie-1080p.mkv