Opened 3 years ago

Closed 3 years ago

#9052 closed defect (invalid)

Concat frozen frames with audio

Reported by: Toke Stuart Jepsen Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

When using concatenation on videos with audio, the concatenated video has frozen frames.

How to reproduce:

  1. Produce three video files to concatenate:
ffmpeg -y -v 9 -loglevel 99 -f lavfi -i testsrc=duration=1.0:size=960x540:rate=25 -f lavfi -i sine=frequency=1000:duration=1.0 -pix_fmt yuv420p temp0.mov
ffmpeg -y -v 9 -loglevel 99 -f lavfi -i testsrc=duration=1.0:size=960x540:rate=25 -f lavfi -i sine=frequency=1000:duration=1.0 -pix_fmt yuv420p temp1.mov
ffmpeg -y -v 9 -loglevel 99 -f lavfi -i testsrc=duration=1.0:size=960x540:rate=25 -f lavfi -i sine=frequency=1000:duration=1.0 -pix_fmt yuv420p temp2.mov
  1. Concatenate all three video files together:
ffmpeg -y -v 9 -loglevel 99 -i temp0.mov -i temp1.mov -i temp2.mov -filter_complex "[0:0] [0:1][1:0] [1:1][2:0] [2:1]concat=n=3:v=1:a=1 [v] [a]" -map [v] -map [a] temp.mov
  1. Validate frame length:
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 temp.mov

Frame count is 76, but should be 75. Frozen frames are only introduced when the videos have audio. Video only files concatenate without frozen frames.

This reproducible is done with the filter method from https://trac.ffmpeg.org/wiki/Concatenate, but the demuxer method suffers from the same bug. Demuxer method cannot be validated by ffprobe though, but frozen frames can be seen in an editorial software (tested in NukeStudio and Resolve).

A python script for running through the reproducible can be found here; https://gist.github.com/tokejepsen/551afac5728e36bda4c7a9e71087d860.

Change History (3)

comment:1 by Cigaes, 3 years ago

By default, ffmpeg will use AAC in MOV. Since AAC uses frames of 1024 samples, your test files have 45056, not 44100, making them 1.02168 seconds. The extra 0.02168, combined with the fact that the MOV muxer does not support variable frame rate, explains the extra frame.

There are several ways of fixing this, depending on your use case. If you control your intermediate files, use a codec that does not add samples. If not, insert the trim filter to fix the duration before concatenation.

in reply to:  1 comment:2 by Toke Stuart Jepsen, 3 years ago

Replying to Cigaes:

By default, ffmpeg will use AAC in MOV. Since AAC uses frames of 1024 samples, your test files have 45056, not 44100, making them 1.02168 seconds. The extra 0.02168, combined with the fact that the MOV muxer does not support variable frame rate, explains the extra frame.

There are several ways of fixing this, depending on your use case. If you control your intermediate files, use a codec that does not add samples. If not, insert the trim filter to fix the duration before concatenation.

Thank you for the quick answer.

We are looking parallelize our encoding to spread the workload to multiple machines, so was under the impression that we need the destination codec on each intermediate file for concatenation to work with the demuxer method?

We do have control over the intermediate files, so which codec would you recommend that can handle audio as well?

comment:3 by Carl Eugen Hoyos, 3 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.