[FFmpeg-devel] [PATCH 2/3] doc/examples/demuxing_decoding: convert to new decoding API

James Almer jamrial at gmail.com
Sat Apr 11 21:16:27 EEST 2020


On 4/11/2020 2:59 PM, Anton Khirnov wrote:
> Quoting James Almer (2020-04-11 19:46:03)
>> On 4/11/2020 12:06 PM, Anton Khirnov wrote:
>>
>> Instead of this, it might be better to call receive_frame() one time
>> after each call to send_packet(), regardless of the latter consuming the
>> packet or not. If it doesn't, then you just keep it around until at some
>> point a call will consume it, then you can fetch the next one.
>>
>> I say this because if you do
>>
>> ret = avcodec_send_packet(pkt);
>> av_packet_unref(pkt);
>> if (ret < 0)
>>     return ret:
>> do {
>>     ret = avcodec_receive_frame(frame);
>>     if (!ret)
>>         output_frame(frame):
>> } while (!ret);
>>
>> You'll be draining the decoders of all the frames it may have generated,
>> which may be detrimental in frame threading scenarios, versus something
>> like (Untested PoC):
>>
>> do {
>>     ret = avcodec_send_packet(pkt);
>>     if (ret < 0) {
>>         if (ret != AVERROR(EAGAIN))
>>             return ret;
>>     } else
>>         av_packet_unref(pkt);
>>     ret = avcodec_receive_frame(frame);
>>     if (ret < 0) {
>>         if (ret != AVERROR(EAGAIN))
>>             return ret;
>>     } else
>>         output_frame(frame);
>> } while (!ret || pkt->size);
>>
>> Which would constantly keep the decoder fed with packets as you retrieve
>> generated frames.
>>
>> This is something I've noticed when writing the libdav1d decoder
>> wrapper. I don't know if it also applies to our frame threading logic,
>> or if it depends on the decoder used, but if it does, then the CLI would
>> also benefit from this.
> 
> I don't know how libdav1d works, but lavc frame threading will not give
> you any output unless all the workers are busy, i.e. the delay imposed
> is constant and you cannot change it by calling the functions in a
> different pattern.
> 
> There was a patch to change that recently, but people were generally
> against it.
> 
> Also, the way I'm doing it in this patch -- one send_packet(), then
> iterate receive_frame() until failure -- is the officially recommended
> one in the doxy somewhere around the top of avcodec.h

Ok, if it's the recommended way described in the doxy then it makes
sense to use it in the examples, so LGTM if tested.


More information about the ffmpeg-devel mailing list