[Libav-user] Misuse of av_read_frame()'s return in the examples
ilia.kolominsky at intel.com
Mon Mar 11 10:37:56 EET 2019
In order to ensure the complete drainage of the decoding queue, the decoder must be flushed by sending an empty (or null) AVPacket to avcodec_send_packet().
The code can look something like that:
int ret = avcodec_send_packet(decData->m_DecCtx, nullptr);
logErr("avcodec_send_packet() failed on stop, ret: %d", ret);
// drain loop
AVFrame *frame = av_frame_alloc();
ret = avcodec_receive_frame(decData->m_DecCtx, frame);
// flush buffers so the decoder can be reused
The complete API reference is here
The API works for me like a Swiss clock both with h264 and h264_cuvid decoders
Software Group | TrueView
7 HaBarzel st.
Tel Aviv, Israel, 69710
Intel Corporation | intel.com
From: Libav-user [mailto:libav-user-bounces at ffmpeg.org] On Behalf Of Michel Rouzic
Sent: Monday, March 11, 2019 01:05
To: libav-user at ffmpeg.org
Subject: [Libav-user] Misuse of av_read_frame()'s return in the examples
Most of the examples provided in doc/examples stop decoding when
av_read_frame() returns a negative number, which can cause them to completely miss the last few frames of a video. I have verified that this is a problem with transcoding.c using this 300 frame video (with visually labelled frames for convenience)
https://photosounder.com/misc/drop_loop_300_frames_360p.mp4 and by running `./transcoding.exe drop_loop_300_frames_360p.mp4 transcoded.mp4`. In a properly-written video player the original video's last frame shows "299" as expected whereas the transcoding example claims that only 298 were transcoded and the transcoded video indeed shows the last frame as labelled "297". Transcoding the transcoded video outputs only 296 frames, doing that again outputs only 294 frames, and so on, so this is quite serious, and a quick `grep 'av_read_frame' *.c -C 3` in the examples folder seems to show that all the examples might be affected, so that would be great for everyone relying on the examples if this could be addressed.
I don't quite know how to fix this except that somehow some empty frames should be provided when av_read_frame() returns a negative value. FFplay does it properly (see line 3007 of fftools/ffplay.c) however its code lacks the genericness and clarity of the examples which makes it hard to learn how to change the examples or my own code from it.
Libav-user mailing list
Libav-user at ffmpeg.org
To unsubscribe, visit link above, or email libav-user-request at ffmpeg.org with subject "unsubscribe".
Intel Israel (74) Limited
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
More information about the Libav-user