45 lines
999 B
Bash
Executable File
45 lines
999 B
Bash
Executable File
#!/bin/bash
|
|
#!/bin/bash
|
|
|
|
err_file="/tmp/getaudio_$$"
|
|
|
|
if [[ -z "$1" ]]; then
|
|
printf 'Need a filename of a video\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
input_file="$1"
|
|
if [[ ! -f "$input_file" ]]; then
|
|
printf "Can't read %s\n" >&2
|
|
exit 1
|
|
fi
|
|
|
|
base_path="$(dirname "$input_file" 2>"$err_file")"
|
|
err="$(<"$err_file")"
|
|
|
|
if [[ -n "$err" ]]; then
|
|
printf '%s\n' "$err" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# audio_ext="$(ffprobe "$input_file" 2>&1 | sed -nr 's/.*Audio: (...).*/\1/p')"
|
|
|
|
mediainfo_json="$(mediainfo --Output=JSON "$input_file")"
|
|
audio_codec="$(jq -r '.media.track[] | select(."@type"=="Audio") | .Format' <<< "$mediainfo_json")"
|
|
audio_ext="$(tr [:upper:] [:lower:] <<< "$audio_codec")"
|
|
|
|
if [[ -n "$2" ]]; then
|
|
if [[ "$2" == *.* ]]; then
|
|
audio_out="$2"
|
|
else
|
|
audio_out="${2}.${audio_ext}"
|
|
fi
|
|
else
|
|
out_file="$(basename ${input_file%%.*})"
|
|
audio_out="${base_path}/${out_file}.${audio_ext}"
|
|
fi
|
|
|
|
echo ffmpeg -i "$input_file" -vn -acodec copy "$audio_out"
|
|
ffmpeg -i "$input_file" -vn -acodec copy "$audio_out"
|
|
|