#!/bin/sh ################################################################################ ## User options ################################################################################ ## To check what fmmpeg supports: # ffmpeg -codecs # ffmpeg -formats ## Useful guides ## x264: http://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide ## ID3 details: http://en.wikipedia.org/wiki/ID3 TC_VIDEO_AUDIO_QUAL=192k ## quality*size ~= 1/speed # ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo TC_VIDEO_PRESET=slow ## Overall quality. Logarithmic scale. # 18 is near perfection. # 22 is really good compression, while a bit more blurry than the original. # 20 is a good compromise. TC_VIDEO_QUAL=20 ## x264 tuning (presets). ## Possible values: film, animation, grain, ... ## See x264 --fullhelp. ## No tuning by default. # TC_VIDEO_TUNE="-tune film" TC_VIDEO_TUNE="" ## x264 options. ## Possible values: hex, umh... ## me=umh is default. # TC_VIDEO_OPTS="-x264opts me=hex" TC_VIDEO_OPTS="" ################################################################################ ## End of user options ################################################################################ ## TODO: option to replace original file. ## TODO: audio quality. Copy if AAC or OGG <320k. ## TODO: crop options. ## TODO: handle srt encoding. ## TODO: separate functions: ## tc_video_batch ## tc_video_transcode if [ -z "$(command -v ffmpeg)" ]; then echo "ffmpeg required." exit fi _printhelp() { cat <&1 | grep -c 'Stream') for i in $(seq 0 $STREAM_NUM); do STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= " done # echo "$STREAM_NUM[$STREAM_TITLE]" fi ffmpeg $TC_OVERWRITE $TC_SAMPLE -i "$1" \ -c:v libx264 -preset $TC_VIDEO_PRESET -crf $TC_VIDEO_QUAL $TC_VIDEO_TUNE $TC_VIDEO_OPTS \ -c:a libvorbis -b:a $TC_VIDEO_AUDIO_QUAL -ac 2 \ -c:s copy \ -map 0 $STREAM_TITLE \ $TC_USER_OPT "${1%.*}-$(date '+%F-%H%M%S').mkv" } for i in "$@"; do ## Argument is a folder. We search for all video files in there. if [ -d "$i" ]; then ## TODO: provide max-depth as option. while read -r j; do _tc_transcode $j done <