Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5883 closed defect (invalid)

libx264 fails to produce valid output with mp4 container

Reported by: Steve Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: libx264
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


I managed to find a video that causes ffmpeg to crash and produce invalid output, but only when producing an mp4 container -- the same transcode done with an mkv container works fine.

I first reproduced it with version (i.e from Fedora Core 23 repos), but it also happens with the latest version of ffmpeg (i.e. the 2-Oct-2016 build from

In the version, the error message is "Incomplete MB-tree stats file". In the latest version, the error message is "2nd pass has more frames than 1st pass".

Enclosed is the script that I used to transcode the video, and a short video that demonstrates the problem. The command line to run the script is:

./ "216 - Dancing above turbines.mpg" 1000 2000 "216 - Dancing above turbines.mp4"

Substitute mkv for mp4 in the target filename and it'll work.

Attachments (1) (799 bytes ) - added by Steve 6 years ago.
Transcoding script

Download all attachments as: .zip

Change History (7)

by Steve, 6 years ago

Attachment: added

Transcoding script

comment:1 by Steve, 6 years ago

Since the upload limit for attachments is 2.5 MB, and the video that reproduces the problem is 19 MB, I've put it on . See .

comment:2 by Carl Eugen Hoyos, 6 years ago

Resolution: invalid
Status: newclosed

You are lucky: If FFmpeg / x264 would not crash, you wouldn't know that the quality of your encode is completely broken.
You have to use the same output container format and the same audio options for both passes when doing two-pass encoding (if mov is involved).
For future tickets, please remember that we do not accept scripts, actual command lines together with their complete, uncut console output are required for valid tickets.

comment:3 by Carl Eugen Hoyos, 6 years ago

Keywords: libx264 added

comment:4 by Steve, 6 years ago

I never expected that the container format would affect the behavior of encoding the streams inside the container.

Perhaps the 2nd pass should have detected that and emitted a more descriptive error message, to avoid silently producing a "completely broken" encode.

comment:5 by Timo R., 6 years ago

I think both errors you got are very clear about the stats file being invalid for your second pass.

comment:6 by Steve, 6 years ago

But not why.

Note: See TracTickets for help on using tickets.