From: Lance Wang <lance.lmwang@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 Date: Tue, 30 May 2023 12:44:54 +0800 Message-ID: <CAM=jba8MdARCMZqTMZ1zz_GA6cRaUpDJa9dqR6NmyQuWbvjgUQ@mail.gmail.com> (raw) In-Reply-To: <tencent_3475D489168EA8E54B9306685333F3736D05@qq.com> On Tue, May 30, 2023 at 11:09 AM "zhilizhao(赵志立)" <quinkblack@foxmail.com> wrote: > > > > On May 30, 2023, at 09:03, Lance Wang <lance.lmwang@gmail.com> wrote: > > > > On Mon, May 29, 2023 at 10:16 PM Zhao Zhili <quinkblack@foxmail.com> > wrote: > > > >> From: Zhao Zhili <zhilizhao@tencent.com> > >> > >> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> > >> --- > >> libavformat/hlsenc.c | 14 ++++++++++++-- > >> 1 file changed, 12 insertions(+), 2 deletions(-) > >> > >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c > >> index 871afb571b..1e0848ce3d 100644 > >> --- a/libavformat/hlsenc.c > >> +++ b/libavformat/hlsenc.c > >> @@ -355,9 +355,19 @@ static void write_codec_attr(AVStream *st, > >> VariantStream *vs) > >> > >> if (st->codecpar->codec_id == AV_CODEC_ID_H264) { > >> uint8_t *data = st->codecpar->extradata; > >> - if (data && (data[0] | data[1] | data[2]) == 0 && data[3] == 1 > && > >> (data[4] & 0x1F) == 7) { > >> + if (data) { > >> + const uint8_t *p; > >> + > >> + if (AV_RB32(data) == 0x01 && (data[4] & 0x1F) == 7) > >> + p = &data[5]; > >> + else if (AV_RB24(data) == 0x01 && (data[3] & 0x1F) == 7) > >> + p = &data[4]; > >> + else if (data[0] == 0x01) /* avcC */ > >> + p = &data[1]; > >> + else > >> + goto fail; > >> > > > > how to reproduce the issue? I recall mpegts is annex b format and sps/pps > > start code is 4 byte always. > > For example: > > ffmpeg -i foo.mp4 -c copy -hls_playlist_type vod -master_pl_name bar.m3u8 > test.m3u8 > > 1. The input of hls muxer can be avcc > > 2. The output of hls muxer can be avcc too, with fmp4 segments. > > Yes, this is the case. I had to add mp4toannexb bsf after the copy for avcc input. If we don't add the format conversion, hevc may have the same issue I guess. Also we should check the size of extradata. > 3. Start code of SPS/PPS should be 0 0 0 1, however, 0 0 1 exist in wild. > ff_isom_write_avcc() does the same: > > /* check for H.264 start code */ > if (AV_RB32(data) != 0x00000001 && > AV_RB24(data) != 0x000001) { > avio_write(pb, data, len); > return 0; > } > > ff_isom_write_avcc() can be used here, and get/create CODECS attribute can > be > shared by multiple muxers. I won't go that further by now. > > The next NALU checking is for SPS only, so one more byte is zero_byte. It's required by specs: zero_byte is a single byte equal to 0x00. When any of the following conditions are true, the zero_byte syntax element shall be present: - – the nal_unit_type within the nal_unit( ) is equal to 7 (sequence parameter set) or 8 (picture parameter set), - – the byte stream NAL unit syntax structure contains the first NAL unit of an access unit in decoding order, as specified in clause 7.4.1.2.3. > > > > > > >> snprintf(attr, sizeof(attr), > >> - "avc1.%02x%02x%02x", data[5], data[6], data[7]); > >> + "avc1.%02x%02x%02x", p[0], p[1], p[2]); > >> } else { > >> goto fail; > >> } > >> -- > >> 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". > >> > > _______________________________________________ > > 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". > _______________________________________________ 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".
next prev parent reply other threads:[~2023-05-30 4:45 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-29 22:16 Zhao Zhili 2023-05-29 14:46 ` Anton Khirnov 2023-05-29 15:08 ` Zhao Zhili 2023-05-29 15:16 ` Anton Khirnov 2023-06-08 2:45 ` [FFmpeg-devel] [PATCH v2] " Zhao Zhili 2023-06-09 4:58 ` Lance Wang 2023-05-30 1:03 ` [FFmpeg-devel] [PATCH] " Lance Wang 2023-05-30 3:09 ` "zhilizhao(赵志立)" 2023-05-30 4:44 ` Lance Wang [this message] 2023-05-30 5:28 ` "zhilizhao(赵志立)"
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='CAM=jba8MdARCMZqTMZ1zz_GA6cRaUpDJa9dqR6NmyQuWbvjgUQ@mail.gmail.com' \ --to=lance.lmwang@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /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