> On Jun 8, 2016, at 5:48 AM, Michael Niedermayer <mich...@niedermayer.cc> > wrote: > > 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 <ker...@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()
I’ll change these locally and push tomorrow if no one else reviews. > > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > While the State exists there can be no freedom; when there is freedom there > will be no State. -- Vladimir Lenin > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel