From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 18BC646C29 for ; Thu, 6 Jul 2023 08:20:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B66B68C6E5; Thu, 6 Jul 2023 11:20:20 +0300 (EEST) Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4870868C6C9 for ; Thu, 6 Jul 2023 11:20:12 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1688631599; bh=O0ZKjg8LDOeDq7QSXFoj5yi0oFpINLyS3g9XvohQl4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qCStzU8VgmEMD4njpa5ti8hO5x56QqRQSMMI7LPGX0p1d4qVtvGO8irduq9pQpWmj gC2+nLqmFN4h9LI3aucZG8iYnYduVyYJHM7rALvMTJNizBEL07V4gfjjIsKZxH7GzL wl6lIHOicFY6LJdrgFk7omMwgifCWY/sm82/cfjc= Received: from localhost.localdomain ([113.108.77.56]) by newxmesmtplogicsvrszc2-0.qq.com (NewEsmtp) with SMTP id 4F8BA662; Thu, 06 Jul 2023 16:19:56 +0800 X-QQ-mid: xmsmtpt1688631598ty70h95oh Message-ID: X-QQ-XMAILINFO: MR/iVh5QLeiecpv/VTMuXXq2EHDFUaIln+HmteURaegTJbZfmrwyCDJCsyhYRA ro05EYGv6ciCOjd5sabio274NZsRM2Uxuq1AUMsrj06J3a/M038oxemJ1YVcXneRa3rVOfKdLMUr O5TlpWiPjDS1GWmgt4uCpmg6bpkd/qGhfLLqU8fIyzMXw7bg6E4Y8r6OMCrqg59RlRYOh3OvakWA 7AmB1BBu6qlbqLlz8QCt9DVs/TZnKNCzdU/VORZ8O1pDvPAztGpNq2Dismy1ut28Ro9V8IMSYgXO bkFxamBCL6yUZkxEQJw2xvkqXtcplHjxBwUFJpjgN5f28j+DM8YhNWmIKUzgKNew8XxI7FMbsfHs WlAlNcJe/aOhb2FoGp7ToJ71G6D0oJaY2hVDkuiSZtYEaXa+qmNXN0gQcXjBDPgUaNAohUH5Hv9g 8CJZbWfAHX88G29RyLR5oN3sJOiq8pXhP6ymGr9Glq8nOx0vGgbLdb2nChqZgtFx3av7KbIBcahk dzdAcoWfBMlYV8kxi+XYWwdJtBiOKyYzZEFoEpMHhE91K1cp4cpEDY16NHrZ2Ktb69oVtqNvyNLU x69BZo7n5n75i++q4JmldP0Obz2zdP4wuR+PKR+Pki+V81VE8Bn+uT75ST14mDp2k82CQCbqeis9 F+R5TWO5cpn74aPQZbiVfQ9gg8/TNSV9xY6QVfVU1dzEuXAT688D7+jA153og+vWgqeXVIwe1QcN 4HJG7DPU/s3mAACBSiHk0lZuxfb5sBoGIxZJaeH4FR1bF0YmNdc62caO+e67qTANP91nrZ9TpMv9 Hg6tPB8YxzpLKb/2U0xzzSodE/88oJT74h3hpCRbooSSCjvce4rkLVN/A1RzOUFmoRE501RmC/n/ x23iKeembpLXl4eKNfwdKdLiUMVcIm9Cq3Z3jx4r728oiUF94wkZ8C9Rw8ZWnKAtus7O9McLTa+8 Xqot1qsJv2zBLvZUuvaXl79Nr6aWfpymNlfxCNktAotr1uuVBRIw== X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Jul 2023 00:19:56 +0800 X-OQ-MSGID: <20230706161957.1758621-4-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230706161957.1758621-1-quinkblack@foxmail.com> References: <20230706161957.1758621-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/5] avcodec/h264_mp4toannexb_bsf: process new extradata X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Zhao Zhili For fate-h264_mp4toannexb_ticket5927 and fate-h264_mp4toannexb_ticket5927_2, they work by accident previously. The sample file has two 'avc1' entries, and video samples use the second one. It means packets should be decoded with new extradata in side data. Before this patch, only extradata was kept in the output, new extradata has been dropped. The output can be decoded because the two extradata are almost the same, except level indication. This patch fixed the issue, and add another fate test. --- libavcodec/h264_mp4toannexb_bsf.c | 37 ++++++++++++------- tests/fate/h264.mak | 4 +- .../fate/h264-bsf-mp4toannexb-new-extradata | 9 +++++ tests/ref/fate/h264_mp4toannexb_ticket5927 | 8 ++-- tests/ref/fate/h264_mp4toannexb_ticket5927_2 | 8 ++-- 5 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 tests/ref/fate/h264-bsf-mp4toannexb-new-extradata diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 4073c780c5..120241c892 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -80,7 +80,8 @@ static void count_or_copy(uint8_t **out, uint64_t *out_size, *out_size += start_code_size + in_size; } -static int h264_extradata_to_annexb(AVBSFContext *ctx) +static int h264_extradata_to_annexb(AVBSFContext *ctx, + uint8_t *extradata, int extradata_size) { H264BSFContext *s = ctx->priv_data; GetByteContext ogb, *gb = &ogb; @@ -91,7 +92,7 @@ static int h264_extradata_to_annexb(AVBSFContext *ctx) const int padding = AV_INPUT_BUFFER_PADDING_SIZE; int length_size, pps_offset = 0; - bytestream2_init(gb, ctx->par_in->extradata, ctx->par_in->extradata_size); + bytestream2_init(gb, extradata, extradata_size); bytestream2_skipu(gb, 4); @@ -169,7 +170,13 @@ pps: ctx->par_out->extradata = out; ctx->par_out->extradata_size = total_size; - return length_size; + s->length_size = length_size; + s->new_idr = 1; + s->idr_sps_seen = 0; + s->idr_pps_seen = 0; + s->extradata_parsed = 1; + + return 0; } static int h264_mp4toannexb_save_ps(uint8_t **dst, int *dst_size, @@ -203,9 +210,7 @@ static int h264_mp4toannexb_save_ps(uint8_t **dst, int *dst_size, static int h264_mp4toannexb_init(AVBSFContext *ctx) { - H264BSFContext *s = ctx->priv_data; int extra_size = ctx->par_in->extradata_size; - int ret; /* retrieve sps and pps NAL units from extradata */ if (!extra_size || @@ -214,15 +219,9 @@ static int h264_mp4toannexb_init(AVBSFContext *ctx) av_log(ctx, AV_LOG_VERBOSE, "The input looks like it is Annex B already\n"); } else if (extra_size >= 7) { - ret = h264_extradata_to_annexb(ctx); - if (ret < 0) - return ret; - - s->length_size = ret; - s->new_idr = 1; - s->idr_sps_seen = 0; - s->idr_pps_seen = 0; - s->extradata_parsed = 1; + return h264_extradata_to_annexb(ctx, + ctx->par_in->extradata, + ctx->par_in->extradata_size); } else { av_log(ctx, AV_LOG_ERROR, "Invalid extradata size: %d\n", extra_size); return AVERROR_INVALIDDATA; @@ -241,11 +240,21 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) uint8_t *out; uint64_t out_size; int ret; + size_t extradata_size; + uint8_t *extradata; ret = ff_bsf_get_packet(ctx, &in); if (ret < 0) return ret; + extradata = av_packet_get_side_data(in, AV_PKT_DATA_NEW_EXTRADATA, + &extradata_size); + if (extradata) { + ret = h264_extradata_to_annexb(ctx, extradata, extradata_size); + if (ret < 0) + goto fail; + } + /* nothing to filter */ if (!s->extradata_parsed) { av_packet_move_ref(opkt, in); diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak index c7e0d0a84e..c747111ebe 100644 --- a/tests/fate/h264.mak +++ b/tests/fate/h264.mak @@ -225,7 +225,8 @@ FATE_H264-$(call FRAMECRC, MOV, H264) += fate-h264-unescaped-extradata FATE_H264-$(call FRAMECRC, MOV, H264) += fate-h264-twofields-packet FATE_H264-$(call DEMMUX, MOV, H264, H264_MP4TOANNEXB_BSF) += fate-h264-bsf-mp4toannexb \ - fate-h264-bsf-mp4toannexb-2 + fate-h264-bsf-mp4toannexb-2 \ + fate-h264-bsf-mp4toannexb-new-extradata \ FATE_H264-$(call FRAMECRC, MATROSKA, H264) += fate-h264-direct-bff FATE_H264-$(call FRAMECRC, FLV, H264, SCALE_FILTER) += fate-h264-brokensps-2580 @@ -432,6 +433,7 @@ fate-h264-bsf-mp4toannexb: CMD = md5 -i $(TARGET_SAMPLES) fate-h264-bsf-mp4toannexb-2: CMD = md5 -i $(TARGET_SAMPLES)/h264/ps_prefix_first_idr.mp4 -c:v copy -f h264 fate-h264-bsf-mp4toannexb-2: CMP = oneline fate-h264-bsf-mp4toannexb-2: REF = cffcfa6a2d0b58c9de1f5785f099f41d +fate-h264-bsf-mp4toannexb-new-extradata: CMD = stream_remux mov $(TARGET_SAMPLES)/h264/extradata-reload-multi-stsd.mov h264 "-map 0:v" fate-h264-crop-to-container: CMD = framemd5 -i $(TARGET_SAMPLES)/h264/crop-to-container-dims-canon.mov fate-h264-direct-bff: CMD = framecrc -i $(TARGET_SAMPLES)/h264/direct-bff.mkv diff --git a/tests/ref/fate/h264-bsf-mp4toannexb-new-extradata b/tests/ref/fate/h264-bsf-mp4toannexb-new-extradata new file mode 100644 index 0000000000..a0423ad295 --- /dev/null +++ b/tests/ref/fate/h264-bsf-mp4toannexb-new-extradata @@ -0,0 +1,9 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 256x128 +#sar 0: 1/1 +0, 0, 0, 1, 49152, 0x08745db9 +0, 1, 1, 1, 49152, 0x96bf5e58 +0, 2, 2, 1, 49152, 0x8fe31b6d +0, 3, 3, 1, 49152, 0x0b621cc3 diff --git a/tests/ref/fate/h264_mp4toannexb_ticket5927 b/tests/ref/fate/h264_mp4toannexb_ticket5927 index 95e35c4d80..eb0b5cf283 100644 --- a/tests/ref/fate/h264_mp4toannexb_ticket5927 +++ b/tests/ref/fate/h264_mp4toannexb_ticket5927 @@ -1,12 +1,12 @@ -a3b02fd09392e01619cebc959d4d9ff2 *tests/data/fate/h264_mp4toannexb_ticket5927.h264 +edddeef7901b2bd8d55625b8105b579f *tests/data/fate/h264_mp4toannexb_ticket5927.h264 595583 tests/data/fate/h264_mp4toannexb_ticket5927.h264 -#extradata 0: 33, 0x84fe08f8 +#extradata 0: 33, 0x84e308f7 #tb 0: 1/1200000 #media_type 0: video #codec_id 0: h264 #dimensions 0: 1920x1080 #sar 0: 0/1 -0, -48000, -9223372036854775808, 48000, 247993, 0x1ce821ea +0, -48000, -9223372036854775808, 48000, 247993, 0x541321e9 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 @@ a3b02fd09392e01619cebc959d4d9ff2 *tests/data/fate/h264_mp4toannexb_ticket5927.h2 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, 6369, 0x858b2aa1 +0, 528000, -9223372036854775808, 48000, 6369, 0x6cca2aa0 diff --git a/tests/ref/fate/h264_mp4toannexb_ticket5927_2 b/tests/ref/fate/h264_mp4toannexb_ticket5927_2 index 8db6a7e54a..8c3613ee79 100644 --- a/tests/ref/fate/h264_mp4toannexb_ticket5927_2 +++ b/tests/ref/fate/h264_mp4toannexb_ticket5927_2 @@ -1,12 +1,12 @@ -a3b02fd09392e01619cebc959d4d9ff2 *tests/data/fate/h264_mp4toannexb_ticket5927_2.h264 +edddeef7901b2bd8d55625b8105b579f *tests/data/fate/h264_mp4toannexb_ticket5927_2.h264 595583 tests/data/fate/h264_mp4toannexb_ticket5927_2.h264 -#extradata 0: 33, 0x84fe08f8 +#extradata 0: 33, 0x84e308f7 #tb 0: 1/1200000 #media_type 0: video #codec_id 0: h264 #dimensions 0: 1920x1080 #sar 0: 0/1 -0, -48000, -9223372036854775808, 48000, 247993, 0x1ce821ea +0, -48000, -9223372036854775808, 48000, 247993, 0x541321e9 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 @@ a3b02fd09392e01619cebc959d4d9ff2 *tests/data/fate/h264_mp4toannexb_ticket5927_2. 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, 6369, 0x858b2aa1 +0, 528000, -9223372036854775808, 48000, 6369, 0x6cca2aa0 -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".