From patchwork Thu Oct 17 08:29:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15806 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 16044449FA2 for ; Thu, 17 Oct 2019 11:30:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EEFDA68A79E; Thu, 17 Oct 2019 11:30:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E9DA68A67D for ; Thu, 17 Oct 2019 11:30:44 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id n14so1271889wrw.9 for ; Thu, 17 Oct 2019 01:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rndWbQSiBKVIoPa/EQlM+b2IDJZYlZsqwpyc5UVRMwc=; b=vD0AdAZEGFkPQJMukHQn75kGz2zk8hbwtdMxQlF9dOZTy+rukmdD5QO1J4UAzE7Tm6 eSP8Febt54UcHMELIpgyZSx7THNpDfPeYI/jWNEJGXkRStdUs7Q0EvArLu+RhjoKE7nR 2D2VP5HPfLJl7JQUPLEO15G9vcMeG8UXD8hN+5pO5Te3CgVuTIew4ALBPW0/nfvivn84 eFWtEZDNoKwro0UgrXFVGWj8AQZE2md0sb2Wjnt03dCP4YNjMUrtAMQTT6iUUW5aoziN t/3tq5pfPROHMeE2KFgPWALZxlVMEy2iuBZES0FqSmhTjQj9ArwyYNsKVaT3SteRilIv AbSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rndWbQSiBKVIoPa/EQlM+b2IDJZYlZsqwpyc5UVRMwc=; b=Y25x6C7FX+kYVDOaKML+gv1i3yx4te45ry0jIA89/w+jgNRRcGM6UrOnpvWnvJVaYR t1KMXpGX4GS8LRf0jYD3zkO52MMyj2hIR+AD6xuYkT5JmGoKgw6sZQ6Cc3ki6SRRph+v CzKCwZ5LYzO+BYPABPnRmonqgkoadrVHMOdg99S1ptcqORATNUHX44VzuJH1brF49rCq gc7saI3/3fydQYcRxoEr/vHBFJ7/xlHQesvsymkS3qAbwS8Il2WYj1elV2FXn5GzgOxs dStl9eooIp2U7nn9aKUpDB+4qdyhQOy1JKyY+0HLuRQTsd1hZMgtr5O0H/lCMJmRCs82 YO/Q== X-Gm-Message-State: APjAAAWxyBbQOOa/oYgiP8G1bj25XI0hwFEiF2YIK4BSqDEktMP3rcKi Us4B6FeQTPX7hktuGqf8F5M737B/ X-Google-Smtp-Source: APXvYqxwRR0tONNe26d3Xz4nhuy6PraQ0zpK0e+wjrnxQAqRxrIK34ziJv0AMLDO99fES8B6kvLtrw== X-Received: by 2002:a5d:420b:: with SMTP id n11mr1869708wrq.88.1571301043054; Thu, 17 Oct 2019 01:30:43 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id l7sm1369273wrv.77.2019.10.17.01.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 01:30:42 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Oct 2019 10:29:38 +0200 Message-Id: <20191017082945.13534-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017082945.13534-1-andreas.rheinhardt@gmail.com> References: <20191017082945.13534-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/15] h264_mp4toannexb: Try to avoid four byte startcodes 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" According to the H.264 specifications, the only NAL units that need to have four byte startcodes in H.264 Annex B format are SPS/PPS units and units that start a new access unit. Before af7e953a, the first of these conditions wasn't upheld as already existing in-band parameter sets would not automatically be written with a four byte startcode, but only when they already were at the beginning of their input packets. But it made four byte startcodes be used too often as every unit that is written together with a parameter set that is inserted from extradata received a four byte startcode although a three byte start code would suffice unless the unit itself were a parameter set. FATE has been updated to reflect the changes. Although the patch leaves the extradata unchanged, the size of the extradata according to the FATE reports changes. This is due to a quirk in ff_h2645_packet_split which is used by extract_extradata: If the input is Annex B, the first zero of a four byte startcode is considered a part of the last unit (if any). Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_mp4toannexb_bsf.c | 6 +++--- tests/ref/fate/h264-bsf-mp4toannexb | 2 +- tests/ref/fate/h264_mp4toannexb_ticket2991 | 22 ++++++++++---------- tests/ref/fate/h264_mp4toannexb_ticket5927 | 10 ++++----- tests/ref/fate/h264_mp4toannexb_ticket5927_2 | 10 ++++----- tests/ref/fate/segment-mp4-to-ts | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 7db26595f0..718878c9f2 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -47,7 +47,7 @@ static int alloc_and_copy(AVPacket *out, const uint8_t *in, uint32_t in_size, int ps) { uint32_t offset = out->size; - uint8_t start_code_size = offset == 0 || ps ? 4 : 3; + uint8_t start_code_size = offset == 0 && sps_pps_size == 0 || ps ? 4 : 3; int err; err = av_grow_packet(out, sps_pps_size + in_size + start_code_size); @@ -244,7 +244,7 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) if (s->new_idr && unit_type == H264_NAL_IDR_SLICE && !s->idr_sps_seen && !s->idr_pps_seen) { if ((ret=alloc_and_copy(out, ctx->par_out->extradata, ctx->par_out->extradata_size, - buf, nal_size, 1)) < 0) + buf, nal_size, 0)) < 0) goto fail; s->new_idr = 0; /* if only SPS has been seen, also insert PPS */ @@ -255,7 +255,7 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) goto fail; } else if ((ret = alloc_and_copy(out, s->pps, s->pps_size, - buf, nal_size, 1)) < 0) + buf, nal_size, 0)) < 0) goto fail; } else { if ((ret=alloc_and_copy(out, NULL, 0, buf, nal_size, unit_type == H264_NAL_SPS || unit_type == H264_NAL_PPS)) < 0) diff --git a/tests/ref/fate/h264-bsf-mp4toannexb b/tests/ref/fate/h264-bsf-mp4toannexb index 7cd086a268..2049f39701 100644 --- a/tests/ref/fate/h264-bsf-mp4toannexb +++ b/tests/ref/fate/h264-bsf-mp4toannexb @@ -1 +1 @@ -f340e7ca9a46d437af4e96f6c8de221c +5f04c27cc6ee8625fe2405fb0f7da9a3 diff --git a/tests/ref/fate/h264_mp4toannexb_ticket2991 b/tests/ref/fate/h264_mp4toannexb_ticket2991 index 3245ef442c..76bdf3cae7 100644 --- a/tests/ref/fate/h264_mp4toannexb_ticket2991 +++ b/tests/ref/fate/h264_mp4toannexb_ticket2991 @@ -1,12 +1,12 @@ -dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h264 -1985823 tests/data/fate/h264_mp4toannexb_ticket2991.h264 -#extradata 0: 48, 0x47ae0d55 +05d66e60ab22ee004720e0051af0fe74 *tests/data/fate/h264_mp4toannexb_ticket2991.h264 +1985815 tests/data/fate/h264_mp4toannexb_ticket2991.h264 +#extradata 0: 47, 0x3a590d55 #tb 0: 1/1200000 #media_type 0: video #codec_id 0: h264 #dimensions 0: 1280x720 #sar 0: 3/4 -0, 0, 0, 48000, 37127, 0xc125184c +0, 0, 0, 48000, 37126, 0xb020184c 0, 48000, 48000, 40040, 6920, 0x8512361a, F=0x0 0, 88040, 88040, 40040, 7550, 0x1bc56ed4, F=0x0 0, 128081, 128081, 40040, 8752, 0xb8c6f0a1, F=0x0 @@ -21,7 +21,7 @@ dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h2 0, 488444, 488444, 40040, 11234, 0x83cbd9fd, F=0x0 0, 528485, 528485, 40040, 17616, 0xfdf95104, F=0x0 0, 568525, 568525, 40040, 10689, 0x9633d32b, F=0x0 -0, 608566, 608566, 40040, 45292, 0x66dd2cf6 +0, 608566, 608566, 40040, 45291, 0x543c2cf6 0, 648606, 648606, 40040, 20837, 0x051abfab, F=0x0 0, 688646, 688646, 40040, 21418, 0xe2a59d70, F=0x0 0, 728687, 728687, 40040, 15643, 0x15cf2cec, F=0x0 @@ -36,7 +36,7 @@ dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h2 0, 1089050, 1089050, 40040, 13130, 0xcbb6bb8e, F=0x0 0, 1129091, 1129091, 40040, 16180, 0x5d188a7a, F=0x0 0, 1169131, 1169131, 40040, 14961, 0x9ff2f463, F=0x0 -0, 1209172, 1209172, 40040, 54297, 0xf98d30ed +0, 1209172, 1209172, 40040, 54296, 0xe6ec30ed 0, 1249212, 1249212, 40040, 11500, 0x8c4852c9, F=0x0 0, 1289252, 1289252, 40040, 12065, 0xfb7954c3, F=0x0 0, 1329293, 1329293, 40040, 12532, 0xf0a935d3, F=0x0 @@ -51,7 +51,7 @@ dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h2 0, 1689656, 1689656, 40040, 13250, 0xfed0deb8, F=0x0 0, 1729697, 1729697, 40040, 13360, 0xbf92d476, F=0x0 0, 1769737, 1769737, 40040, 11749, 0x3041eaf1, F=0x0 -0, 1809778, 1809778, 40040, 23998, 0xee87d5c4 +0, 1809778, 1809778, 40040, 23997, 0xdbe6d5c4 0, 1849818, 1849818, 40040, 16065, 0xe8f715b7, F=0x0 0, 1889858, 1889858, 40040, 16441, 0x0a4e060f, F=0x0 0, 1929899, 1929899, 40040, 17395, 0xa8edecc2, F=0x0 @@ -66,7 +66,7 @@ dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h2 0, 2290262, 2290262, 40040, 13748, 0xed26aeb4, F=0x0 0, 2330303, 2330303, 40040, 15092, 0x3c983538, F=0x0 0, 2370343, 2370343, 40040, 14636, 0x9b278a6c, F=0x0 -0, 2410384, 2410384, 40040, 29135, 0x0a34be18 +0, 2410384, 2410384, 40040, 29134, 0xf784be18 0, 2450424, 2450424, 40040, 10232, 0x5408e15b, F=0x0 0, 2490464, 2490464, 40040, 9769, 0xc93cb7f9, F=0x0 0, 2530505, 2530505, 40040, 14454, 0x45230dbe, F=0x0 @@ -81,7 +81,7 @@ dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h2 0, 2890868, 2890868, 40040, 14801, 0x40bae016, F=0x0 0, 2930909, 2930909, 40040, 17303, 0x9ce1fd31, F=0x0 0, 2970949, 2970949, 40040, 17678, 0x9bd66141, F=0x0 -0, 3010990, 3010990, 40040, 48673, 0x44b6ce46 +0, 3010990, 3010990, 40040, 48672, 0x3215ce46 0, 3051030, 3051030, 40040, 11894, 0x12e1fece, F=0x0 0, 3091070, 3091070, 40040, 16514, 0xc57aed05, F=0x0 0, 3131111, 3131111, 40040, 13044, 0x61914fa0, F=0x0 @@ -96,7 +96,7 @@ dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h2 0, 3491474, 3491474, 40040, 12208, 0x81a587c0, F=0x0 0, 3531515, 3531515, 40040, 14709, 0x5dffbe04, F=0x0 0, 3571555, 3571555, 40040, 14390, 0xbfd1e041, F=0x0 -0, 3611596, 3611596, 40040, 37237, 0xfa9a24b1 +0, 3611596, 3611596, 40040, 37236, 0xe7f924b1 0, 3651636, 3651636, 40040, 14056, 0x24714c7c, F=0x0 0, 3691676, 3691676, 40040, 19438, 0x0c50dcd5, F=0x0 0, 3731717, 3731717, 40040, 21728, 0x7eea4a11, F=0x0 @@ -111,7 +111,7 @@ dba672c154b41414cf26aae967c27eef *tests/data/fate/h264_mp4toannexb_ticket2991.h2 0, 4092080, 4092080, 40040, 16878, 0x98efbae2, F=0x0 0, 4132121, 4132121, 40040, 14685, 0x1bf78d65, F=0x0 0, 4172161, 4172161, 40040, 13127, 0x0b91881d, F=0x0 -0, 4212202, 4212202, 40040, 29391, 0x0955ed6b +0, 4212202, 4212202, 40040, 29390, 0xf6a5ed6b 0, 4252242, 4252242, 40040, 12576, 0xe9845ded, F=0x0 0, 4292282, 4292282, 40040, 12599, 0x96a79ab8, F=0x0 0, 4332323, 4332323, 40040, 16134, 0xb4c36d3f, F=0x0 diff --git a/tests/ref/fate/h264_mp4toannexb_ticket5927 b/tests/ref/fate/h264_mp4toannexb_ticket5927 index 006ea398fd..95e35c4d80 100644 --- a/tests/ref/fate/h264_mp4toannexb_ticket5927 +++ b/tests/ref/fate/h264_mp4toannexb_ticket5927 @@ -1,12 +1,12 @@ -562487bfea635cdadbc23d390322b589 *tests/data/fate/h264_mp4toannexb_ticket5927.h264 -595585 tests/data/fate/h264_mp4toannexb_ticket5927.h264 -#extradata 0: 34, 0x8df608f8 +a3b02fd09392e01619cebc959d4d9ff2 *tests/data/fate/h264_mp4toannexb_ticket5927.h264 +595583 tests/data/fate/h264_mp4toannexb_ticket5927.h264 +#extradata 0: 33, 0x84fe08f8 #tb 0: 1/1200000 #media_type 0: video #codec_id 0: h264 #dimensions 0: 1920x1080 #sar 0: 0/1 -0, -48000, -9223372036854775808, 48000, 247994, 0x2e1e21ea +0, -48000, -9223372036854775808, 48000, 247993, 0x1ce821ea 0, 0, -9223372036854775808, 48000, 43354, 0xa05dca6f, F=0x0 0, 48000, -9223372036854775808, 48000, 11423, 0x5e8086dd, F=0x0 0, 96000, -9223372036854775808, 48000, 50798, 0x145fbe4f, F=0x0 @@ -18,4 +18,4 @@ 0, 384000, -9223372036854775808, 48000, 54483, 0xefead99f, F=0x0 0, 432000, -9223372036854775808, 48000, 13705, 0x23cd27e8, F=0x0 0, 480000, -9223372036854775808, 48000, 22308, 0x4093b5af, F=0x0 -0, 528000, -9223372036854775808, 48000, 6370, 0x96c12aa1 +0, 528000, -9223372036854775808, 48000, 6369, 0x858b2aa1 diff --git a/tests/ref/fate/h264_mp4toannexb_ticket5927_2 b/tests/ref/fate/h264_mp4toannexb_ticket5927_2 index 51432b1535..8db6a7e54a 100644 --- a/tests/ref/fate/h264_mp4toannexb_ticket5927_2 +++ b/tests/ref/fate/h264_mp4toannexb_ticket5927_2 @@ -1,12 +1,12 @@ -562487bfea635cdadbc23d390322b589 *tests/data/fate/h264_mp4toannexb_ticket5927_2.h264 -595585 tests/data/fate/h264_mp4toannexb_ticket5927_2.h264 -#extradata 0: 34, 0x8df608f8 +a3b02fd09392e01619cebc959d4d9ff2 *tests/data/fate/h264_mp4toannexb_ticket5927_2.h264 +595583 tests/data/fate/h264_mp4toannexb_ticket5927_2.h264 +#extradata 0: 33, 0x84fe08f8 #tb 0: 1/1200000 #media_type 0: video #codec_id 0: h264 #dimensions 0: 1920x1080 #sar 0: 0/1 -0, -48000, -9223372036854775808, 48000, 247994, 0x2e1e21ea +0, -48000, -9223372036854775808, 48000, 247993, 0x1ce821ea 0, 0, -9223372036854775808, 48000, 43354, 0xa05dca6f, F=0x0 0, 48000, -9223372036854775808, 48000, 11423, 0x5e8086dd, F=0x0 0, 96000, -9223372036854775808, 48000, 50798, 0x145fbe4f, F=0x0 @@ -18,4 +18,4 @@ 0, 384000, -9223372036854775808, 48000, 54483, 0xefead99f, F=0x0 0, 432000, -9223372036854775808, 48000, 13705, 0x23cd27e8, F=0x0 0, 480000, -9223372036854775808, 48000, 22308, 0x4093b5af, F=0x0 -0, 528000, -9223372036854775808, 48000, 6370, 0x96c12aa1 +0, 528000, -9223372036854775808, 48000, 6369, 0x858b2aa1 diff --git a/tests/ref/fate/segment-mp4-to-ts b/tests/ref/fate/segment-mp4-to-ts index b5accb60f7..847c1a297d 100644 --- a/tests/ref/fate/segment-mp4-to-ts +++ b/tests/ref/fate/segment-mp4-to-ts @@ -1,10 +1,10 @@ -#extradata 0: 51, 0x5d140df9 +#extradata 0: 50, 0x4f1b0df9 #tb 0: 1/90000 #media_type 0: video #codec_id 0: h264 #dimensions 0: 640x360 #sar 0: 1/1 -0, -7200, 0, 0, 22631, 0x9cec9541, S=1, 1, 0x00e000e0 +0, -7200, 0, 0, 22630, 0x9b109541, S=1, 1, 0x00e000e0 0, -3600, 14400, 0, 4021, 0xbf7cdb02, F=0x0, S=1, 1, 0x00e000e0 0, 0, 7200, 0, 1096, 0x4f162690, F=0x0, S=1, 1, 0x00e000e0 0, 3600, 3600, 0, 687, 0x00394b95, F=0x0, S=1, 1, 0x00e000e0