summaryrefslogtreecommitdiff
path: root/.local/bin/ffmpeg-convert
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/ffmpeg-convert')
-rwxr-xr-x.local/bin/ffmpeg-convert60
1 files changed, 60 insertions, 0 deletions
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 @@
1#!/bin/sh
2
3# Converts audio/video files to a different specified container format with ffmpeg
4# Depends on the youtube-filename-fixer script for cleaining up YouTube filenames
5
6usage() {
7 echo "usage: ffmpeg-convert [options] container video_codec audio_codec files"
8 echo "\npositional parameters"
9 echo "\tcontainer\textension of the container that is being converted to"
10 echo "\tvideo_codec\tvideo codec of the output file"
11 echo "\taudio_codec\taudio codec of the output file"
12 echo "\noptions"
13 echo "\t-d\tdelete original files after conversion"
14 echo "\t-h\tshow this help and exit"
15}
16stdin() {
17 while read -r infile
18 do
19 outfile="$(echo $infile | rev | cut -d '.' -f 2 | rev)$container"
20 echo "converting $infile -> $outfile..."
21 ffmpeg -nostdin -loglevel 16 -i "$infile" -c:v $video -c:a $audio "$outfile"
22 [ $delete -eq 1 ] && rm -v "$infile"
23 done
24}
25cli() {
26 for infile in $@
27 do
28 outfile="$(echo $infile | rev | cut -d '.' -f 2 | rev)$container"
29 echo "converting $infile -> $outfile..."
30 ffmpeg -nostdin -loglevel 16 -i "$infile" -c:v $video -c:a $audio "$outfile"
31 [ $delete -eq 1 ] && rm -v "$infile"
32 done
33}
34
35options=$(getopt -o 'dhs' -- "$@")
36eval set -- "$options"
37delete=0
38stdin=0
39while true
40do
41 case $1 in
42 '-h') usage ; exit 0 ;;
43 '-d') delete=1; shift; continue ;;
44 '-s') stdin=1; shift; continue ;;
45 '--') shift; break;;
46 *) echo "internal error"; exit 1 ;;
47 esac
48done
49[ $# -ge 3 ] || (usage && exit 1)
50
51# Set variables specified on command line
52container="$1"; shift; video="$1"; shift; audio="$1"; shift;
53
54# Prepend a dot to the container name if not specified already
55[ "${container#.}" = "$container" ] && container=".$container"
56
57# If there is only one file argument and it is "-"
58[ $stdin -eq 1 ] && stdin || cli $@
59
60