Last active
October 6, 2022 04:42
-
-
Save tytydraco/83fd7f0c0ac13415c8a150d1610a6cd5 to your computer and use it in GitHub Desktop.
A bash script to extract audio from a container.
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
#!/usr/bin/env bash | |
trap 'echo Ignoring' INT | |
get_codec_name() { | |
ffprobe "$1" \ | |
-v quiet \ | |
-show_streams \ | |
-select_streams a \ | |
-show_entries stream=codec_name \ | |
| grep codec_name \ | |
| awk -F'=' '{ print $2 }' \ | |
|| exit 1 | |
} | |
ext_from_codec() { | |
case "$1" in | |
"aac") | |
echo "m4a" | |
;; | |
"vorbis") | |
echo "ogg" | |
;; | |
*) | |
echo "$1" | |
;; | |
esac | |
} | |
codec_name="$(get_codec_name "$1")" | |
ext="$(ext_from_codec "$codec_name")" | |
filename="$(basename -- "$1")" | |
filenameNoExt="${filename%.*}" | |
dir="$(dirname "$1")" | |
new="$dir/$filenameNoExt.$ext" | |
[[ -f "$new" ]] && exit 0 | |
echo "Extracting audio for $1" | |
ffmpeg -hide_banner -v error -nostats -nostdin -i "$1" -c:a copy -x -o "$new" || exit 1 | |
rm "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Designed to be used in https://github.com/tytydraco/meow_dart. Pass in like this:
meow_dart ... -c ./extract_audio