From patchwork Thu Feb 7 18:22:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Duponchelle X-Patchwork-Id: 11988 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 408F7445B2C for ; Thu, 7 Feb 2019 20:22:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 28D5E68AAF2; Thu, 7 Feb 2019 20:22:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.centricular.com (mail.centricular.com [50.116.37.142]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 14E9868A857 for ; Thu, 7 Feb 2019 20:22:52 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.centricular.com (Postfix) with ESMTP id E697E58B9F; Fri, 8 Feb 2019 05:22:50 +1100 (AEDT) X-Virus-Scanned: Debian amavisd-new at centricular.com Authentication-Results: worm-farm.widgetgrove.com.au (amavisd-new); dkim=neutral reason="invalid (public key: not available)" header.d=centricular.com Received: from mail.centricular.com ([IPv6:::1]) by localhost (worm-farm.widgetgrove.com.au [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id l12T7Jy_qh1f; Fri, 8 Feb 2019 05:22:50 +1100 (AEDT) Received: from linux-1.home (alyon-650-1-21-203.w92-137.abo.wanadoo.fr [92.137.56.203]) by mail.centricular.com (Postfix) with ESMTPSA id C25AB58B8E; Fri, 8 Feb 2019 05:22:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=centricular.com; s=201701; t=1549563770; bh=lQ7KB90zU+FILgbWL+xS2xN8iKHezFlVNQweNf70Rq0=; h=From:To:Cc:Subject:Date:From; b=vacMHC8EBWRxtQVlN1J8eDc6Levl4ybHRPqQuNpb5bEVg/uvGHMrgYFMktL7Nj9HK B2pTTXOv0caph8EuqdbWDJHeR103ECXJ9dmhvK1WvcJ1KCvuZnyOBS5ABH3Po9FkZv H+Sa7h3MeaeyXzE1VgLkQ8UpSsRPFmMaQJMDjAsXbjU6/xJha47yt9S6nqm+pa4F56 9V5ziUwXpyug5EGSPTeXL1dTMMBsxGJzRazTSZpC84laccne26y9CDDejoccfWoKDz 3evio9JncaUsqTYKzK+i/iZWdQI7OPXopNSV4f8NvxfQAG79MNMoumvqD7UbYu53kt /182WM4Wy6Bxg== From: Mathieu Duponchelle To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Feb 2019 19:22:46 +0100 Message-Id: <20190207182246.30628-1-mathieu@centricular.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] mpeg12enc: Use Closed Captions if available 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: Mathieu Duponchelle Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- doc/encoders.texi | 3 +++ libavcodec/mpeg12enc.c | 29 +++++++++++++++++++++++++++++ libavcodec/mpegvideo.h | 2 ++ 3 files changed, 34 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index e86ae69cc5..378a2ca8eb 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -2574,6 +2574,9 @@ Specifies the video_format written into the sequence display extension indicating the source of the video pictures. The default is @samp{unspecified}, can be @samp{component}, @samp{pal}, @samp{ntsc}, @samp{secam} or @samp{mac}. For maximum compatibility, use @samp{component}. +@item a53cc @var{boolean} +Import closed captions (which must be ATSC compatible format) into output. +Only the mpeg2 and h264 decoders provide these. Default is 1 (on). @end table @section png diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index d0b458e34b..6447e34563 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -544,6 +544,35 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) } } + if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->a53_cc) { + side_data = av_frame_get_side_data(s->current_picture_ptr->f, + AV_FRAME_DATA_A53_CC); + if (side_data) { + if (side_data->size <= 93) { + int i = 0; + + put_header (s, USER_START_CODE); + + put_bits(&s->pb, 8, 'G'); // user_identifier + put_bits(&s->pb, 8, 'A'); + put_bits(&s->pb, 8, '9'); + put_bits(&s->pb, 8, '4'); + put_bits(&s->pb, 8, 3); // user_data_type_code + put_bits(&s->pb, 8, + ((side_data->size / 3) & 0x1f) | 0x40); // flags, cc_count + put_bits(&s->pb, 8, 0xff); // em_data + + for (i = 0; i < side_data->size; i++) + put_bits(&s->pb, 8, side_data->data[i]); + + put_bits(&s->pb, 8, 0xff); // marker_bits + } else { + av_log(s->avctx, AV_LOG_WARNING, + "Warning Closed Caption size can not exceed 96 bytes\n"); + } + } + } + s->mb_y = 0; ff_mpeg1_encode_slice_header(s); } diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index bbc6b5646a..3e52f98390 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -455,6 +455,7 @@ typedef struct MpegEncContext { /* MPEG-2-specific - I wished not to have to support this mess. */ int progressive_sequence; int mpeg_f_code[2][2]; + int a53_cc; // picture structure defines are loaded from mpegutils.h int picture_structure; @@ -663,6 +664,7 @@ FF_MPV_OPT_CMP_FUNC, \ {"ps", "RTP payload size in bytes", FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", FF_MPV_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"mepre", "pre motion estimation", FF_MPV_OFFSET(me_pre), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ +{ "a53cc", "Use A53 Closed Captions (if available)", FF_MPV_OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FF_MPV_OPT_FLAGS }, \ extern const AVOption ff_mpv_generic_options[];