Created
February 17, 2012 04:52
-
-
Save tyru/1850771 to your computer and use it in GitHub Desktop.
ffmpeg-split-audio - 色んなフォーマットの動画から音声を抽出
This file contains 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
#!/bin/sh | |
# | |
# Original script from http://linuxos.blog102.fc2.com/blog-entry-131.html | |
QUIET=true | |
die() { | |
echo "$@" >&2 | |
exit 1 | |
} | |
ask() { | |
msg="$1" | |
default="$2" | |
echo -n "$msg" | |
# input | |
read answer || answer="$default" | |
[ "$answer" ] || answer="$default" | |
# check | |
[ "$(echo "$answer" | sed 's/^y\(es\|eah\|ep\)\?.*//i')" = '' ] | |
} | |
do_ffmpeg() { | |
input="$1" | |
output="$2" | |
if [ -e "$output" ] && ! ask "File '$output' already exists. Overwrite? [y/N] " 'N'; then | |
echo "[skip] $output" >&2 | |
return 1 | |
fi | |
if $QUIET; then | |
ffmpeg -y -i "$input" -vn -acodec copy "$output" >/dev/null 2>/dev/null | |
else | |
ffmpeg -y -i "$input" -vn -acodec copy "$output" | |
fi | |
echo "[done] $output" | |
return 0 | |
} | |
while [ $# -ne 0 ]; do | |
case "$1" in | |
--) shift; break ;; | |
-v|--verbose) QUIET=false ;; | |
-*) die "error: unknown option '$1'" ;; | |
*) break ;; # found non-option argument. | |
esac | |
shift | |
done | |
for arg; do | |
noext="$(basename "$arg" | sed 's/\.[^.]\+$//')" | |
ext="$(basename "$arg" | sed 's/.\+\.\([^.]\+\)$/\1/')" | |
# no match -> empty string | |
[ "$ext" = "$(basename "$arg")" ] && ext= | |
# upper case -> lower case | |
ext="$(echo "$ext" | tr '[:upper:]' '[:lower:]')" | |
if [ "$ext" = "webm" ]; then | |
# WebM | |
do_ffmpeg "$arg" "$noext.ogg" | |
elif [ "`file "$arg" --mime-type | grep x-flv`" ]; then | |
# FLV | |
do_ffmpeg "$arg" "$noext.mp3" | |
elif [ "`file "$arg" --mime-type | grep mp4`" ]; then | |
# MP4 | |
do_ffmpeg "$arg" "$noext.aac" | |
elif [ "`file "$arg" --mime-type | grep asf`" ]; then | |
# ASF | |
do_ffmpeg "$arg" "$noext.wma" | |
elif [ "`file "$arg" --mime-type | grep msvideo`" ]; then | |
# MSVIDEO | |
do_ffmpeg "$arg" "$noext.mp3" | |
else | |
echo "error: Couldn't find audio data: $arg" >&2 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment