[FFmpeg-devel] [PATCH 2/2] lavc/videotoolboxenc: set extradata when opening codec

Michael Niedermayer michael at niedermayer.cc
Wed Jun 8 11:48:10 CEST 2016


On Thu, Jun 02, 2016 at 02:43:56AM -0400, Rick Kern wrote:
> VideoToolbox doesn't supply parameter sets until the first frame is done
> encoding. This spins up a temporary encoder and encodes a single frame to
> get this data.
> 
> Signed-off-by: Rick Kern <kernrj at gmail.com>
> ---
>  libavcodec/videotoolboxenc.c | 326 ++++++++++++++++++++++++++++++++-----------
>  1 file changed, 241 insertions(+), 85 deletions(-)
[...]

> @@ -1753,6 +1801,114 @@ end_nopkt:
>      return status;
>  }
>  
> +static int vtenc_populate_extradata(AVCodecContext   *avctx,
> +                                    CMVideoCodecType codec_type,
> +                                    CFStringRef      profile_level,
> +                                    CFNumberRef      gamma_level,
> +                                    CFDictionaryRef  enc_info,
> +                                    CFDictionaryRef  pixel_buffer_info)
> +{
> +    VTEncContext *vtctx = avctx->priv_data;
> +    AVFrame *frame = av_frame_alloc();
> +    int y_size = avctx->width * avctx->height;
> +    int chroma_size = (avctx->width / 2) * (avctx->height / 2);
> +    CMSampleBufferRef buf = NULL;
> +    int status;
> +
> +    if (!frame)
> +        return AVERROR(ENOMEM);
> +
> +    frame->buf[0] = av_buffer_alloc(y_size + 2 * chroma_size);
> +
> +    if(!frame->buf[0]){
> +        status = AVERROR(ENOMEM);
> +        goto pe_cleanup;
> +    }
> +
> +    status = vtenc_create_encoder(avctx,
> +                                  codec_type,
> +                                  profile_level,
> +                                  gamma_level,
> +                                  enc_info,
> +                                  pixel_buffer_info,
> +                                  &vtctx->session);
> +    if (status)
> +        goto pe_cleanup;
> +
> +    frame->data[0] = frame->buf[0]->data;
> +    memset(frame->data[0],   0,      y_size);
> +
> +    frame->data[1] = frame->buf[0]->data + y_size;
> +    memset(frame->data[1], 128, chroma_size);
> +
> +
> +    if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
> +        frame->data[2] = frame->buf[0]->data + y_size + chroma_size;
> +        memset(frame->data[2], 128, chroma_size);
> +    }
> +
> +    frame->linesize[0] = avctx->width;
> +
> +    if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
> +        frame->linesize[1] =
> +        frame->linesize[2] = (avctx->width + 1) / 2;
> +    } else {
> +        frame->linesize[1] = (avctx->width + 1) / 2;
> +    }
> +
> +    frame->format          = avctx->pix_fmt;
> +    frame->width           = avctx->width;
> +    frame->height          = avctx->height;

> +    frame->colorspace      = avctx->colorspace;

Iam not sure the docs fully match current intend but
colorspace and color_range are documented to be only accessed
through av_frame_get_color_range(), av_frame_set_color_range(),
av_frame_get_colorspace() and av_frame_set_colorspace()


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160608/692b40ad/attachment.sig>


More information about the ffmpeg-devel mailing list