[FFmpeg-devel] Question Regarding Outputting Frames on Image/Video Formats with Non-Contiguous Storage of Frames
Anamitra Ghorui
aghorui at teknik.io
Thu Jul 2 09:05:30 EEST 2020
Hello,
I have written a decoder for a video (gif-like) format[1] which, due to
the nature of the format, is fed packets until it detects the end of
stream[2]. Until then, no frames are outputted and AVERROR(EAGAIN) is
returned.
After the stream is completely processed, the decoder starts to try to
output all the frames one by one. However, the decoder stops after the
first frame.
I am currently using doc/examples/decode_video.c for testing the
decoder. The concerned part is:
ret = avcodec_send_packet(dec_ctx, pkt);
if (ret < 0) {
fprintf(stderr, "Error sending a packet for decoding\n");
exit(1);
}
while (ret >= 0) {
ret = avcodec_receive_frame(dec_ctx, frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return;
else if (ret < 0) {
fprintf(stderr, "Error during decoding\n");
exit(1);
}
// Frame writing routines
// ...
}
In libavcodec/decode.c, decode_simple_internal(), the function exits
on the condition of (ret < 0 && ret != AVERROR_EOF), after outputting
the first frame as shown below:
if (!pkt->data && !avci->draining) {
av_packet_unref(pkt);
ret = ff_decode_get_packet(avctx, pkt);
if (ret < 0 && ret != AVERROR_EOF)
return ret;
}
What I am guessing is happening is that while the decoder is spitting
out frames in the while loop, calling avcodec_receive_frame causes the
last packet (the packet that the decoder will be on until all the
frames are outputted) is being unreferenced, and that causes the packet
to be freed and the aforementioned condition to fail.
At the end of doc/examples/decode_video.c, there is this call:
decode(c, frame, NULL, outfilename);
Which I think is the "draining" condition. However I don't think the
specific decode_frame is being called here
What should I do to mitigate this? Should I reference the packet within
the decoder until al the frames are outputted, or are there some special
routines for handling this condition that I don't know about?
[1]: https://flif.info/spec.html,
[2]: http://ffmpeg.org/pipermail/ffmpeg-devel/2020-March/258465.html
---
Regards,
Anamitra
More information about the ffmpeg-devel
mailing list