From patchwork Mon Aug 5 17:58:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 14252 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2370044836A for ; Mon, 5 Aug 2019 21:04:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F148568A8CA; Mon, 5 Aug 2019 21:04:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 15E1768A89E for ; Mon, 5 Aug 2019 21:04:51 +0300 (EEST) Received: by mail-ot1-f68.google.com with SMTP id o101so86158145ota.8 for ; Mon, 05 Aug 2019 11:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=UiH1LZ3GX4CQZ7LgRPlwuGAuTN4QAyPKc/pBipQMjfA=; b=TdXnRVT4+b6jHeY/yRnjTBBH1c/CCKxROxlb993q94VLNQd6FPihiv/esH3TfxD1WQ loK4edZ8P6/9KsANoGAaWOF6xMbPjZOU1isOHn5Id/yQ2km02HQns6OY6YZ8mAfrL5C0 bm/IMxheMBjnSJluFHS9Ax0wxiTHML9X5EN2t8bteOdurujv11gqqR/RxfywhQCo6jyz m5bZRD2GVkvpr51cOu/pN64suPzjA7IkS+ZeQ1H29GTDML/qb3XB0qFnYkzUID4Ghssg Rqh5dR3KG5eZgtm369VSntmqi1Guw9zxqw1hPDKzZhzXYezVN8n68lgDhsv10q86IFVV KklA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=UiH1LZ3GX4CQZ7LgRPlwuGAuTN4QAyPKc/pBipQMjfA=; b=fR9Iy7hLntum9PzUNXUXiRiIp1P38hqeA6uJsbv10STpaandyLkeYcvOVRLY/+k5yJ S11Yd5mnBgeUw5sOw0pdNou7RZ/Bbae55X18akVpneriBBIo++mYeVmZeLWxygIMblYG 5iNo+1g4podA1UVmDF2/Pz6YUbkUT96E5h7e9FyqPwZ7VNx5x/q6gRi7nSMw2HmIlOQs hyyc17ee2scFfwyQUQdre9n0KLxIVyLlFlXUtXU9Yhn9pnjGGNyAArMDKjvnw38XlvBf TVyfzzNR0uEYosGyrrB/QoOzT+SwcRpI3GxWU07TyzG5cqi5/MYL+/XKOLl2v39GAfSu jGzA== X-Gm-Message-State: APjAAAUHC4nSz4hXwd0we7U39jSj3JN/xdWVqeoF3Pl20WoqE/7esZXB 1ghIsmFIMSrZ/9MpS/zQLogvXx8w X-Google-Smtp-Source: APXvYqy0pG+lxRfHRf+icUeUHeXuChyQ4Uw2cohuiibVF0TZBDq+MKpRUqQ6kKQBAvsZd1fO6zElRA== X-Received: by 2002:a9d:7203:: with SMTP id u3mr84053934otj.313.1565027926722; Mon, 05 Aug 2019 10:58:46 -0700 (PDT) Received: from tmm1-imac.lan (ip184-189-221-177.sb.sd.cox.net. [184.189.221.177]) by smtp.gmail.com with ESMTPSA id m21sm26841339otl.70.2019.08.05.10.58.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Aug 2019 10:58:45 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Aug 2019 10:58:43 -0700 Message-Id: <20190805175843.16847-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/vaapi_encode_h264: add support for a/53 closed caption sei X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Aman Gupta , "Fu, Linjie" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta Signed-off-by: Aman Gupta --- libavcodec/vaapi_encode_h264.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index f4965d8b09..280bd4752b 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -39,6 +39,7 @@ enum { SEI_TIMING = 0x01, SEI_IDENTIFIER = 0x02, SEI_RECOVERY_POINT = 0x04, + SEI_A53_CC = 0x08, }; // Random (version 4) ISO 11578 UUID. @@ -72,6 +73,7 @@ typedef struct VAAPIEncodeH264Context { int sei; int profile; int level; + bool enable_a53_cc; // Derived settings. int mb_width; @@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context { H264RawSEIRecoveryPoint sei_recovery_point; H264RawSEIUserDataUnregistered sei_identifier; char *sei_identifier_string; + H264RawSEIUserDataRegistered sei_a53cc; + void *sei_a53cc_data; int aud_needed; int sei_needed; @@ -251,6 +255,11 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, sei->payload[i].payload.recovery_point = priv->sei_recovery_point; ++i; } + if (priv->sei_needed & SEI_A53_CC) { + sei->payload[i].payload_type = H264_SEI_TYPE_USER_DATA_REGISTERED; + sei->payload[i].payload.user_data_registered = priv->sei_a53cc; + ++i; + } sei->payload_count = i; av_assert0(sei->payload_count > 0); @@ -626,7 +635,8 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *prev = pic->prev; VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL; VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params; - int i; + int i, err; + size_t sei_a53cc_len; if (pic->type == PICTURE_TYPE_IDR) { av_assert0(pic->display_order == pic->encode_order); @@ -700,6 +710,21 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, priv->sei_needed |= SEI_RECOVERY_POINT; } + if (priv->enable_a53_cc) { + av_freep(&priv->sei_a53cc_data); + err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len); + if (err < 0) + return err; + + if (priv->sei_a53cc_data) { + priv->sei_a53cc.itu_t_t35_country_code = 181; + priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1; + priv->sei_a53cc.data_length = sei_a53cc_len - 1; + + priv->sei_needed |= SEI_A53_CC; + } + } + vpic->CurrPic = (VAPictureH264) { .picture_id = pic->recon_surface, .frame_idx = hpic->frame_num, @@ -1245,6 +1270,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx) ff_cbs_fragment_free(priv->cbc, &priv->current_access_unit); ff_cbs_close(&priv->cbc); av_freep(&priv->sei_identifier_string); + av_freep(&priv->sei_a53cc_data); return ff_vaapi_encode_close(avctx); } @@ -1321,6 +1347,8 @@ static const AVOption vaapi_encode_h264_options[] = { { LEVEL("6.2", 62) }, #undef LEVEL + { "a53cc", "Use A53 Closed Captions (if available)", OFFSET(enable_a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS }, + { NULL }, };