[FFmpeg-devel] [PATCH 2/4] avcodec/encode: restructure the core encoding code

James Almer jamrial at gmail.com
Mon Mar 2 05:07:45 EET 2020


On 3/1/2020 2:36 AM, Andriy Gelman wrote:
> On Thu, 27. Feb 15:02, James Almer wrote:
>> This commit follows the same logic as 061a0c14bb, but for the encode API: The
>> new public encoding API will no longer be a wrapper around the old deprecated
>> one, and the internal API used by the encoders now consists of a single
>> receive_packet() callback that pulls frames as required.
>>
>> Signed-off-by: James Almer <jamrial at gmail.com>
>> ---
>>  libavcodec/avcodec.h  |  12 +-
>>  libavcodec/encode.c   | 268 ++++++++++++++++++++++++++++++++----------
>>  libavcodec/encode.h   |  39 ++++++
>>  libavcodec/internal.h |   7 +-
>>  libavcodec/utils.c    |  12 +-
>>  5 files changed, 268 insertions(+), 70 deletions(-)
>>  create mode 100644 libavcodec/encode.h
>>
>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>> index 894a9e5565..9d22390dd3 100644
>> --- a/libavcodec/avcodec.h
>> +++ b/libavcodec/avcodec.h
>> @@ -3641,14 +3641,10 @@ typedef struct AVCodec {
>>      int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
>>      int (*close)(AVCodecContext *);
>>      /**
>> -     * Encode API with decoupled packet/frame dataflow. The API is the
>> -     * same as the avcodec_ prefixed APIs (avcodec_send_frame() etc.), except
>> -     * that:
>> -     * - never called if the codec is closed or the wrong type,
>> -     * - if AV_CODEC_CAP_DELAY is not set, drain frames are never sent,
>> -     * - only one drain frame is ever passed down,
>> -     */
>> -    int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
>> +     * Encode API with decoupled frame/packet dataflow. This function is called
> 
>> +     * to get one output packet. It should call ff_encode_get_packet() to obtain
> 
> should it be ff_encode_get_frame() ? 

Yes, fixed locally.

[...]

>> diff --git a/libavcodec/encode.h b/libavcodec/encode.h
>> new file mode 100644
>> index 0000000000..2eef31251a
>> --- /dev/null
>> +++ b/libavcodec/encode.h
>> @@ -0,0 +1,39 @@
>> +/*
>> + * generic encoding-related code
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>> + */
>> +
>> +#ifndef AVCODEC_ENCODE_H
>> +#define AVCODEC_ENCODE_H
>> +
>> +#include "libavutil/frame.h"
>> +
>> +#include "avcodec.h"
>> +
>> +/**
>> + * Called by encoders to get the next frame for encoding.
>> + *
>> + * @param frame An empty frame to be filled with data.
>> + * @return 0 if a new reference has been successfully written to frame
>> + *         AVERROR(EAGAIN) if no data is currently available
>> + *         AVERROR_EOF if and end of stream has been reached, so no more data
>                              ^^^
> looks like an extra "and"

Fixed as well.

Thanks.


More information about the ffmpeg-devel mailing list