A collection of shell scripts, both useful and purely recreational.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Scripts/cvrt

82 lines
1.8 KiB

#!/bin/sh
print_help() {
cat << EOF
Usage: cvrt [infiles...] [FFMPEG options] [outfile/extension]
Options
-h Print this help screen
-e Edit the cvrt script (add defaults)
-d Delete infiles after processing (DANGEROUS!)
-* Other FFMPEG options (ie. -c:v libx264)
EOF
exit 0
}
# Universal FFMPEG options
OPT=" -hide_banner -loglevel error -stats"
declare -a FILES=()
[ -z $EDITOR ] && EDITOR=nano
# Find file list
i=1
while [ $i -le $# ]; do
case "${!i}" in
-e) $EDITOR `readlink -f "$0"`; exit 0 ;;
-d) DELETE=true ;;
-h) print_help ;;
-*) OPT="$OPT ${!i} ${@:$((i+1)):1}"; ((i++)) ;;
*) FILES+=( "${!i}" ) ;;
esac
((i++))
done
# Error check
[ -z "${FILES[1]}" ] && print_help
[ -n "$DELETE" ] && echo "WARNING: Your infiles will be DELETED!"
# Get outfile and extension
OUTFILE="${FILES[-1]}"
unset "FILES[-1]"
echo "$OUTFILE" | grep -q "." && EXT="${OUTFILE##*.}" || EXT="$OUTFILE"
# Custom defaults
case "$EXT" in
*flac) OPT="-vn $OPT" ;;
*mov) OPT="-c:v mpeg4 -q:v 0 -pix_fmt yuv420p -c:a pcm_s16le $OPT" ;;
*mp4) OPT="-c:v libx264 -crf 21 -c:a libopus -b:a 320k $OPT" ;;
esac
# Concatenate files
if ([ $EXT != $OUTFILE ] && [ -n "${FILES[1]}" ]); then
echo "Attempting to concatenate infiles into $OUTFILE"
echo "# Generated by cvrt" > mylist.txt
for i in "${FILES[@]}"; do
i="${i//\'/\'\\\'\'}"
echo "file '$i'" >> mylist.txt
done
ffmpeg -f concat -safe 0 -i mylist.txt $OPT $OUTFILE
if [ -n "$DELETE" ]; then
for i in "${FILES[@]}"; do
rm "$i"
done
fi
rm mylist.txt
exit 0
# Single infile --> outfile
elif ([ $EXT != $OUTFILE ] && [ -z "${FILES[2]}" ]); then
ffmpeg -i "${FILES[0]}" $OPT "$OUTFILE"
[ -n "$DELETE" ] && rm "${FILES[0]}"
exit 0
fi
# Multiple infiles ---> outfiles
for i in "${FILES[@]}"; do
ffmpeg -i "$i" $OPT "${i%.*}.$EXT"
[ -n "$DELETE" ] && rm "$i"
done
exit 0