[FFmpeg-devel] [PATCHv2] avcodec/utils: do not reallocate packet buffer for AV_CODEC_ID_WRAPPED_AVFRAME

Marton Balint cus at passwd.hu
Wed Feb 22 00:52:56 EET 2017


On Tue, 21 Feb 2017, wm4 wrote:

> On Mon, 20 Feb 2017 21:11:50 +0100 (CET)
> Marton Balint <cus at passwd.hu> wrote:
>
>> On Sun, 19 Feb 2017, Hendrik Leppkes wrote:
>> 
>> > On Sun, Feb 19, 2017 at 2:41 PM, wm4 <nfxjfg at googlemail.com> wrote: 
>> >> On Sun, 19 Feb 2017 14:35:42 +0100
>> >> Marton Balint <cus at passwd.hu> wrote:
>> >> 
>> >>> Reallocating a wrapped avframe invalidates internal pointers, such as extended
>> >>> data.
>> >>>
>> >>> FFmpeg has another way of passing AVFrames to muxers, but it seems the API
>> >>> (av_write_uncoded_frame) is not implemented in the ffmpeg CLI yet.
>> >>>
>> >>> Signed-off-by: Marton Balint <cus at passwd.hu>
>> >>> ---
>> >>>  libavcodec/utils.c | 4 ++--
>> >>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> >>>

[...]

>> 
>> So is it OK to apply the patch?
>
> My suggestion doesn't work? (Would probably imply adding the padding in
> wrapped_avframe.c.)

Yes it does work, if I set the buffer size to sizeof(AVFrame) + 
AV_INPUT_BUFFER_PADDING_SIZE. av_buffer_realloc already checks the size of 
the buffer, and avoids the reallocation there is no size change.

In wrapped_avframe.c I can either lie about the buffer size in 
av_create_buffer and set it bigger than the actual allocated memory for 
the data (AVFrame). Or I can mallocz a buffer with the proper size with 
padding, and move a frame ref to that buffer. Maybe that is better.

I will post an updated patch.

Thanks,
Marton


More information about the ffmpeg-devel mailing list