Hardware-accelerated encoding may not support 10-bit encoding. Use '-require_sw 1' in this case. Fixes: #7581
Unified · Split
| @@ -762,6 +762,11 @@ static int get_cv_pixel_format(AVCodecContext* avctx, · 761 unmodified lines | ||
| 762 | 762 | *av_pixel_format = range == AVCOL_RANGE_JPEG ? |
| 763 | 763 | kCVPixelFormatType_420YpCbCr8PlanarFullRange : |
| 764 | 764 | kCVPixelFormatType_420YpCbCr8Planar; |
| 765 | + } else if (fmt == AV_PIX_FMT_P010LE) { | |
| 766 | + *av_pixel_format = range == AVCOL_RANGE_JPEG ? | |
| 767 | + kCVPixelFormatType_420YpCbCr10BiPlanarFullRange : | |
| 768 | + kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange; | |
| 769 | + *av_pixel_format = kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange; | |
| 765 | 770 | } else { |
| 766 | 771 | return AVERROR(EINVAL); |
| 767 | 772 | } |
| @@ -1986,6 +1991,17 @@ static int get_cv_pixel_info( · 1218 unmodified lines | ||
| 1986 | 1991 | strides[2] = frame ? frame->linesize[2] : (avctx->width + 1) / 2; |
| 1987 | 1992 | break; |
| 1988 | 1993 | |
| 1994 | + case AV_PIX_FMT_P010LE: | |
| 1995 | + *plane_count = 2; | |
| 1996 | + widths[0] = avctx->width; | |
| 1997 | + heights[0] = avctx->height; | |
| 1998 | + strides[0] = frame ? frame->linesize[0] : (avctx->width * 2 + 63) & -64; | |
| 1999 | + | |
| 2000 | + widths[1] = (avctx->width + 1) / 2; | |
| 2001 | + heights[1] = (avctx->height + 1) / 2; | |
| 2002 | + strides[1] = frame ? frame->linesize[1] : ((avctx->width + 1) / 2 + 63) & -64; | |
| 2003 | + break; | |
| 2004 | + | |
| 1989 | 2005 | default: |
| 1990 | 2006 | av_log( |
| 1991 | 2007 | avctx, |
| @@ -2348,21 +2364,11 @@ static int vtenc_populate_extradata(AVCodecContext *avctx, · 356 unmodified lines | ||
| 2348 | 2364 | CFDictionaryRef pixel_buffer_info) |
| 2349 | 2365 | { |
| 2350 | 2366 | VTEncContext *vtctx = avctx->priv_data; |
| 2351 | − AVFrame *frame = av_frame_alloc(); | |
| 2352 | − int y_size = avctx->width * avctx->height; | |
| 2353 | − int chroma_size = (avctx->width / 2) * (avctx->height / 2); | |
| 2354 | − CMSampleBufferRef buf = NULL; | |
| 2355 | 2367 | int status; |
| 2356 | − | |
| 2357 | − if (!frame) | |
| 2358 | − return AVERROR(ENOMEM); | |
| 2359 | − | |
| 2360 | − frame->buf[0] = av_buffer_alloc(y_size + 2 * chroma_size); | |
| 2361 | − | |
| 2362 | − if(!frame->buf[0]){ | |
| 2363 | − status = AVERROR(ENOMEM); | |
| 2364 | − goto pe_cleanup; | |
| 2365 | − } | |
| 2368 | + CVPixelBufferPoolRef pool = NULL; | |
| 2369 | + CVPixelBufferRef pix_buf = NULL; | |
| 2370 | + CMTime time; | |
| 2371 | + CMSampleBufferRef buf = NULL; | |
| 2366 | 2372 | |
| 2367 | 2373 | status = vtenc_create_encoder(avctx, |
| 2368 | 2374 | codec_type, |
| @@ -2374,39 +2380,38 @@ static int vtenc_populate_extradata(AVCodecContext *avctx, · 5 unmodified lines | ||
| 2374 | 2380 | if (status) |
| 2375 | 2381 | goto pe_cleanup; |
| 2376 | 2382 | |
| 2377 | − frame->data[0] = frame->buf[0]->data; | |
| 2378 | − memset(frame->data[0], 0, y_size); | |
| 2379 | − | |
| 2380 | − frame->data[1] = frame->buf[0]->data + y_size; | |
| 2381 | − memset(frame->data[1], 128, chroma_size); | |
| 2382 | − | |
| 2383 | − | |
| 2384 | − if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) { | |
| 2385 | − frame->data[2] = frame->buf[0]->data + y_size + chroma_size; | |
| 2386 | − memset(frame->data[2], 128, chroma_size); | |
| 2383 | + pool = VTCompressionSessionGetPixelBufferPool(vtctx->session); | |
| 2384 | + if(!pool){ | |
| 2385 | + av_log(avctx, AV_LOG_ERROR, "Error getting pixel buffer pool.\n"); | |
| 2386 | + goto pe_cleanup; | |
| 2387 | 2387 | } |
| 2388 | 2388 | |
| 2389 | − frame->linesize[0] = avctx->width; | |
| 2389 | + status = CVPixelBufferPoolCreatePixelBuffer(NULL, | |
| 2390 | + pool, | |
| 2391 | + &pix_buf); | |
| 2390 | 2392 | |
| 2391 | − if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) { | |
| 2392 | − frame->linesize[1] = | |
| 2393 | − frame->linesize[2] = (avctx->width + 1) / 2; | |
| 2394 | − } else { | |
| 2395 | − frame->linesize[1] = (avctx->width + 1) / 2; | |
| 2393 | + if(status != kCVReturnSuccess){ | |
| 2394 | + av_log(avctx, AV_LOG_ERROR, "Error creating frame from pool: %d\n", status); | |
| 2395 | + goto pe_cleanup; | |
| 2396 | 2396 | } |
| 2397 | 2397 | |
| 2398 | − frame->format = avctx->pix_fmt; | |
| 2399 | − frame->width = avctx->width; | |
| 2400 | − frame->height = avctx->height; | |
| 2401 | − frame->colorspace = avctx->colorspace; | |
| 2402 | − frame->color_range = avctx->color_range; | |
| 2403 | − frame->color_trc = avctx->color_trc; | |
| 2404 | − frame->color_primaries = avctx->color_primaries; | |
| 2398 | + unsigned pbuftype = CVPixelBufferGetPixelFormatType(pix_buf); | |
| 2399 | + | |
| 2400 | + time = CMTimeMake(0, avctx->time_base.den); | |
| 2401 | + status = VTCompressionSessionEncodeFrame(vtctx->session, | |
| 2402 | + pix_buf, | |
| 2403 | + time, | |
| 2404 | + kCMTimeInvalid, | |
| 2405 | + NULL, | |
| 2406 | + NULL, | |
| 2407 | + NULL); | |
| 2405 | 2408 | |
| 2406 | − frame->pts = 0; | |
| 2407 | − status = vtenc_send_frame(avctx, vtctx, frame); | |
| 2408 | 2409 | if (status) { |
| 2409 | − av_log(avctx, AV_LOG_ERROR, "Error sending frame: %d\n", status); | |
| 2410 | + av_log(avctx, | |
| 2411 | + AV_LOG_ERROR, | |
| 2412 | + "Error sending frame for extradata: %d\n", | |
| 2413 | + status); | |
| 2414 | + | |
| 2410 | 2415 | goto pe_cleanup; |
| 2411 | 2416 | } |
| 2412 | 2417 | |
| @@ -2434,9 +2439,6 @@ pe_cleanup: · 21 unmodified lines | ||
| 2434 | 2439 | vtctx->session = NULL; |
| 2435 | 2440 | vtctx->frame_ct_out = 0; |
| 2436 | 2441 | |
| 2437 | − av_frame_unref(frame); | |
| 2438 | − av_frame_free(&frame); | |
| 2439 | − | |
| 2440 | 2442 | av_assert0(status != 0 || (avctx->extradata && avctx->extradata_size > 0)); |
| 2441 | 2443 | |
| 2442 | 2444 | return status; |
| @@ -2475,10 +2477,18 @@ static av_cold int vtenc_close(AVCodecContext *avctx) · 32 unmodified lines | ||
| 2475 | 2477 | return 0; |
| 2476 | 2478 | } |
| 2477 | 2479 | |
| 2478 | −static const enum AVPixelFormat pix_fmts[] = { | |
| 2480 | +static const enum AVPixelFormat avc_pix_fmts[] = { | |
| 2481 | + AV_PIX_FMT_VIDEOTOOLBOX, | |
| 2482 | + AV_PIX_FMT_NV12, | |
| 2483 | + AV_PIX_FMT_YUV420P, | |
| 2484 | + AV_PIX_FMT_NONE | |
| 2485 | +}; | |
| 2486 | + | |
| 2487 | +static const enum AVPixelFormat hevc_pix_fmts[] = { | |
| 2479 | 2488 | AV_PIX_FMT_VIDEOTOOLBOX, |
| 2480 | 2489 | AV_PIX_FMT_NV12, |
| 2481 | 2490 | AV_PIX_FMT_YUV420P, |
| 2491 | + AV_PIX_FMT_P010LE, | |
| 2482 | 2492 | AV_PIX_FMT_NONE |
| 2483 | 2493 | }; |
| 2484 | 2494 | |
| @@ -2539,7 +2549,7 @@ AVCodec ff_h264_videotoolbox_encoder = { · 54 unmodified lines | ||
| 2539 | 2549 | .type = AVMEDIA_TYPE_VIDEO, |
| 2540 | 2550 | .id = AV_CODEC_ID_H264, |
| 2541 | 2551 | .priv_data_size = sizeof(VTEncContext), |
| 2542 | − .pix_fmts = pix_fmts, | |
| 2552 | + .pix_fmts = avc_pix_fmts, | |
| 2543 | 2553 | .init = vtenc_init, |
| 2544 | 2554 | .encode2 = vtenc_frame, |
| 2545 | 2555 | .close = vtenc_close, |
| @@ -2571,7 +2581,7 @@ AVCodec ff_hevc_videotoolbox_encoder = { · 25 unmodified lines | ||
| 2571 | 2581 | .type = AVMEDIA_TYPE_VIDEO, |
| 2572 | 2582 | .id = AV_CODEC_ID_HEVC, |
| 2573 | 2583 | .priv_data_size = sizeof(VTEncContext), |
| 2574 | − .pix_fmts = pix_fmts, | |
| 2584 | + .pix_fmts = hevc_pix_fmts, | |
| 2575 | 2585 | .init = vtenc_init, |
| 2576 | 2586 | .encode2 = vtenc_frame, |
| 2577 | 2587 | .close = vtenc_close, |