1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-28 20:53:54 +02:00

lavc/videotoolboxenc: add handling for non-NAL-based codecs

This commit is contained in:
rcombs 2021-12-16 17:31:19 -06:00
parent 30539394bb
commit 2bb5edc38c

View File

@ -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,6 +560,7 @@ static int set_extradata(AVCodecContext *avctx, CMSampleBufferRef sample_buffer)
return AVERROR_EXTERNAL;
}
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");
@ -577,6 +579,19 @@ static int set_extradata(AVCodecContext *avctx, CMSampleBufferRef sample_buffer)
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;
}
@ -1936,8 +1951,9 @@ static int vtenc_cm_to_avpacket(
CMTime dts;
CMVideoFormatDescriptionRef vid_fmt;
vtenc_get_frame_info(sample_buffer, &is_key_frame);
if (vtctx->get_param_set_func) {
status = get_length_code_size(avctx, sample_buffer, &length_code_size);
if (status) return status;
@ -1993,6 +2009,26 @@ static int vtenc_cm_to_avpacket(
av_log(avctx, AV_LOG_ERROR, "Error copying packet data: %d\n", status);
return status;
}
} else {
size_t len;
CMBlockBufferRef buf = CMSampleBufferGetDataBuffer(sample_buffer);
if (!buf) {
av_log(avctx, AV_LOG_ERROR, "Error getting block buffer\n");
return AVERROR_EXTERNAL;
}
len = CMBlockBufferGetDataLength(buf);
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) {
pkt->flags |= AV_PKT_FLAG_KEY;