[FFmpeg-devel] [PATCH v16 01/16] global: Prepare AVFrame for subtitle handling

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Nov 27 11:06:35 EET 2021


Anton Khirnov:
> Quoting Soft Works (2021-11-25 18:53:24)
>> @@ -759,9 +802,39 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src);
>>   *              recommended to pass 0 here unless you know what you are doing.
>>   *
>>   * @return 0 on success, a negative AVERROR on error.
>> + *
>> + * @deprecated Use @ref av_frame_get_buffer2 instead and set @ref AVFrame.type
>> + * before calling.
>>   */
>> +attribute_deprecated
>>  int av_frame_get_buffer(AVFrame *frame, int align);
>>  
>> +/**
>> + * Allocate new buffer(s) for audio, video or subtitle data.
>> + *
>> + * The following fields must be set on frame before calling this function:
>> + * - format (pixel format for video, sample format for audio)
>> + * - width and height for video
>> + * - nb_samples and channel_layout for audio
>> + * - type (AVMediaType)
>> + *
>> + * This function will fill AVFrame.data and AVFrame.buf arrays and, if
>> + * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
>> + * For planar formats, one buffer will be allocated for each plane.
>> + *
>> + * @warning: if frame already has been allocated, calling this function will
>> + *           leak memory. In addition, undefined behavior can occur in certain
>> + *           cases.
>> + *
>> + * @param frame frame in which to store the new buffers.
>> + * @param align Required buffer size alignment. If equal to 0, alignment will be
>> + *              chosen automatically for the current CPU. It is highly
>> + *              recommended to pass 0 here unless you know what you are doing.
>> + *
>> + * @return 0 on success, a negative AVERROR on error.
>> + */
>> +int av_frame_get_buffer2(AVFrame *frame, int align);
> 
> Not sure whether this was asked already - why do we need this new
> function? Seems to me you can accomplish the same thing by just adding
> the type field to AVFrame. Then
> - if type is AVMEDIA_TYPE_SUBTITLE -> allocate a subtitle
> - if type is AVMEDIA_TYPE_{VIDEO,AUDIO} -> allocate video/audio
> - otherwise detect video/audio as we do now
> 

https://ffmpeg.org/pipermail/ffmpeg-devel/2021-September/285185.html

- Andreas


More information about the ffmpeg-devel mailing list