scripts/video-convert.sh

57 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
scale=
crf=23
rate=
output=output.mp4
while getopts "hs:r:c:o:" flag
do
case $flag in
h)
echo "Usage: $0 [options] <file>..."
echo "-o <output-file> : Output file name"
echo "-s <width> : Image size (720p => 1280, 1080p => 1920…)"
echo "-r <rate> : Frame rate"
echo "-c <crf> : Quality factor (default 23, use 17-28, max range 0-51)"
exit
;;
o)
output=${OPTARG}
;;
s)
scale=${OPTARG}
;;
r)
rate=${OPTARG}
;;
c)
crf=${OPTARG}
;;
esac
done
shift "$((OPTIND-1))"
count=0
intput=()
vids=""
concat=""
for arg in "$@"
do
input[$((2*$count))]="-i"
input[$((2*$count+1))]=${arg}
if [ x"$scale" != x"" ] ; then
vids="$vids [$count:v:0] scale=$scale:$scale:force_original_aspect_ratio=decrease [v$count] ;"
concat="$concat [v$count] [$count:a:0]"
else
concat="$concat [$count:v:0] [$count:a:0]"
fi
count=$((count + 1))
done
filter="$vids $concat concat=n=$count:v=1:a=1 [v] [a]"
if [ x"$rate" != x"" ] ; then
rate="-r $rate"
fi
ffmpeg "${input[@]}" -filter_complex "$filter" -map "[v]" -map "[a]" $rate -c:v libx264 -preset medium -crf $crf -c:a libfdk_aac -b:a 128k -map_metadata 0:g "$output"
# for i in *.mov ; do ~/scripts/video-convert.sh -o ${i/mov/mkv} $i ; done