[FFmpeg-devel] Problem with vstats file and frame number

Thierry Foucu tfoucu at gmail.com
Fri Nov 11 22:50:06 EET 2016


Hi,

Before sending you some patches to fix it, I would like to know how you
want this issue to be fixed.
Let me explain it:

When we enable vstats file to be generated, each line of the file contains
the frame number of the encoded video frames.
The frame number is the one from AVStream.nb_frames

See
https://github.com/FFmpeg/FFmpeg/blob/master/ffmpeg.c#L1345

The problem is that nb_frames is being incremented only when we succeed to
write the encoded frame  to the muxer.
https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/mux.c#L1270

But we get there only when the function interleave_packet does return 1,
which means a packet can be output.
If the function interleave_packet return 0, because no packet could be
output (waiting for some audio frames to be encoded for example), the
nb_frames is not incremented.

In this case, when we call do_video_stats, the AVStream.nb_frames was not
incremented and you will get a new entry in the file with the frame number
of the last video frames being written to the muxer.

Here are some ideas to fix it:
* Instead of using AVStream.nb_frames, used OutputStream.frame_number which
is incremented just before calling do_video_stats
See https://github.com/FFmpeg/FFmpeg/blob/master/ffmpeg.c#L1303
* Increment AVStream.nb_frames after calling interleave_packet by checking
(ret >= 0). But in this case, the nb_frames will be the number of frames
going through the interleave_packet but not the number of frames written to
the muxer.
* Add a new field in the AVStream, maybe call it nb_encoded_frame (similar
to nb_decoded_frames)
* any other suggestion?

Thanks.


More information about the ffmpeg-devel mailing list