Opened 22 months ago

Closed 22 months ago

Last modified 21 months ago

#5883 closed defect (invalid)

libx264 fails to produce valid output with mp4 container

Reported by: ulatekh 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 ulatekh 22 months ago.
Transcoding script

Download all attachments as: .zip

Change History (7)

Changed 22 months ago by ulatekh

Transcoding script

comment:1 Changed 22 months ago by ulatekh

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 Changed 22 months ago by cehoyos

  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 22 months ago by cehoyos

  • Keywords libx264 added

comment:4 Changed 21 months ago by ulatekh

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 Changed 21 months ago by oromit

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

comment:6 Changed 21 months ago by ulatekh

But not why.

Note: See TracTickets for help on using tickets.