[Libav-user] Misuse of av_read_frame()'s return in the examples

Kolominsky, Ilia 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:

//signal drain
int ret = avcodec_send_packet(decData->m_DecCtx, nullptr);
if (ret)
{
	logErr("avcodec_send_packet() failed on stop, ret: %d", ret);
	return;
}
// drain loop
while (!ret)
{
	AVFrame *frame = av_frame_alloc();
	ret = avcodec_receive_frame(decData->m_DecCtx, frame);
	if (!ret)
	{
		processGoodFrame(frame, decData);
	}
	av_frame_free(&frame);
}
// flush buffers so the decoder can be reused
avcodec_flush_buffers(decData->m_DecCtx);


The complete API reference is here
https://ffmpeg.org/doxygen/3.1/group__lavc__encdec.html

The API works for me like a Swiss clock both with h264 and h264_cuvid decoders
BR


Ilia Kolominsky 
Software Architect
Software Group | TrueView
7 HaBarzel st.
Tel Aviv, Israel, 69710
Intel Corporation | intel.com


-----Original Message-----
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
https://ffmpeg.org/mailman/listinfo/libav-user

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 mailing list