Created
June 9, 2024 18:10
-
-
Save mmguero/87fb8ca52a5b9642e88da8486ded6c54 to your computer and use it in GitHub Desktop.
ffmpeg to extract audio streams from video file according to language with different codecs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for FILE in *.mkv; do \ | |
echo "$FILE"; \ | |
for STREAM in $(ffprobe "$FILE" -loglevel error -show_entries stream=index:stream_tags=language -select_streams a -of compact=p=0:nk=1); do \ | |
export STREAM_ID=$(( $(echo "$STREAM" | cut -d'|' -f1)-1 )); \ | |
export STREAM_LANG="$(echo "$STREAM" | cut -d'|' -f2)"; \ | |
export STREAM_CODEC="$(ffprobe "$FILE" -loglevel error -select_streams a:"$STREAM_ID" -show_entries stream=codec_name -of csv=p=0)"; \ | |
mkdir -p "$STREAM_LANG"; \ | |
ffmpeg -hide_banner -loglevel error -y -i "$FILE" -map 0:a:m:language:"$STREAM_LANG" -vn -sn -c:a copy -map_metadata 0 ./"$STREAM_LANG"/"$(base "$FILE").$STREAM_LANG.$STREAM_CODEC"; \ | |
done; \ | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment