I'd like to be able to duplicate what HandBrake does using libav directly.

Here's what I've got so far, to duplicate my setup:

  • x264 slow preset, high profile, level 4.1, CRF 14
  • 60 fps
dvd_copy dvd.iso -c 1-1 -o - | avconv -y -i - -vcodec libx264 -acodec libfdk_aac -tune animation -ab 160k -r 60 -vsync cfr -crf 14 -x264-params ref=10:subme=8:trellis=2:keyint=240:rc-lookahead=50:direct=auto -bufsize 78125k -maxrate 62500k -t 1 -color_primaries smpte170m -color_trc smpte170m -colorspace smpte170m dvd_encode.mkv

Note that Handbrake will set the colorspace to BT.709 if it doesn't recognize what it is (source: I lost it, but I remember it being verified by a second one).

See here for the same scenario I was running into – comparing mediainfo output from a HandBrake encode to a direct ffmpeg one.

I can't figure out how to use my own avpreset files which is annoying, but then I thought about how it's probably a good thing to have one less file to track when making changes, so oh well. :)


  • detect and apply cropping
  • detelecining
  • setting SAR and DAR


  • a way to rip VobSub as well
  • MKV chapters

Other than the todo list, it works great. :) Proof-of-concept invented!

Related libav documentation I had open in a file:

fieldorder - Transform the field order of the input video.

The transformation is done by shifting the picture content up or down by one line, and filling the remaining line with appropriate picture content. This method is consistent with most broadcast field order converters.

fps - Convert the video to specified constant framerate by duplicating or dropping frames as necessary.

scale - Scale the input video and/or convert the image format.

setdar - Set the Display Aspect Ratio for the filter output video.

setsar - Set the Sample (aka Pixel) Aspect Ratio for the filter output video.

showinfo - Show a line containing various information for each input video frame. The input video is not modified.

yadif - Deinterlace the input video ("yadif" means "yet another deinterlacing filter").

avconv -i h264.mp4 -c:v copy -bsf:v h264_mp4toannexb -an out.h264


https://github.com/HandBrake/HandBrake/issues/780 - Jun 9, 2017

HandBrake uses bt.709 for untagged HD video

https://video.stackexchange.com/questions/16840/ffmpeg-explicitly-tag-h-264-as-bt-601-rather-than-leaving-unspecified (2016)

ffmpeg -i input  \
-color_primaries smpte170m -color_trc smpte170m -colorspace smpte170m