[FFmpeg-devel] [PATCH 1/3] ffmpeg: use avformat_init_output to initialize output files

James Almer jamrial at gmail.com
Mon Nov 27 23:44:41 EET 2017


On 11/27/2017 6:25 PM, Michael Niedermayer wrote:
> On Sun, Nov 26, 2017 at 05:51:02PM -0300, James Almer wrote:
>> Postpone writing the header until the first output packet is ready to be
>> written.
>> This makes sure any stream parameter change that could take place while
>> processing an input frame will be taken into account when writing the
>> output file header.
>>
>> Signed-off-by: James Almer <jamrial at gmail.com>
>> ---
>>  fftools/ffmpeg.c | 31 ++++++++++++++++++++++++++-----
>>  fftools/ffmpeg.h |  3 +++
>>  2 files changed, 29 insertions(+), 5 deletions(-)
> 
> This changes (generates a file before, does not afterwards)
> ./ffmpeg  -i ~/tickets/5114/test_case.ivf -an -y test.mp4
> https://trac.ffmpeg.org/attachment/ticket/5114/test_case.ivf
> 
> ill see if i can find a failure that is more clear, as this one
> arguable doesnt produce a very usefull file

Note the log message you get after this patch: "Nothing was written into
output file 0 (test.mp4), because at least one of its streams received
no packets."

Before this patch, of->header_written was set to 1 after calling
avformat_write_header even if no header was really written (Because of
the delayed header code in lavf I'm removing in patch 2), so ffmpeg.c
instead of printing the above log would call av_write_trailer() which,
again, would trigger the delayed header code in lavf and write the
header and the trailer in one go, but no packets in between.

After this patch, where we used to call avformat_write_header we're now
calling avformat_init_output, so of->header_written is 0 at the time the
invalid input data error happens, and as such av_write_trailer is
effectively never called.


More information about the ffmpeg-devel mailing list