#!/bin/sh if [ -z "$(command -v ffmpeg)" ]; then echo "ffmpeg required." exit fi _transcode () { ## Zsh compatibility. We need it otherwise word splitting of parameter like ## TC_SAMPLE will not work. STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')" [ "$STATUS" = "off" ] && set -o shwordsplit ffmpeg -i "$@" \ -c:v libx264 -preset slow -crf 20 \ -c:a libvorbis -b:a 192k -ac 2 \ -c:s copy \ -map 0 \ $TC_SAMPLE \ "${1%.*}-$(date '+%F-%H%M%S').mkv" ## Restore Zsh previous options. This will not turn off shwordsplit if it ## was on before calling the function. [ "$STATUS" = "off" ] && set +o shwordsplit } _printhelp() { cat <). ## preset ~= speed and quality*size ~= 1/speed ## ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo ## Recommended values: faster -- slow ## slow is approx. two times slower than fast, and reduces the size by approx. 10%. ## ## x264 overall quality (-crf) is a logarithmic scale. ## 18 is near perfection. ## 22 is really good compression, while a bit more blurry than the original. ## 20 is a good compromise. ## ## x264 tuning (-tune ). ## Possible values: film, animation, grain, ... ## See x264 --fullhelp. ## No tuning by default. ## ## x264 options (-x264opts me=). ## Possible values: hex, umh... ## me=umh is default. ################################################################################ ################################################################################ ## FALLACIOUS INPUT ## ## In general, FFmpeg is not so good at copying fallacious streams. Reecoding ## video and audio streams helps a lot. ## ## "Can't write packet with unknown timestamp" ## Put '-fflags genpts' before the input command. ################################################################################ ################################################################################ ## MISC ## 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 ################################################################################