2
votes

I've been struggling with encoding videos using FFMPEG and x264. The output stutters when played back in Quicktime, while in VLC it shows a lot of compression artifacts at the same places Quicktime stutters. So it seems like Quicktime is stuttering because it's trying to suppress the corruption/artifacts.

The videos have a lot of random motion in them, including frames where 75% of the pixels will change at a random interval (the video is software generated so it's truly pseudo-random). The compression seems to be choking in these places where it's likely detecting a "scene cut" incorrectly. It also seems to choke at regular intervals where I guess it's doing a keyframe.

I've based my encoding preset off of the x264-hq preset that comes with FFMPEG. I've tried turning off scene cut detection, and playing with the keyint/g and keyint_min options. Setting g to 1 makes it work, but blows out the filesize. I've tried the lossless presets, but they won't playback at all in Quicktime. Oddly, I haven't had any problems when working with a lower-resolution test video (1440x810).

Here's the preset I have right now, which works, but yields a file that's approximately 60% larger than the (non-working) hq preset yields. Is there any way to improve upon this? The filesize doesn't matter much, I just want something that will playback anywhere and be very high quality.

coder=1
flags=+loop
cmp=+chroma
partitions=+parti8x8+parti4x4+partp8x8+partp4x4+partb8x8
me_method=umh
subq=8
me_range=16
g=1
keyint_min=1
sc_threshold=0
i_qfactor=0.71
b_strategy=1crf=20
qcomp=0.6
qmin=20
qmax=51
qdiff=4
bf=16
refs=4
trellis=1
flags2=+dct8x8+wpred+bpyramid+mixed_refs
wpredp=2

Here's the command:

ffmpeg \
  -r 60 -i "frame-%06d.tiff" \
  -vcodec libx264 -vpre my_preset \
  -threads 0 \
  -r 60 -an -f out.mp4
1

1 Answers

2
votes

Use multi-pass encoding if possible, this will give H264 a chance to detect scene changes and prepare for them.

Why are you setting your sc_threshold to zero?

Don't be too tolerant of large file sizes, stuttering can happen if the instantaneous bitrate exceeds the transfer rate of the storage device (including network). 1080p content should be easily encoded in under 10mbit/sec.