[FFmpeg-devel] how to use own buffers for input data with av_read_frame()

Jan Pohanka xhpohanka at gmail.com
Mon Sep 3 09:49:06 CEST 2012


> I guess "get a better hardware decoder" does not count as a helpful  
> answer, even though I do consider the problem here that the decoders are  
> technologically stuck about 10 years in the past when it was ok to  
> design hardware without bothering how messy it is for software to use.

Hardware decoder is a part of a SoC that we use in our product. Replacing  
it is not an option. On the other I think that the requirement of  
continuous buffer is reasonable as one need to transfer the data between  
MCU and codec memory using DMA. Especially on small chips running embedded  
linux this is probably easier than implementing more complex DMA.

>> I dont think that a single memcpy of the compressed data will have a
>> speed effect that could easily be meassured. Instead it will be
>> overshadowed by both obtaining this data from network/disk and the
>> actual decoding. If you still wish to avoid this memcpy you would have
>> to add some callback mechanism for the AVPacket allocation.
>> Such a optimization would of course be welcome in main ffmpeg if you
>> implement it and it sclean & simple & faster
> I think that such a solution is a very bad idea in this case.
> The fact that packet sizes vary a lot together with the fact that FFmpeg  
> can buffer quite a lot of them sometimes means you run into serious risk  
> of issues with memory fragmentation when you allocate and deallocate  
> them constantly as continuous physical memory regions.
> Depending on the details, some hack like using huge pages and only  
> copying when the buffer by bad luck crosses a page boundary _might_ be a  
> way to improve average performance...

I will probably stay with copying the input compressed data to own buffer  
within the decoder. It is most simple and as Michael said the speed effect  
shouldn't be so huge.

Providing own buffer for av_read_frame (something like if (pkt->data[0] !=  
NULL) {use it instead of allocating}) could be useful IMHO, but I give it  
up implementing this when I saw that there is some packet buffer logic and  
unfortunately I do not have a time to analyze it more deeply

best regards

More information about the ffmpeg-devel mailing list