From: Rick Kern <kernrj@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH 07/10] lavc/videotoolboxenc: add handling for non-NAL-based codecs Date: Sun, 19 Dec 2021 11:40:49 -0500 Message-ID: <CABmg8gVB7ax3xy_77j5+7m5Z2ptJXh45NYukJ2jigQ8-ALAsmA@mail.gmail.com> (raw) In-Reply-To: <20211217001215.75135-8-rcombs@rcombs.me> On Thu, Dec 16, 2021 at 7:13 PM rcombs <rcombs@rcombs.me> wrote: > --- > libavcodec/videotoolboxenc.c | 149 +++++++++++++++++++++-------------- > 1 file changed, 92 insertions(+), 57 deletions(-) > > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c > index 82e01fbe29..67bb563639 100644 > --- a/libavcodec/videotoolboxenc.c > +++ b/libavcodec/videotoolboxenc.c > @@ -549,6 +549,7 @@ static int copy_param_sets( > > static int set_extradata(AVCodecContext *avctx, CMSampleBufferRef > sample_buffer) > { > + VTEncContext *vtctx = avctx->priv_data; > CMVideoFormatDescriptionRef vid_fmt; > size_t total_size; > int status; > @@ -559,23 +560,37 @@ static int set_extradata(AVCodecContext *avctx, > CMSampleBufferRef sample_buffer) > return AVERROR_EXTERNAL; > } > > - status = get_params_size(avctx, vid_fmt, &total_size); > - if (status) { > - av_log(avctx, AV_LOG_ERROR, "Could not get parameter sets.\n"); > - return status; > - } > + if (vtctx->get_param_set_func) { > + status = get_params_size(avctx, vid_fmt, &total_size); > + if (status) { > + av_log(avctx, AV_LOG_ERROR, "Could not get parameter > sets.\n"); > + return status; > + } > > - avctx->extradata = av_mallocz(total_size + > AV_INPUT_BUFFER_PADDING_SIZE); > - if (!avctx->extradata) { > - return AVERROR(ENOMEM); > - } > - avctx->extradata_size = total_size; > + avctx->extradata = av_mallocz(total_size + > AV_INPUT_BUFFER_PADDING_SIZE); > + if (!avctx->extradata) { > + return AVERROR(ENOMEM); > + } > + avctx->extradata_size = total_size; > > - status = copy_param_sets(avctx, vid_fmt, avctx->extradata, > total_size); > + status = copy_param_sets(avctx, vid_fmt, avctx->extradata, > total_size); > > - if (status) { > - av_log(avctx, AV_LOG_ERROR, "Could not copy param sets.\n"); > - return status; > + if (status) { > + av_log(avctx, AV_LOG_ERROR, "Could not copy param sets.\n"); > + return status; > + } > + } else { > + CFDataRef data = CMFormatDescriptionGetExtension(vid_fmt, > kCMFormatDescriptionExtension_VerbatimSampleDescription); > + if (data && CFGetTypeID(data) == CFDataGetTypeID()) { > + CFIndex size = CFDataGetLength(data); > + > + avctx->extradata = av_mallocz(size + > AV_INPUT_BUFFER_PADDING_SIZE); > + if (!avctx->extradata) > + return AVERROR(ENOMEM); > + avctx->extradata_size = size; > + > + CFDataGetBytes(data, CFRangeMake(0, size), avctx->extradata); > + } > } > > return 0; > @@ -1938,62 +1953,82 @@ static int vtenc_cm_to_avpacket( > CMTime dts; > CMVideoFormatDescriptionRef vid_fmt; > > - > vtenc_get_frame_info(sample_buffer, &is_key_frame); > - status = get_length_code_size(avctx, sample_buffer, > &length_code_size); > - if (status) return status; > > - add_header = is_key_frame && !(avctx->flags & > AV_CODEC_FLAG_GLOBAL_HEADER); > + if (vtctx->get_param_set_func) { > + status = get_length_code_size(avctx, sample_buffer, > &length_code_size); > + if (status) return status; > > - if (add_header) { > - vid_fmt = CMSampleBufferGetFormatDescription(sample_buffer); > - if (!vid_fmt) { > - av_log(avctx, AV_LOG_ERROR, "Cannot get format > description.\n"); > - return AVERROR_EXTERNAL; > + add_header = is_key_frame && !(avctx->flags & > AV_CODEC_FLAG_GLOBAL_HEADER); > + > + if (add_header) { > + vid_fmt = CMSampleBufferGetFormatDescription(sample_buffer); > + if (!vid_fmt) { > + av_log(avctx, AV_LOG_ERROR, "Cannot get format > description.\n"); > + return AVERROR_EXTERNAL; > + } > + > + int status = get_params_size(avctx, vid_fmt, &header_size); > + if (status) return status; > } > > - int status = get_params_size(avctx, vid_fmt, &header_size); > - if (status) return status; > - } > + status = count_nalus(length_code_size, sample_buffer, > &nalu_count); > + if(status) > + return status; > > - status = count_nalus(length_code_size, sample_buffer, &nalu_count); > - if(status) > - return status; > + if (sei) { > + size_t msg_size = get_sei_msg_bytes(sei, > + > SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35); > > - if (sei) { > - size_t msg_size = get_sei_msg_bytes(sei, > - > SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35); > + sei_nalu_size = sizeof(start_code) + 1 + msg_size + 1; > + } > > - sei_nalu_size = sizeof(start_code) + 1 + msg_size + 1; > - } > + in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer); > + out_buf_size = header_size + > + in_buf_size + > + sei_nalu_size + > + nalu_count * ((int)sizeof(start_code) - > (int)length_code_size); > > - in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer); > - out_buf_size = header_size + > - in_buf_size + > - sei_nalu_size + > - nalu_count * ((int)sizeof(start_code) - > (int)length_code_size); > + status = ff_get_encode_buffer(avctx, pkt, out_buf_size, 0); > + if (status < 0) > + return status; > > - status = ff_get_encode_buffer(avctx, pkt, out_buf_size, 0); > - if (status < 0) > - return status; > + if (add_header) { > + status = copy_param_sets(avctx, vid_fmt, pkt->data, > out_buf_size); > + if(status) return status; > + } > > - if (add_header) { > - status = copy_param_sets(avctx, vid_fmt, pkt->data, out_buf_size); > - if(status) return status; > - } > + status = copy_replace_length_codes( > + avctx, > + length_code_size, > + sample_buffer, > + sei, > + pkt->data + header_size, > + pkt->size - header_size > + ); > > - status = copy_replace_length_codes( > - avctx, > - length_code_size, > - sample_buffer, > - sei, > - pkt->data + header_size, > - pkt->size - header_size > - ); > + if (status) { > + av_log(avctx, AV_LOG_ERROR, "Error copying packet data: > %d\n", status); > + return status; > + } > + } else { > + CMBlockBufferRef buf = CMSampleBufferGetDataBuffer(sample_buffer); > + if (!buf) { > + av_log(avctx, AV_LOG_ERROR, "Error getting block buffer\n"); > + return AVERROR_EXTERNAL; > + } > > - if (status) { > - av_log(avctx, AV_LOG_ERROR, "Error copying packet data: %d\n", > status); > - return status; > + size_t len = CMBlockBufferGetDataLength(buf); > The declaration should be at the beginning of the block. > + > + status = ff_get_encode_buffer(avctx, pkt, len, 0); > + if (status < 0) > + return status; > + > + status = CMBlockBufferCopyDataBytes(buf, 0, len, pkt->data); > + if (status) { > + av_log(avctx, AV_LOG_ERROR, "Error copying packet data: > %d\n", status); > + return AVERROR_EXTERNAL; > + } > } > > if (is_key_frame) { > -- > 2.33.1 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2021-12-19 16:41 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-17 0:12 [FFmpeg-devel] lavc/videotoolboxenc: add ProRes support rcombs 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 01/10] lavc/videotoolboxenc: use common routine for pixfmt conversion rcombs 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 02/10] lavc/videotoolboxenc: don't access int64_t member as int rcombs 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 03/10] lavc/videotoolboxenc: detect alpha more generically rcombs 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 04/10] lavc/videotoolboxenc: fix RGB support rcombs 2021-12-19 16:18 ` Rick Kern 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 05/10] lavc/videotoolboxenc: config-gate ATSC CC support rcombs 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 06/10] lavc/videotoolboxenc: vastly simplify get_cv_pixel_info rcombs 2021-12-19 16:25 ` Rick Kern 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 07/10] lavc/videotoolboxenc: add handling for non-NAL-based codecs rcombs 2021-12-19 16:40 ` Rick Kern [this message] 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 08/10] lavc/Makefile: fix missing hevc_videotoolbox case rcombs 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 09/10] swscale: add P210/P410/P216/P416 output rcombs 2021-12-23 11:00 ` Michael Niedermayer 2021-12-17 0:12 ` [FFmpeg-devel] [PATCH 10/10] lavc/videotoolboxenc: add ProRes support rcombs 2021-12-19 17:30 ` [FFmpeg-devel] " Rick Kern
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=CABmg8gVB7ax3xy_77j5+7m5Z2ptJXh45NYukJ2jigQ8-ALAsmA@mail.gmail.com \ --to=kernrj@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git