Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata
@ 2021-12-20 18:22 Andreas Rheinhardt
  2021-12-20 18:27 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libx26[45]: Don't forward old x26[45] SEI's Andreas Rheinhardt
  2021-12-21  1:42 ` [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata lance.lmwang
  0 siblings, 2 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2021-12-20 18:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

The check here is meant to check for whether avcintra-class option
(default value -1) has been set; yet it checks for the x264_param_t
value where 0 is the default value (treated as "no avcintra-mode"
by x264). This meant that in-band extradata has been added unnecessarily
when using global headers; furthermore, the first output packet
had two x264 SEIs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
This would have been found ages ago if we could test external
components.

 libavcodec/libx264.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 5f62c7b1d8..2b680abf21 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -944,7 +944,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
 
 #if X264_BUILD >= 142
     /* Separate headers not supported in AVC-Intra mode */
-    if (x4->params.i_avcintra_class >= 0)
+    if (x4->avcintra_class >= 0)
         x4->params.b_repeat_headers = 1;
 #endif
 
-- 
2.32.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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avcodec/libx26[45]: Don't forward old x26[45] SEI's
  2021-12-20 18:22 [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata Andreas Rheinhardt
@ 2021-12-20 18:27 ` Andreas Rheinhardt
  2021-12-21  1:52   ` lance.lmwang
  2021-12-21  1:42 ` [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata lance.lmwang
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Rheinhardt @ 2021-12-20 18:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Currently, user data unregistered SEIs found in input are
forwarded as side-data to encoders; for the libx26[45] encoders
these are included in the reencoded output (even including x264 SEIs
in H.265 and vice versa).
This makes tools like mediainfo display the wrong (old) encoding
parameters and basically makes these SEI messages useless.
This commit therefore filters the SEI messages by some known,
recognized encoders away.
This fixes tickets #9500 and #9557.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
1. Obviously, having to maintain a list of recognized encoders and
their uuids is horrible; but I didn't see another way.
2. nvenc is probably also affected by this; but I couldn't test it
anyway, so someone else will have to fix it.
3. How could it happen that no one noticed this issue when the SEI
patches were applied?

 libavcodec/Makefile  |  6 +++---
 libavcodec/libx264.c |  3 ++-
 libavcodec/libx265.c |  3 ++-
 libavcodec/sei.c     | 38 ++++++++++++++++++++++++++++++++++++++
 libavcodec/sei.h     |  9 +++++++++
 5 files changed, 54 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/sei.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb90ecea84..969311947f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1066,9 +1066,9 @@ OBJS-$(CONFIG_LIBVPX_VP9_DECODER)         += libvpxdec.o libvpx.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER)         += libvpxenc.o libvpx.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)            += libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)       += libwebpenc_common.o libwebpenc_animencoder.o
-OBJS-$(CONFIG_LIBX262_ENCODER)            += libx264.o
-OBJS-$(CONFIG_LIBX264_ENCODER)            += libx264.o
-OBJS-$(CONFIG_LIBX265_ENCODER)            += libx265.o
+OBJS-$(CONFIG_LIBX262_ENCODER)            += libx264.o sei.o
+OBJS-$(CONFIG_LIBX264_ENCODER)            += libx264.o sei.o
+OBJS-$(CONFIG_LIBX265_ENCODER)            += libx265.o sei.o
 OBJS-$(CONFIG_LIBXAVS_ENCODER)            += libxavs.o
 OBJS-$(CONFIG_LIBXAVS2_ENCODER)           += libxavs2.o
 OBJS-$(CONFIG_LIBXVID_ENCODER)            += libxvid.o
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 2b680abf21..27920ba295 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -468,7 +468,8 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
             AVFrameSideData *side_data = frame->side_data[j];
             void *tmp;
             x264_sei_payload_t *sei_payload;
-            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
+            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED ||
+                side_data->size < 16 || ff_sei_is_encoder_uuid(side_data->data))
                 continue;
             tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload));
             if (!tmp) {
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 7dd70a3450..bb2133f4a4 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -548,7 +548,8 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             void *tmp;
             x265_sei_payload *sei_payload;
 
-            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
+            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED ||
+                side_data->size < 16 || ff_sei_is_encoder_uuid(side_data->data))
                 continue;
 
             tmp = av_fast_realloc(ctx->sei_data,
diff --git a/libavcodec/sei.c b/libavcodec/sei.c
new file mode 100644
index 0000000000..8678704e6f
--- /dev/null
+++ b/libavcodec/sei.c
@@ -0,0 +1,38 @@
+/*
+ * Filtering of H.26[45] encoder user data unregistered SEI messages
+ * Copyright (C) 2021 Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include "sei.h"
+
+int ff_sei_is_encoder_uuid(const uint8_t uuid[16])
+{
+    static const uint8_t x264_uuid[] = {
+        0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7,
+        0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef
+    };
+    static const uint8_t x265_uuid[] = {
+        0x2c, 0xa2, 0xde, 0x09, 0xb5, 0x17, 0x47, 0xdb,
+        0xbb, 0x55, 0xa4, 0xfe, 0x7f, 0xc2, 0xfc, 0x4e
+    };
+    return !memcmp(uuid, x264_uuid, sizeof(x264_uuid)) ||
+           !memcmp(uuid, x265_uuid, sizeof(x265_uuid));
+}
diff --git a/libavcodec/sei.h b/libavcodec/sei.h
index 5513590b51..e143e0f045 100644
--- a/libavcodec/sei.h
+++ b/libavcodec/sei.h
@@ -19,6 +19,8 @@
 #ifndef AVCODEC_SEI_H
 #define AVCODEC_SEI_H
 
+#include <stdint.h>
+
 // SEI payload types form a common namespace between the H.264, H.265
 // and H.266 standards.  A given payload type always has the same
 // meaning, but some names have different payload types in different
@@ -137,4 +139,11 @@ enum {
     SEI_TYPE_SAMPLE_ASPECT_RATIO_INFO                    = 204,
 };
 
+/**
+ * Returns 0 iff the uuid does not match the uuid of
+ * a user_data_unregistered SEI message emitted by
+ * a recognized encoder.
+ */
+int ff_sei_is_encoder_uuid(const uint8_t uuid[16]);
+
 #endif /* AVCODEC_SEI_H */
-- 
2.32.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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata
  2021-12-20 18:22 [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata Andreas Rheinhardt
  2021-12-20 18:27 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libx26[45]: Don't forward old x26[45] SEI's Andreas Rheinhardt
@ 2021-12-21  1:42 ` lance.lmwang
  1 sibling, 0 replies; 4+ messages in thread
From: lance.lmwang @ 2021-12-21  1:42 UTC (permalink / raw)
  To: ffmpeg-devel

On Mon, Dec 20, 2021 at 07:22:56PM +0100, Andreas Rheinhardt wrote:
> The check here is meant to check for whether avcintra-class option
> (default value -1) has been set; yet it checks for the x264_param_t
> value where 0 is the default value (treated as "no avcintra-mode"
> by x264). This meant that in-band extradata has been added unnecessarily
> when using global headers; furthermore, the first output packet
> had two x264 SEIs.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> This would have been found ages ago if we could test external
> components.
> 
>  libavcodec/libx264.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 5f62c7b1d8..2b680abf21 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -944,7 +944,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
>  
>  #if X264_BUILD >= 142
>      /* Separate headers not supported in AVC-Intra mode */
> -    if (x4->params.i_avcintra_class >= 0)
> +    if (x4->avcintra_class >= 0)
>          x4->params.b_repeat_headers = 1;
>  #endif
>  
> -- 
> 2.32.0

good catch, LGTM, thanks.


> 
> _______________________________________________
> 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".

-- 
Thanks,
Limin Wang
_______________________________________________
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] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libx26[45]: Don't forward old x26[45] SEI's
  2021-12-20 18:27 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libx26[45]: Don't forward old x26[45] SEI's Andreas Rheinhardt
@ 2021-12-21  1:52   ` lance.lmwang
  0 siblings, 0 replies; 4+ messages in thread
From: lance.lmwang @ 2021-12-21  1:52 UTC (permalink / raw)
  To: ffmpeg-devel

On Mon, Dec 20, 2021 at 07:27:30PM +0100, Andreas Rheinhardt wrote:
> Currently, user data unregistered SEIs found in input are
> forwarded as side-data to encoders; for the libx26[45] encoders
> these are included in the reencoded output (even including x264 SEIs
> in H.265 and vice versa).
> This makes tools like mediainfo display the wrong (old) encoding
> parameters and basically makes these SEI messages useless.
> This commit therefore filters the SEI messages by some known,
> recognized encoders away.
> This fixes tickets #9500 and #9557.

I prefer to add an option so that we can disable the forwarded for
user data unregistered if need. It's better to disable it default.
Most of user data unregistered have their own private format, it's
not preferable to forward it to new encoder directly.

> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> 1. Obviously, having to maintain a list of recognized encoders and
> their uuids is horrible; but I didn't see another way.
> 2. nvenc is probably also affected by this; but I couldn't test it
> anyway, so someone else will have to fix it.
> 3. How could it happen that no one noticed this issue when the SEI
> patches were applied?
> 
>  libavcodec/Makefile  |  6 +++---
>  libavcodec/libx264.c |  3 ++-
>  libavcodec/libx265.c |  3 ++-
>  libavcodec/sei.c     | 38 ++++++++++++++++++++++++++++++++++++++
>  libavcodec/sei.h     |  9 +++++++++
>  5 files changed, 54 insertions(+), 5 deletions(-)
>  create mode 100644 libavcodec/sei.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index fb90ecea84..969311947f 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1066,9 +1066,9 @@ OBJS-$(CONFIG_LIBVPX_VP9_DECODER)         += libvpxdec.o libvpx.o
>  OBJS-$(CONFIG_LIBVPX_VP9_ENCODER)         += libvpxenc.o libvpx.o
>  OBJS-$(CONFIG_LIBWEBP_ENCODER)            += libwebpenc_common.o libwebpenc.o
>  OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)       += libwebpenc_common.o libwebpenc_animencoder.o
> -OBJS-$(CONFIG_LIBX262_ENCODER)            += libx264.o
> -OBJS-$(CONFIG_LIBX264_ENCODER)            += libx264.o
> -OBJS-$(CONFIG_LIBX265_ENCODER)            += libx265.o
> +OBJS-$(CONFIG_LIBX262_ENCODER)            += libx264.o sei.o
> +OBJS-$(CONFIG_LIBX264_ENCODER)            += libx264.o sei.o
> +OBJS-$(CONFIG_LIBX265_ENCODER)            += libx265.o sei.o
>  OBJS-$(CONFIG_LIBXAVS_ENCODER)            += libxavs.o
>  OBJS-$(CONFIG_LIBXAVS2_ENCODER)           += libxavs2.o
>  OBJS-$(CONFIG_LIBXVID_ENCODER)            += libxvid.o
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 2b680abf21..27920ba295 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -468,7 +468,8 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>              AVFrameSideData *side_data = frame->side_data[j];
>              void *tmp;
>              x264_sei_payload_t *sei_payload;
> -            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
> +            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED ||
> +                side_data->size < 16 || ff_sei_is_encoder_uuid(side_data->data))
>                  continue;
>              tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload));
>              if (!tmp) {
> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> index 7dd70a3450..bb2133f4a4 100644
> --- a/libavcodec/libx265.c
> +++ b/libavcodec/libx265.c
> @@ -548,7 +548,8 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>              void *tmp;
>              x265_sei_payload *sei_payload;
>  
> -            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
> +            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED ||
> +                side_data->size < 16 || ff_sei_is_encoder_uuid(side_data->data))
>                  continue;
>  
>              tmp = av_fast_realloc(ctx->sei_data,
> diff --git a/libavcodec/sei.c b/libavcodec/sei.c
> new file mode 100644
> index 0000000000..8678704e6f
> --- /dev/null
> +++ b/libavcodec/sei.c
> @@ -0,0 +1,38 @@
> +/*
> + * Filtering of H.26[45] encoder user data unregistered SEI messages
> + * Copyright (C) 2021 Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <stdint.h>
> +#include <string.h>
> +#include "sei.h"
> +
> +int ff_sei_is_encoder_uuid(const uint8_t uuid[16])
> +{
> +    static const uint8_t x264_uuid[] = {
> +        0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7,
> +        0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef
> +    };
> +    static const uint8_t x265_uuid[] = {
> +        0x2c, 0xa2, 0xde, 0x09, 0xb5, 0x17, 0x47, 0xdb,
> +        0xbb, 0x55, 0xa4, 0xfe, 0x7f, 0xc2, 0xfc, 0x4e
> +    };
> +    return !memcmp(uuid, x264_uuid, sizeof(x264_uuid)) ||
> +           !memcmp(uuid, x265_uuid, sizeof(x265_uuid));
> +}
> diff --git a/libavcodec/sei.h b/libavcodec/sei.h
> index 5513590b51..e143e0f045 100644
> --- a/libavcodec/sei.h
> +++ b/libavcodec/sei.h
> @@ -19,6 +19,8 @@
>  #ifndef AVCODEC_SEI_H
>  #define AVCODEC_SEI_H
>  
> +#include <stdint.h>
> +
>  // SEI payload types form a common namespace between the H.264, H.265
>  // and H.266 standards.  A given payload type always has the same
>  // meaning, but some names have different payload types in different
> @@ -137,4 +139,11 @@ enum {
>      SEI_TYPE_SAMPLE_ASPECT_RATIO_INFO                    = 204,
>  };
>  
> +/**
> + * Returns 0 iff the uuid does not match the uuid of
> + * a user_data_unregistered SEI message emitted by
> + * a recognized encoder.
> + */
> +int ff_sei_is_encoder_uuid(const uint8_t uuid[16]);
> +
>  #endif /* AVCODEC_SEI_H */
> -- 
> 2.32.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".

-- 
Thanks,
Limin Wang
_______________________________________________
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] 4+ messages in thread

end of thread, other threads:[~2021-12-21  1:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 18:22 [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata Andreas Rheinhardt
2021-12-20 18:27 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libx26[45]: Don't forward old x26[45] SEI's Andreas Rheinhardt
2021-12-21  1:52   ` lance.lmwang
2021-12-21  1:42 ` [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: Don't unnecessarily add in-band extradata lance.lmwang

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