#!/bin/sh _printhelp() { cat </dev/null; then echo "ffmpeg required." exit fi _transcode () { ## Zsh compatibility. We need it otherwise word splitting of parameter will ## not work. STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')" [ "$STATUS" = "off" ] && set -o shwordsplit ## You can choose here to process all files at the same time. Useful if you ## need to remux streams or to concatenate. # ffmpeg -i ###FILELIST \ ffmpeg -nostdin -i "$@" \ -c:v libx264 -preset slow -crf 20 \ -c:a libvorbis -b:a 192k -ac 2 \ -c:s copy \ -map 0 \ $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 } ## Choose to process all files one after another. while IFS= read -r i; do _transcode "$i" done<). ## 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 ################################################################################