* [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 @ 2023-05-29 22:16 Zhao Zhili 2023-05-29 14:46 ` Anton Khirnov 2023-05-30 1:03 ` [FFmpeg-devel] [PATCH] " Lance Wang 0 siblings, 2 replies; 10+ messages in thread From: Zhao Zhili @ 2023-05-29 22:16 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili 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; 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 2023-05-29 22:16 [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 Zhao Zhili @ 2023-05-29 14:46 ` Anton Khirnov 2023-05-29 15:08 ` Zhao Zhili 2023-05-30 1:03 ` [FFmpeg-devel] [PATCH] " Lance Wang 1 sibling, 1 reply; 10+ messages in thread From: Anton Khirnov @ 2023-05-29 14:46 UTC (permalink / raw) To: FFmpeg development discussions and patches; +Cc: Zhao Zhili Quoting Zhao Zhili (2023-05-30 00:16:05) >Subject: Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 "fix bug" commit message are not very useful -- Anton Khirnov _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 2023-05-29 14:46 ` Anton Khirnov @ 2023-05-29 15:08 ` Zhao Zhili 2023-05-29 15:16 ` Anton Khirnov 0 siblings, 1 reply; 10+ messages in thread From: Zhao Zhili @ 2023-05-29 15:08 UTC (permalink / raw) To: FFmpeg development discussions and patches; +Cc: Zhao Zhili > 在 2023年5月29日,22:46,Anton Khirnov <anton@khirnov.net> 写道: > > Quoting Zhao Zhili (2023-05-30 00:16:05) >> Subject: Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 > > "fix bug" commit message are not very useful However, CODECS attribute is a particular detail for HLS. Any suggestions to make it more clear and not too verbose? > > -- > Anton Khirnov > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 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 0 siblings, 1 reply; 10+ messages in thread From: Anton Khirnov @ 2023-05-29 15:16 UTC (permalink / raw) To: FFmpeg development discussions and patches; +Cc: Zhao Zhili Quoting Zhao Zhili (2023-05-29 17:08:50) > > > 在 2023年5月29日,22:46,Anton Khirnov <anton@khirnov.net> 写道: > > > > Quoting Zhao Zhili (2023-05-30 00:16:05) > >> Subject: Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 > > > > "fix bug" commit message are not very useful > > However, CODECS attribute is a particular detail for HLS. Any suggestions to make it more clear and not too verbose? Keep the first line as is, but add a commit message body that says at least what the problem was. Possibly also how it's being fixed, if it is not obvious. -- Anton Khirnov _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2] avformat/hlsenc: fix CODECS attribute of H.264 2023-05-29 15:16 ` Anton Khirnov @ 2023-06-08 2:45 ` Zhao Zhili 2023-06-09 4:58 ` Lance Wang 0 siblings, 1 reply; 10+ messages in thread From: Zhao Zhili @ 2023-06-08 2:45 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> 1. Add avcc extradata support. 2. Add non-standard annexb support with 0 0 1 as prefix for SPS. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- v2: Describe what the patch does. 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; 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/hlsenc: fix CODECS attribute of H.264 2023-06-08 2:45 ` [FFmpeg-devel] [PATCH v2] " Zhao Zhili @ 2023-06-09 4:58 ` Lance Wang 0 siblings, 0 replies; 10+ messages in thread From: Lance Wang @ 2023-06-09 4:58 UTC (permalink / raw) To: FFmpeg development discussions and patches On Thu, Jun 8, 2023 at 10:47 AM Zhao Zhili <quinkblack@foxmail.com> wrote: > From: Zhao Zhili <zhilizhao@tencent.com> > > 1. Add avcc extradata support. > 2. Add non-standard annexb support with 0 0 1 as prefix for SPS. > > LGTM > Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> > --- > v2: Describe what the patch does. > > 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; > 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 2023-05-29 22:16 [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 Zhao Zhili 2023-05-29 14:46 ` Anton Khirnov @ 2023-05-30 1:03 ` Lance Wang 2023-05-30 3:09 ` "zhilizhao(赵志立)" 1 sibling, 1 reply; 10+ messages in thread From: Lance Wang @ 2023-05-30 1:03 UTC (permalink / raw) To: FFmpeg development discussions and patches 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. > 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 2023-05-30 1:03 ` [FFmpeg-devel] [PATCH] " Lance Wang @ 2023-05-30 3:09 ` "zhilizhao(赵志立)" 2023-05-30 4:44 ` Lance Wang 0 siblings, 1 reply; 10+ messages in thread From: "zhilizhao(赵志立)" @ 2023-05-30 3:09 UTC (permalink / raw) To: FFmpeg development discussions and patches > 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. 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. > > >> 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 2023-05-30 3:09 ` "zhilizhao(赵志立)" @ 2023-05-30 4:44 ` Lance Wang 2023-05-30 5:28 ` "zhilizhao(赵志立)" 0 siblings, 1 reply; 10+ messages in thread From: Lance Wang @ 2023-05-30 4:44 UTC (permalink / raw) To: FFmpeg development discussions and patches 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 2023-05-30 4:44 ` Lance Wang @ 2023-05-30 5:28 ` "zhilizhao(赵志立)" 0 siblings, 0 replies; 10+ messages in thread From: "zhilizhao(赵志立)" @ 2023-05-30 5:28 UTC (permalink / raw) To: FFmpeg development discussions and patches > On May 30, 2023, at 12:44, Lance Wang <lance.lmwang@gmail.com> wrote: > > 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. Use mp4toannexb for TS segments is a good practice, but not for fmp4. No comments on hevc. > Also we should > check the size of extradata. extradata has a AV_INPUT_BUFFER_PADDING_SIZE, so not necessary. > > > >> 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. Yes, but it’s not the first time people don’t follow spec. > > > >> >>> >>> >>>> 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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-06-09 4:58 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-05-29 22:16 [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS attribute of H.264 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 2023-05-30 5:28 ` "zhilizhao(赵志立)"
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