code cleanup
This commit is contained in:
parent
f5f0174b12
commit
6f8154153d
1 changed files with 12 additions and 20 deletions
32
to_opus.sh
32
to_opus.sh
|
@ -39,39 +39,31 @@ for file in **/*.@($extension); do
|
||||||
# array over the number of channels of all streams
|
# array over the number of channels of all streams
|
||||||
readarray -t channels <<<"$(ffprobe -v error -select_streams a -show_entries stream=channels -of compact=p=0:nk=1 "$file")"
|
readarray -t channels <<<"$(ffprobe -v error -select_streams a -show_entries stream=channels -of compact=p=0:nk=1 "$file")"
|
||||||
# array over the bitrates of all streams
|
# array over the bitrates of all streams
|
||||||
readarray -t bitrate <<<"$(ffprobe -v error -select_streams a -show_entries stream=bit_rate -of compact=p=0:nk=1 "$file")"
|
readarray -t bitrates <<<"$(ffprobe -v error -select_streams a -show_entries stream=bit_rate -of compact=p=0:nk=1 "$file")"
|
||||||
# number of audiostreams
|
# number of audiostreams
|
||||||
audiostreams=${#channels[@]}
|
audiostreams=${#channels[@]}
|
||||||
# check if it contains video streams (Thumbnails etc. will be ignored)
|
|
||||||
isvideo=$(ffprobe -v error -select_streams V -show_entries stream=codec_type "$file")
|
|
||||||
use_mkv="false"
|
|
||||||
command="ffmpeg -i \"$file\""
|
|
||||||
|
|
||||||
# use mkv, if multiple audiostreams exists or it is a videofile
|
|
||||||
if [[ ${#channels[@]} -gt 1 || -n "$is_video" ]]; then
|
|
||||||
command="$command -map 0 -map -0:d -c copy -c:a libopus"
|
|
||||||
use_mkv="true"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# set a channel dependend bitrate for every audio stream
|
# set a channel dependend bitrate for every audio stream
|
||||||
# https://wiki.xiph.org/Opus_Recommended_Settings
|
# https://wiki.xiph.org/Opus_Recommended_Settings
|
||||||
# to use ffmpegs default just comment out this block
|
# to use ffmpegs default just comment out this block
|
||||||
|
bitrate_settings=""
|
||||||
for ((index=0; index<audiostreams;index++)); do
|
for ((index=0; index<audiostreams;index++)); do
|
||||||
if [[ ${channels[index]} -eq 1 ]]; then
|
if [[ ${channels[index]} -eq 1 ]]; then
|
||||||
if [[ $bitrate == 'N/A' || ${bitrate[index]} -gt 64000 ]]; then command="$command -b:a:$index 64k"; fi
|
if [[ $bitrates == 'N/A' || ${bitrates[index]} -gt 64000 ]]; then bitrate_settings="$bitrate_settings-b:a:$index 64k "; fi
|
||||||
elif [[ ${channels[index]} -eq 2 ]]; then
|
elif [[ ${channels[index]} -eq 2 ]]; then
|
||||||
if [[ $bitrate == 'N/A' || ${bitrate[index]} -gt 128000 ]]; then command="$command -b:a:$index 128k"; fi
|
if [[ $bitrates == 'N/A' || ${bitrates[index]} -gt 128000 ]]; then bitrate_settings="$bitrate_settings-b:a:$index 128k "; fi
|
||||||
elif [[ ${channels[index]} -lt 6 ]]; then
|
elif [[ ${channels[index]} -lt 6 ]]; then
|
||||||
if [[ $bitrate == 'N/A' || ${bitrate[index]} -gt 256000 ]]; then command="$command -b:a:$index 256k"; fi
|
if [[ $bitrates == 'N/A' || ${bitrates[index]} -gt 256000 ]]; then bitrate_settings="$bitrate_settings-b:a:$index 256k "; fi
|
||||||
elif [[ $bitrate == 'N/A' || ${bitrate[index]} -gt 450000 ]]; then command="$command -b:a:$index 450k"; fi
|
elif [[ $bitrates == 'N/A' || ${bitrates[index]} -gt 450000 ]]; then bitrate_settings="$bitrate_settings-b:a:$index 450k "; fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "$use_mkv"
|
# check if it contains video streams (Thumbnails etc. will be ignored)
|
||||||
|
# use mkv for videos and for multiple audio streams
|
||||||
if [[ $use_mkv = "true" ]]; then
|
is_video=$(ffprobe -v error -select_streams V -show_entries stream=codec_type "$file")
|
||||||
command="$command -v info -hide_banner \"${file%.*}.mkv\""
|
if [[ ${#channels[@]} -gt 1 || -n "$is_video" ]]; then
|
||||||
|
command="ffmpeg -i \"$file\" -map 0 -map -0:d -map -0:t -c copy -c:a libopus $bitrate_settings -v info -hide_banner \"${file%.*}.mkv\""
|
||||||
else
|
else
|
||||||
command="$command -v info -hide_banner \"${file%.*}.opus\""
|
command="ffmpeg -i \"$file\" $bitrate_settings-v info -hide_banner \"${file%.*}.opus\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eval "$command" #&& rm "$file"
|
eval "$command" #&& rm "$file"
|
||||||
|
|
Loading…
Reference in a new issue