From 82df70eff06e7b44ee84283070d7f801f7fc1d92 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sat, 6 Nov 2021 20:25:45 -0400 Subject: initial commit --- .local/bin/ffmpeg-convert | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 .local/bin/ffmpeg-convert (limited to '.local/bin/ffmpeg-convert') diff --git a/.local/bin/ffmpeg-convert b/.local/bin/ffmpeg-convert new file mode 100755 index 0000000..171a97b --- /dev/null +++ b/.local/bin/ffmpeg-convert @@ -0,0 +1,60 @@ +#!/bin/sh + +# Converts audio/video files to a different specified container format with ffmpeg +# Depends on the youtube-filename-fixer script for cleaining up YouTube filenames + +usage() { + echo "usage: ffmpeg-convert [options] container video_codec audio_codec files" + echo "\npositional parameters" + echo "\tcontainer\textension of the container that is being converted to" + echo "\tvideo_codec\tvideo codec of the output file" + echo "\taudio_codec\taudio codec of the output file" + echo "\noptions" + echo "\t-d\tdelete original files after conversion" + echo "\t-h\tshow this help and exit" +} +stdin() { + while read -r infile + do + outfile="$(echo $infile | rev | cut -d '.' -f 2 | rev)$container" + echo "converting $infile -> $outfile..." + ffmpeg -nostdin -loglevel 16 -i "$infile" -c:v $video -c:a $audio "$outfile" + [ $delete -eq 1 ] && rm -v "$infile" + done +} +cli() { + for infile in $@ + do + outfile="$(echo $infile | rev | cut -d '.' -f 2 | rev)$container" + echo "converting $infile -> $outfile..." + ffmpeg -nostdin -loglevel 16 -i "$infile" -c:v $video -c:a $audio "$outfile" + [ $delete -eq 1 ] && rm -v "$infile" + done +} + +options=$(getopt -o 'dhs' -- "$@") +eval set -- "$options" +delete=0 +stdin=0 +while true +do + case $1 in + '-h') usage ; exit 0 ;; + '-d') delete=1; shift; continue ;; + '-s') stdin=1; shift; continue ;; + '--') shift; break;; + *) echo "internal error"; exit 1 ;; + esac +done +[ $# -ge 3 ] || (usage && exit 1) + +# Set variables specified on command line +container="$1"; shift; video="$1"; shift; audio="$1"; shift; + +# Prepend a dot to the container name if not specified already +[ "${container#.}" = "$container" ] && container=".$container" + +# If there is only one file argument and it is "-" +[ $stdin -eq 1 ] && stdin || cli $@ + + -- cgit v1.2.3