Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: jie jiang <jiangjie618@gmail.com>
To: Zhao Zhili <quinkblack@foxmail.com>
Cc: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH] avcodec/bsf/h264_mp4toannexb.c: change extradata to annexb if this is avcc.
Date: Thu, 24 Apr 2025 13:18:20 +0800
Message-ID: <CAJ53Rru_vypPmxxV7oYueCX6SpWgTyPcj6E65Ay=skPyT9wc0w@mail.gmail.com> (raw)
In-Reply-To: <tencent_DBB2260150BBA6C5E7E52A87D32E5C498B06@qq.com>

fmpeg -i rtmp://xxx/live/xxx -bsf:v
"h264_mp4toannexb,h264_metadata=aud=remove" -c copy -f null -

For h264_mp4toannexb, input 264 is avcc,  output is annexb. and for
h264_metadata, both input and output are annexb.
If the sps/pps header is updated,  flvdec module will insert
AV_PKT_DATA_NEW_EXTRADATA to AVPacket and is this format of header is avcc.
In cbs_bsf_update_side_data function, it will find
AV_PKT_DATA_NEW_EXTRADATA and this extradata is avcc, that will cause
h264_metadata to judge that its input is also avcc, but  its input  is from
h264_mp4toannexb. Using the logic of parsing avcc to parse annexb is
problematic.




On Thu, Apr 24, 2025 at 12:19 PM Zhao Zhili <quinkblack@foxmail.com> wrote:

>
>
> > On Apr 24, 2025, at 11:38, jiangjie <jiangjie618@gmail.com> wrote:
> >
> > if get AV_PKT_DATA_NEW_EXTRADATA in AVPacket, this bitstream filter will
> return an error.
> > ffmpeg -i rtmp://xxx/live/xxx -bsf:v
> "h264_mp4toannexb,h264_metadata=aud=remove" -c copy -f null -
>
> H.264 in FLV is avcc. Which service provider use annexb in FLV?
>
> And I don’t think it makes sense to use AV_PKT_DATA_NEW_EXTRADATA together
> with annexb.
>
> > ---
> > libavcodec/bsf/h264_mp4toannexb.c | 26 ++++++++++++++++++++------
> > 1 file changed, 20 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavcodec/bsf/h264_mp4toannexb.c
> b/libavcodec/bsf/h264_mp4toannexb.c
> > index dda064287e..4cd002d166 100644
> > --- a/libavcodec/bsf/h264_mp4toannexb.c
> > +++ b/libavcodec/bsf/h264_mp4toannexb.c
> > @@ -252,14 +252,21 @@ static int
> h264_mp4toannexb_filter_ps(H264BSFContext *s,
> >     return 0;
> > }
> >
> > +static int is_annexb(const uint8_t *extradata, int extra_size) {
> > +    if (!extra_size || (extra_size >= 3 && AV_RB24(extradata) == 1) ||
> > +        (extra_size >= 4 && AV_RB32(extradata) == 1)) {
> > +        return 1;
> > +    } else {
> > +        return 0;
> > +    }
> > +}
> > +
> > static int h264_mp4toannexb_init(AVBSFContext *ctx)
> > {
> >     int extra_size = ctx->par_in->extradata_size;
> >
> >     /* retrieve sps and pps NAL units from extradata */
> > -    if (!extra_size                                               ||
> > -        (extra_size >= 3 && AV_RB24(ctx->par_in->extradata) == 1) ||
> > -        (extra_size >= 4 && AV_RB32(ctx->par_in->extradata) == 1)) {
> > +    if (is_annexb(ctx->par_in->extradata, extra_size)) {
> >         av_log(ctx, AV_LOG_VERBOSE,
> >                "The input looks like it is Annex B already\n");
> >     } else if (extra_size >= 7) {
> > @@ -294,9 +301,16 @@ static int h264_mp4toannexb_filter(AVBSFContext
> *ctx, AVPacket *opkt)
> >     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;
> > +        if (!is_annexb(extradata, extradata_size) && extradata_size >=
> 7) {
> > +            ret = h264_extradata_to_annexb(ctx, extradata,
> extradata_size);
> > +            if (ret < 0)
> > +                goto fail;
> > +            av_packet_side_data_remove(in->side_data,
> &in->side_data_elems,
> > +                                       AV_PKT_DATA_NEW_EXTRADATA);
> > +            av_packet_add_side_data(in, AV_PKT_DATA_NEW_EXTRADATA,
> > +                                    ctx->par_out->extradata,
> > +                                    ctx->par_out->extradata_size);
> > +        }
> >     }
> >
> >     /* nothing to filter */
> > --
> > 2.49.0
> >
> > _______________________________________________
> > 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".
>
>
_______________________________________________
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".

  reply	other threads:[~2025-04-24  5:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-24  3:38 jiangjie
2025-04-24  4:19 ` Zhao Zhili
2025-04-24  5:18   ` jie jiang [this message]
2025-04-24  6:41     ` Zhao Zhili
2025-04-24 12:42 ` jiangjie
2025-04-24 13:04   ` jie jiang
2025-04-24 14:03     ` Zhao Zhili
2025-04-24 14:20   ` Zhao Zhili
2025-04-24 14:53     ` jie jiang
2025-04-24 17:23       ` Zhao Zhili
2025-04-25  2:41         ` jie jiang

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='CAJ53Rru_vypPmxxV7oYueCX6SpWgTyPcj6E65Ay=skPyT9wc0w@mail.gmail.com' \
    --to=jiangjie618@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=quinkblack@foxmail.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