Lines Matching defs:avctx
253 static int vtenc_populate_extradata(AVCodecContext *avctx,
414 static CMVideoCodecType get_cm_codec_type(AVCodecContext *avctx,
418 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX ? avctx->sw_pix_fmt : avctx->pix_fmt);
419 switch (avctx->codec_id) {
442 av_log(avctx, AV_LOG_ERROR, "Unknown profile ID: %"PRId64", using auto\n", profile);
464 AVCodecContext *avctx,
468 VTEncContext *vtctx = avctx->priv_data;
509 av_log(avctx, AV_LOG_ERROR, "Error getting parameter set sizes: %d\n", status);
518 AVCodecContext *avctx,
523 VTEncContext *vtctx = avctx->priv_data;
562 av_log(avctx, AV_LOG_ERROR, "Error: buffer too small for parameter sets.\n");
574 av_log(avctx, AV_LOG_ERROR, "Error getting parameter set data: %d\n", status);
581 static int set_extradata(AVCodecContext *avctx, CMSampleBufferRef sample_buffer)
583 VTEncContext *vtctx = avctx->priv_data;
590 av_log(avctx, AV_LOG_ERROR, "No video format.\n");
595 status = get_params_size(avctx, vid_fmt, &total_size);
597 av_log(avctx, AV_LOG_ERROR, "Could not get parameter sets.\n");
601 avctx->extradata = av_mallocz(total_size + AV_INPUT_BUFFER_PADDING_SIZE);
602 if (!avctx->extradata) {
605 avctx->extradata_size = total_size;
607 status = copy_param_sets(avctx, vid_fmt, avctx->extradata, total_size);
610 av_log(avctx, AV_LOG_ERROR, "Could not copy param sets.\n");
618 avctx->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
619 if (!avctx->extradata)
621 avctx->extradata_size = size;
623 CFDataGetBytes(data, CFRangeMake(0, size), avctx->extradata);
637 AVCodecContext *avctx = ctx;
638 VTEncContext *vtctx = avctx->priv_data;
646 av_log(avctx, AV_LOG_ERROR, "Error encoding frame: %d\n", (int)status);
655 if (!avctx->extradata && (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) {
656 int set_status = set_extradata(avctx, sample_buffer);
667 AVCodecContext *avctx,
671 VTEncContext *vtctx = avctx->priv_data;
678 av_log(avctx, AV_LOG_ERROR, "Error getting buffer format description.\n");
689 av_log(avctx, AV_LOG_ERROR, "Error getting length code size: %d\n", status);
703 static bool get_vt_h264_profile_level(AVCodecContext *avctx,
706 VTEncContext *vtctx = avctx->priv_data;
795 av_log(avctx, AV_LOG_ERROR, "Invalid Profile/Level.\n");
808 static bool get_vt_hevc_profile_level(AVCodecContext *avctx,
811 VTEncContext *vtctx = avctx->priv_data;
830 av_log(avctx, AV_LOG_ERROR, "Invalid Profile/Level.\n");
837 static int get_cv_pixel_format(AVCodecContext* avctx,
852 static void add_color_attr(AVCodecContext *avctx, CFMutableDictionaryRef dict) {
853 VTEncContext *vtctx = avctx->priv_data;
874 static int create_cv_pixel_buffer_info(AVCodecContext* avctx,
882 int status = get_cv_pixel_format(avctx,
883 avctx->pix_fmt,
884 avctx->color_range,
909 &avctx->width);
919 &avctx->height);
927 add_color_attr(avctx, pixel_buffer_info);
941 static int get_cv_color_primaries(AVCodecContext *avctx,
944 enum AVColorPrimaries pri = avctx->color_primaries;
967 av_log(avctx, AV_LOG_ERROR, "Color primaries %s is not supported.\n", av_color_primaries_name(pri));
975 static int get_cv_transfer_function(AVCodecContext *avctx,
979 enum AVColorTransferCharacteristic trc = avctx->color_trc;
1031 av_log(avctx, AV_LOG_ERROR, "Transfer function %s is not supported.\n", av_color_transfer_name(trc));
1038 static int get_cv_ycbcr_matrix(AVCodecContext *avctx, CFStringRef *matrix) {
1039 switch(avctx->colorspace) {
1063 av_log(avctx, AV_LOG_ERROR, "Color space %s is not supported.\n", av_color_space_name(avctx->colorspace));
1076 static int vtenc_create_encoder(AVCodecContext *avctx,
1084 VTEncContext *vtctx = avctx->priv_data;
1085 SInt32 bit_rate = avctx->bit_rate;
1086 SInt32 max_rate = avctx->rc_max_rate;
1087 Float32 quality = avctx->global_quality / FF_QP2LAMBDA;
1098 avctx->width,
1099 avctx->height,
1105 avctx,
1109 av_log(avctx, AV_LOG_ERROR, "Error: cannot create compression session: %d\n", status);
1113 av_log(avctx, AV_LOG_ERROR, "Try -allow_sw 1. The hardware encoder may be busy, or not supported.\n");
1120 if (avctx->flags & AV_CODEC_FLAG_QSCALE && !vtenc_qscale_enabled()) {
1121 av_log(avctx, AV_LOG_ERROR, "Error: -q:v qscale not available for encoder. Use -b:v bitrate instead.\n");
1125 if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
1136 } else if (avctx->codec_id != AV_CODEC_ID_PRORES) {
1149 av_log(avctx, AV_LOG_ERROR, "Error setting bitrate property: %d\n", status);
1158 av_log(avctx, AV_LOG_WARNING, "PrioritizeEncodingSpeedOverQuality property is not supported on this device. Ignoring.\n");
1200 av_log(avctx, AV_LOG_ERROR, "Error setting max bitrate property: %d\n", status);
1210 if (avctx->pix_fmt == AV_PIX_FMT_BGRA && vtctx->alpha_quality > 0.0) {
1228 av_log(avctx, AV_LOG_ERROR, "Error setting profile/level property: %d. Output will be encoded using a supported profile/level combination.\n", status);
1232 if (avctx->gop_size > 0 && avctx->codec_id != AV_CODEC_ID_PRORES) {
1235 &avctx->gop_size);
1246 av_log(avctx, AV_LOG_ERROR, "Error setting 'max key-frame interval' property: %d\n", status);
1257 av_log(avctx, AV_LOG_WARNING, "frames_before property is not supported on this device. Ignoring.\n");
1259 av_log(avctx, AV_LOG_ERROR, "Error setting frames_before property: %d\n", status);
1269 av_log(avctx, AV_LOG_WARNING, "frames_after property is not supported on this device. Ignoring.\n");
1271 av_log(avctx, AV_LOG_ERROR, "Error setting frames_after property: %d\n", status);
1275 if (avctx->sample_aspect_ratio.num != 0) {
1279 AVRational *avpar = &avctx->sample_aspect_ratio;
1327 av_log(avctx,
1330 avctx->sample_aspect_ratio.num,
1331 avctx->sample_aspect_ratio.den,
1345 av_log(avctx, AV_LOG_WARNING, "Could not set transfer function: %d\n", status);
1356 av_log(avctx, AV_LOG_WARNING, "Could not set ycbcr matrix: %d\n", status);
1367 av_log(avctx, AV_LOG_WARNING, "Could not set color primaries: %d\n", status);
1377 av_log(avctx, AV_LOG_WARNING, "Could not set gamma level: %d\n", status);
1381 if (!vtctx->has_b_frames && avctx->codec_id != AV_CODEC_ID_PRORES) {
1387 av_log(avctx, AV_LOG_ERROR, "Error setting 'allow frame reordering' property: %d\n", status);
1402 av_log(avctx, AV_LOG_ERROR, "Error setting entropy property: %d\n", status);
1412 av_log(avctx, AV_LOG_ERROR, "Error setting realtime property: %d\n", status);
1418 av_log(avctx, AV_LOG_ERROR, "Error: cannot prepare encoder: %d\n", status);
1425 static int vtenc_configure_encoder(AVCodecContext *avctx)
1430 VTEncContext *vtctx = avctx->priv_data;
1435 codec_type = get_cm_codec_type(avctx, vtctx->profile, vtctx->alpha_quality);
1437 av_log(avctx, AV_LOG_ERROR, "Error: no mapping for AVCodecID %d\n", avctx->codec_id);
1442 if (avctx->codec_id == AV_CODEC_ID_PRORES) {
1449 vtctx->codec_id = avctx->codec_id;
1454 vtctx->has_b_frames = avctx->max_b_frames > 0;
1456 av_log(avctx, AV_LOG_WARNING, "Cannot use B-frames with baseline profile. Output will not contain B-frames.\n");
1461 av_log(avctx, AV_LOG_WARNING, "CABAC entropy requires 'main' or 'high' profile, but baseline was requested. Encode will not use CABAC entropy.\n");
1465 if (!get_vt_h264_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
1469 if (!get_vt_hevc_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
1471 vtctx->has_b_frames = avctx->max_b_frames > 0 ? 2 : 0;
1473 avctx->codec_tag = av_bswap32(codec_type);
1501 if (avctx->pix_fmt != AV_PIX_FMT_VIDEOTOOLBOX) {
1502 status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info);
1511 get_cv_transfer_function(avctx, &vtctx->transfer_function, &gamma_level);
1512 get_cv_ycbcr_matrix(avctx, &vtctx->ycbcr_matrix);
1513 get_cv_color_primaries(avctx, &vtctx->color_primaries);
1516 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
1517 status = vtenc_populate_extradata(avctx,
1527 status = vtenc_create_encoder(avctx,
1547 static av_cold int vtenc_init(AVCodecContext *avctx)
1549 VTEncContext *vtctx = avctx->priv_data;
1559 status = vtenc_configure_encoder(avctx);
1571 vtctx->has_b_frames = avctx->codec_id == AV_CODEC_ID_HEVC ? 2 : 1;
1576 avctx->has_b_frames = vtctx->has_b_frames;
1619 static int find_sei_end(AVCodecContext *avctx,
1651 av_log(avctx, AV_LOG_ERROR, "Unexpected end of SEI NAL Unit parsing type.\n");
1662 av_log(avctx, AV_LOG_ERROR, "Unexpected end of SEI NAL Unit parsing size.\n");
1808 AVCodecContext *avctx,
1842 av_log(avctx, AV_LOG_ERROR, "Cannot copy length: %d\n", status);
1852 av_log(avctx, AV_LOG_ERROR, "Cannot copy type: %d\n", status);
1917 av_log(avctx, AV_LOG_ERROR, "Cannot copy data: %d\n", status);
1927 old_sei_length = find_sei_end(avctx, dst_box, box_len, &new_sei);
1982 AVCodecContext *avctx,
1987 VTEncContext *vtctx = avctx->priv_data;
2007 status = get_length_code_size(avctx, sample_buffer, &length_code_size);
2010 add_header = is_key_frame && !(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER);
2015 av_log(avctx, AV_LOG_ERROR, "Cannot get format description.\n");
2019 int status = get_params_size(avctx, vid_fmt, &header_size);
2040 status = ff_get_encode_buffer(avctx, pkt, out_buf_size, 0);
2045 status = copy_param_sets(avctx, vid_fmt, pkt->data, out_buf_size);
2050 avctx,
2059 av_log(avctx, AV_LOG_ERROR, "Error copying packet data: %d\n", status);
2066 av_log(avctx, AV_LOG_ERROR, "Error getting block buffer\n");
2072 status = ff_get_encode_buffer(avctx, pkt, len, 0);
2078 av_log(avctx, AV_LOG_ERROR, "Error copying packet data: %d\n", status);
2094 av_log(avctx, AV_LOG_ERROR, "DTS is invalid.\n");
2100 time_base_num = avctx->time_base.num;
2112 AVCodecContext *avctx,
2121 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
2122 VTEncContext *vtctx = avctx->priv_data;
2132 status = get_cv_pixel_format(avctx, av_format, av_color_range, color, &range_guessed);
2134 av_log(avctx,
2149 av_log(avctx,
2156 *plane_count = av_pix_fmt_count_planes(avctx->pix_fmt);
2165 widths[p] = (avctx->width + ((1 << shiftw) >> 1)) >> shiftw;
2166 heights[p] = (avctx->height + ((1 << shifth) >> 1)) >> shifth;
2185 static int copy_avframe_to_pixel_buffer(AVCodecContext *avctx,
2204 avctx,
2216 av_log(avctx,
2243 av_log(avctx,
2270 av_log(avctx, AV_LOG_ERROR, "Error: Could not unlock CVPixelBuffer base address: %d.\n", status);
2277 static int create_cv_pixel_buffer(AVCodecContext *avctx,
2289 VTEncContext* vtctx = avctx->priv_data;
2291 if (avctx->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX) {
2306 avctx,
2318 avctx,
2341 status = vtenc_configure_encoder(avctx);
2346 av_log(avctx, AV_LOG_ERROR, "Could not get pixel buffer pool.\n");
2350 av_log(avctx, AV_LOG_WARNING, "VT session restarted because of a "
2360 av_log(avctx, AV_LOG_ERROR, "Could not create pixel buffer from pool: %d.\n", status);
2364 status = copy_avframe_to_pixel_buffer(avctx, frame, *cv_img, strides, heights);
2390 static int vtenc_send_frame(AVCodecContext *avctx,
2399 int status = create_cv_pixel_buffer(avctx, frame, &cv_img);
2414 av_log(avctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");
2418 av_log(avctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");
2426 time = CMTimeMake(frame->pts * avctx->time_base.num, avctx->time_base.den);
2441 av_log(avctx, AV_LOG_ERROR, "Error: cannot encode frame: %d\n", status);
2449 AVCodecContext *avctx,
2454 VTEncContext *vtctx = avctx->priv_data;
2461 status = vtenc_send_frame(avctx, vtctx, frame);
2482 av_log(avctx, AV_LOG_ERROR, "Error flushing frames: %d\n", status);
2499 status = vtenc_cm_to_avpacket(avctx, buf, pkt, sei);
2515 static int vtenc_populate_extradata(AVCodecContext *avctx,
2522 VTEncContext *vtctx = avctx->priv_data;
2529 status = vtenc_create_encoder(avctx,
2541 av_log(avctx, AV_LOG_ERROR, "Error getting pixel buffer pool.\n");
2550 av_log(avctx, AV_LOG_ERROR, "Error creating frame from pool: %d\n", status);
2554 time = CMTimeMake(0, avctx->time_base.den);
2564 av_log(avctx,
2581 av_log(avctx, AV_LOG_ERROR, "popping: %d\n", status);
2597 av_assert0(status != 0 || (avctx->extradata && avctx->extradata_size > 0));
2602 static av_cold int vtenc_close(AVCodecContext *avctx)
2604 VTEncContext *vtctx = avctx->priv_data;