Smooth scrubbing videos, version 2

!
Warning: This post is over 365 days old. The information may be out of date.

This is an update to the original blog post. I decided to write this quick update blog post because I found some new resources and techniques on re-encoding to get a smooth scrubbing video.

ProRes?

Apple’s ProRes stores video frames “uncompressed”, which means computers don’t have to spend a ton of time decoding them, compared to other compressed codecs like H264 and so on.

Here’s an example command that you can use quickly:

ffmpeg -i input.mp4 \   # input file
  -c:v prores_ks    \   # ProRes encoder to use (prores and prores_aw exists, BUT)
  -profile:v 3      \   # ProRes profile to use (see below)
  -qscale:v 11      \   # The "quality" of the output (9-11 is a good range; lower is better)
  -vendor apl0      \   # Tricks Apple programs
  output.mov            # Must be a container that supports ProRes (the other two being mkv and mxf)

Encoder

Do not use prores or prores_aw. I know it’s shown as an option above, but the two implementations are slow and bad. Just use prores_ks.

Profile

ffmpeg ProRes profiles are mapped to the following integer values:

  • proxy - 0
  • lt - 1
  • standard - 2
  • hq - 3
  • 4444 - 4
  • 4444xq - 5

Use 3, unless you need 4:4:4 over 4:2:2 chroma subsampling. In which case you will also need to pass in the -pix_fmpt yuva444p101e parameter. (If you don’t what this means use 3 or below.)

qscale

This parameter is discussed in the documentation below, but brass tacks for fast reading:

  • 0 is the best, 32 is the worst
  • Recommended: 9-13
  • Overkill (space is of no concern): 5 or below
  • Warning: approaching 0 will cause the video file to be unplayable as it would be too big for machines to handle!

I got this command from the official ffmpeg documentation, so if you need more details go check it out there.

And unfortunately, unlike the H264 method below, I have been unable to use hardware accelerated encoders on ProRes, as it keeps giving me a weird, nonsensical error each time I attempt it. If you know how to fix this please leave a comment and I’ll update this section!

H264

I need to make a slight correction to making smooth-scrubbing H264 videos.

After reading ffmpeg’s official documentation, to get the smoothest scrubbable videos, you need to eliminate the P-frames as well as the B-frames. And here’s the updated command to do so:

ffmpeg -i input.mp4 \   # input file
  -c:v libx264      \   # H264 encoder
  -profile:v main   \   # H264 profile
  -g 1              \   # Eliminate P frames
  -crf 9            \   # The "quality" of the output (7-11 is a good range; lower is better)
  -bf 0             \   # Eliminate B frames
  -vendor apl0      \   # Tricks Apple programs
  output.mp4

And a quick last pro-tip: if you have an Apple Silicon Mac, you can use hardware acceleration to speed up the video encoding! Just replace -c:v libx264 with -c:v h264_videotoolbox, and replace the -crf 9 parameter with -b:v 8000k (as the encoder only supports constant bitrate settings and not crf). Adjust the value as necessary, depending on the source file.

OK I said last tip but this is really the last one: check out ffpb as it gives you a progress bar for ffmpeg jobs!

Related Posts

comments