diff mbox series

[FFmpeg-devel,v2] avformat/hlsenc: fix CODECS attribute of H.264

Message ID tencent_FFF5697E7CAAAD2A3A25C0BDB6346BD2000A@qq.com
State New
Headers show
Series [FFmpeg-devel,v2] avformat/hlsenc: fix CODECS attribute of H.264 | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Zhao Zhili June 8, 2023, 2:45 a.m. UTC
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(-)

Comments

Lance Wang June 9, 2023, 4:58 a.m. UTC | #1
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".
>
diff mbox series

Patch

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;
         }