Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Zhao Zhili <quinkblack@foxmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Zhao Zhili <zhilizhao@tencent.com>
Subject: [FFmpeg-devel] [PATCH 4/5] avcodec/h264_mp4toannexb_bsf: process new extradata
Date: Sat, 20 May 2023 00:41:32 +0800
Message-ID: <tencent_75AE3919C1DDB794684E022568967D56AF0A@qq.com> (raw)
In-Reply-To: <20230519164133.3278597-1-quinkblack@foxmail.com>

From: Zhao Zhili <zhilizhao@tencent.com>

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 d75aebb253..cf08cb9e54 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 = 872608399a9aac7cf91a7c447f366f32
+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".

  parent reply	other threads:[~2023-05-19  8:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230519164133.3278597-1-quinkblack@foxmail.com>
2023-05-19 16:41 ` [FFmpeg-devel] [PATCH 2/5] avcodec/h264_mp4toannexb_bsf: remove pass padding size as argument Zhao Zhili
2023-05-19 16:41 ` [FFmpeg-devel] [PATCH 3/5] avcodec/h264_mp4toannexb_bsf: fix missing PS before IDR frames Zhao Zhili
2023-07-05 16:08   ` Thilo Borgmann
2023-07-06  8:55     ` Thilo Borgmann
2023-07-06 16:19     ` [FFmpeg-devel] [PATCH v2 1/5] avcodec/h264_mp4toannexb_bsf: refactor start_code_size handling Zhao Zhili
     [not found]     ` <20230706161957.1758621-1-quinkblack@foxmail.com>
2023-07-06 16:19       ` [FFmpeg-devel] [PATCH v2 2/5] avcodec/h264_mp4toannexb_bsf: remove pass padding size as argument Zhao Zhili
2023-07-06 16:19       ` [FFmpeg-devel] [PATCH v2 3/5] avcodec/h264_mp4toannexb_bsf: fix missing PS before IDR frames Zhao Zhili
2023-07-06 16:19       ` [FFmpeg-devel] [PATCH v2 4/5] avcodec/h264_mp4toannexb_bsf: process new extradata Zhao Zhili
2023-07-06 16:19       ` [FFmpeg-devel] [PATCH v2 5/5] fate/h264: move mp4toannexb_ticket5927 test to fate-h264 Zhao Zhili
2023-05-19 16:41 ` Zhao Zhili [this message]
2023-05-19 16:41 ` [FFmpeg-devel] [PATCH " Zhao Zhili

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_75AE3919C1DDB794684E022568967D56AF0A@qq.com \
    --to=quinkblack@foxmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=zhilizhao@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git