Orginial function was converting m4a and wma files to OGG Vorbis. Function changed to convert to opus and change name to match.
38 lines
1.4 KiB
Fish
38 lines
1.4 KiB
Fish
function audio_to_opus -d "Convert m4a,wma files to opus"
|
|
argparse 'h/help' 'd/delete' 'y/dryrun' -- $argv
|
|
|
|
if set -q _flag_help
|
|
echo "usage: audio_to_opus [-h | --help] [-d | --delete]"
|
|
echo "Convert all m4a, wma files to Ogg Vorbis using ffmpeg."
|
|
echo "Traverses the whole directory structure starting from the working directory."
|
|
echo "-y,--dry-run Goes through all the process but doesn't actually make any conversion, logging the command that would be executed on each file."
|
|
echo "-d,--delete Delete original file after conversion"
|
|
echo "-h,--help display this help message"
|
|
return 0
|
|
end
|
|
|
|
set stats 0
|
|
|
|
for i in **.wma **.m4a
|
|
set audio_path $(path resolve $i)
|
|
set dir_path $(path dirname $audio_path)
|
|
set file_name $(path basename -E $audio_path)
|
|
set out_path "$dir_path/$file_name.ogg"
|
|
echo Converting $audio_path to $out_path
|
|
set stats $(math "$stats + 1")
|
|
if set -q _flag_dryrun
|
|
echo "ffmpeg -i $audio_path -map 0:a:0 -c:a libopus -b:a 130000 $out_path"
|
|
else
|
|
ffmpeg -i $audio_path -map 0:a:0 -c:a libvorbis -qscale:a 8 $out_path
|
|
end
|
|
if set -q _flag_delete && test $status -eq 0
|
|
if set -q _flag_dryrun
|
|
echo "rm $audio_path"
|
|
else
|
|
rm $audio_path
|
|
end
|
|
end
|
|
end
|
|
|
|
echo "File converted: $stats"
|
|
end
|