From patchwork Tue Sep 13 01:19:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Campbell X-Patchwork-Id: 557 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp1904238vsd; Mon, 12 Sep 2016 18:21:00 -0700 (PDT) X-Received: by 10.28.46.134 with SMTP id u128mr14007321wmu.41.1473729660785; Mon, 12 Sep 2016 18:21:00 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id pf5si18199840wjb.153.2016.09.12.18.20.56; Mon, 12 Sep 2016 18:21:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A45B689F9D; Tue, 13 Sep 2016 04:20:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from p3plsmtpout003.prod.phx3.secureserver.net (p3plsmtpout003.prod.phx3.secureserver.net [208.109.80.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9B7FA689F87 for ; Tue, 13 Sep 2016 04:20:34 +0300 (EEST) Received: from ip-192-169-235-64.secureserver.net ([192.169.235.64]) by : HOSTING RELAY : with SMTP id jcO0bQxeLCN7fjcO0beW1S; Mon, 12 Sep 2016 18:19:44 -0700 x-originating-ip: 192.169.235.64 Received: from 50-245-141-73-static.hfc.comcastbusiness.net ([50.245.141.73]:48242 helo=[172.19.234.190]) by ip-192-169-235-64.secureserver.net with esmtpsa (TLSv1:DHE-RSA-CAMELLIA256-SHA:256) (Exim 4.82) (envelope-from ) id 1bjcNz-00047Z-Sf for ffmpeg-devel@ffmpeg.org; Mon, 12 Sep 2016 18:19:44 -0700 Message-ID: <57D7542F.5060103@impactstudiopro.com> Date: Mon, 12 Sep 2016 18:19:43 -0700 From: Jonathan Campbell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: FFmpeg development discussions and patches References: <57D72C08.4020808@impactstudiopro.com> <20160912235650.GX4975@nb4> In-Reply-To: <20160912235650.GX4975@nb4> X-CMAE-Envelope: MS4wfDQBoqKgkQXR0kDutuIEixttz+C/c4DfQ71kYQOZ3nLncLATIH/00XjetSv8JCndlBz0W97UQOVibIuLa0rTpWgRLR80ts6VYwNzQ7P2OeTudamRNAyT KRFMmuazarTiA6CAtFWm5aG/v4AFLDorfmoNUnRMxZ6MrFBfB/XZjFD6K26HmTYq3sYQPoW5DRkNeMzYytcZnmGmuyUP4NfimZcB1td6kPI4b0zASQwWVDCc Subject: Re: [FFmpeg-devel] mpeg12dec fix up DVD caption handling 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On 09/12/2016 04:56 PM, Michael Niedermayer wrote: > On Mon, Sep 12, 2016 at 03:28:24PM -0700, Jonathan Campbell wrote: >> These patches fix up the DVD caption handling in mpeg12dec.c to better handle odd cases. >> It's based on code I've written elsewhere to handle captions. >> While it's common for these packets to contain 15 frames worth and start on the odd field there are also DVDs that start on even field or even encode extra fields and switch starting fields. >> Part of the patch is to document comprehensively the format of the DVD caption packet. >> >> Jonathan Campbell > >> mpeg12dec.c | 27 ++++++++++++++++++++++++++- >> 1 file changed, 26 insertions(+), 1 deletion(-) >> a839a0d0e9000ab140f6aef9dee9577f242462bf 0001-add-comments-documenting-the-format-of-the-DVD-CC-us.patch >> From 9213012c7d8ceef2af43fe3c218b1b50728e8f80 Mon Sep 17 00:00:00 2001 >> From: Jonathan Campbell >> Date: Mon, 12 Sep 2016 12:34:48 -0700 >> Subject: [PATCH 1/2] add comments documenting the format of the DVD CC >> user-data packet. this is to aid development and maintenance of that code. >> >> --- >> libavcodec/mpeg12dec.c | 27 ++++++++++++++++++++++++++- >> 1 file changed, 26 insertions(+), 1 deletion(-) >> >> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c >> index 204a578..522621a 100644 >> --- a/libavcodec/mpeg12dec.c >> +++ b/libavcodec/mpeg12dec.c >> @@ -2262,7 +2262,32 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, >> return 1; >> } else if (buf_size >= 11 && >> p[0] == 'C' && p[1] == 'C' && p[2] == 0x01 && p[3] == 0xf8) { >> - /* extract DVD CC data */ >> + /* extract DVD CC data > >> + * for more information see: [https://en.wikipedia.org/wiki/EIA-608#DVD_GOP_User_Data_Insertion] > > wikipedia is not a good reference, in fact its not even a > constant reference without a revission. wikipedia can massivly change > and may at times, especially with niche areas be just wrong, the link > itself also wont always work possibly > > Please use the specifications itself, H.262 is public, its the 4th > link when searching for H.262 with google for example (wikipedia > refers to H.262 IIUC) > > [...] > > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > Updated patch set, removes Wikipedia link. I see that H.262 specs are free on the web, but I can't find the part that describes the DVD-style H.262 user data packets that this code handles. But the structure as described has been reliable when tested against my DVD library. Jonathan Campbell From 9213012c7d8ceef2af43fe3c218b1b50728e8f80 Mon Sep 17 00:00:00 2001 From: Jonathan Campbell Date: Mon, 12 Sep 2016 12:34:48 -0700 Subject: [PATCH 1/7] add comments documenting the format of the DVD CC user-data packet. this is to aid development and maintenance of that code. --- libavcodec/mpeg12dec.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 204a578..522621a 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2262,7 +2262,32 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, return 1; } else if (buf_size >= 11 && p[0] == 'C' && p[1] == 'C' && p[2] == 0x01 && p[3] == 0xf8) { - /* extract DVD CC data */ + /* extract DVD CC data + * for more information see: [https://en.wikipedia.org/wiki/EIA-608#DVD_GOP_User_Data_Insertion] + * + * uint32_t user_data_start_code 0x000001B2 (big endian) + * uint16_t user_identifier 0x4343 "CC" + * uint8_t user_data_type_code 0x01 + * uint8_t caption_block_size 0xF8 + * uint8_t + * bit 7 caption_odd_field_first 1=odd field (CC1/CC2) first 0=even field (CC3/CC4) first + * bit 6 caption_filler 0 + * bit 5:1 caption_block_count number of caption blocks (pairs of caption words = frames). Most DVDs use 15 per start of GOP. + * bit 0 caption_extra_field_added 1=one additional caption word + * + * struct caption_field_block { + * uint8_t + * bit 7:1 caption_filler 0x7F (all 1s) + * bit 0 caption_field_odd 1=odd field (this is CC1/CC2) 0=even field (this is CC3/CC4) + * uint8_t caption_first_byte + * uint8_t caption_second_byte + * } caption_block[(caption_block_count * 2) + caption_extra_field_added]; + * + * Some DVDs encode caption data for both fields with caption_field_odd=1. The only way to decode the fields + * correctly is to start on the field indicated by caption_odd_field_first and count between odd/even fields. + * Don't assume that the first caption word is the odd field. There do exist MPEG files in the wild that start + * on the even field. There also exist DVDs in the wild that encode an odd field count and the + * caption_extra_field_added/caption_odd_field_first bits change per packet to allow that. */ int cc_count = 0; int i; // There is a caption count field in the data, but it is often