Re: [FFmpeg-devel] [PATCH] avcodec: add VMX1 decoder

2023-06-08 Thread Jean-Baptiste Kempf
On Thu, 8 Jun 2023, at 19:39, Paul B Mahol wrote:
> Attached.

Missing version bumping?

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


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

2023-06-08 Thread Lance Wang
On Thu, Jun 8, 2023 at 10:47 AM Zhao Zhili  wrote:

> From: Zhao Zhili 
>
> 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 
> ---
> 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 = [5];
> +else if (AV_RB24(data) == 0x01 && (data[3] & 0x1F) == 7)
> +p = [4];
> +else if (data[0] == 0x01)  /* avcC */
> +p = [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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/mov: Don't allocate unnecessarily large blocks of memory

2023-06-08 Thread zhilizhao(赵志立)


> On Jun 9, 2023, at 07:51, Hendi  wrote:
> 
> mov_try_read_block is regularly called with sizes such as 48 bytes,
> but would allocate 1 MiB each time, hogging more and more memory
> until playback ends.
> 
> Fixes #7641 and #9243.

It’s a quick fix, but I’m afraid the two tickets are caused by more deep
pitfalls.

It would be helpful if someone can provide a sample for test.

> 
> Signed-off-by: Hendi 
> ---
> libavformat/mov.c | 3 +++
> 1 file changed, 3 insertions(+)
> 
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index a8d004e02b..2e4df42256 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -6662,6 +6662,9 @@ static int mov_try_read_block(AVIOContext *pb, size_t 
> size, uint8_t **data)
> while (offset < size) {
> unsigned int new_size =
> alloc_size >= INT_MAX - block_size ? INT_MAX : alloc_size + 
> block_size;
> +if (size < new_size) {
> +new_size = size;
> +}
> uint8_t *new_buffer = av_fast_realloc(buffer, _size, new_size);
> unsigned int to_read = FFMIN(size, alloc_size) - offset;
> if (!new_buffer) {
> -- 
> 2.40.0.windows.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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 4/5] avformat/jpegxl_probe: inline various ret < 0 checks

2023-06-08 Thread James Almer

On 6/8/2023 11:32 PM, Anton Khirnov wrote:

Quoting Leo Izen (2023-06-08 16:26:36)

Inlines some ret < 0 checks to look like:
 if ((ret = func()) < 0)
 return ret;

which clarifies code slightly.


FWIW I find this variant less readable.
But it's your code, so up to you.


Agree. It's both less readable and more prone to mistakes.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 4/5] avformat/jpegxl_probe: inline various ret < 0 checks

2023-06-08 Thread Anton Khirnov
Quoting Leo Izen (2023-06-08 16:26:36)
> Inlines some ret < 0 checks to look like:
> if ((ret = func()) < 0)
> return ret;
> 
> which clarifies code slightly.

FWIW I find this variant less readable.
But it's your code, so up to you.

-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 5/5] avformat/jpegxl_anim_dec: avoid overrun with jxlp boxes in container

2023-06-08 Thread Anton Khirnov
Quoting Leo Izen (2023-06-08 16:26:37)
> This should avoid overrunning buffers with jxlp boxes if the size is
> zero or if the size is so small the box is invalid.
> 
> Signed-off-by: Leo Izen 
> ---
>  libavformat/jpegxl_anim_dec.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c
> index 6ea6c46d8f..c9e4dcd5fc 100644
> --- a/libavformat/jpegxl_anim_dec.c
> +++ b/libavformat/jpegxl_anim_dec.c
> @@ -76,8 +76,14 @@ static int jpegxl_collect_codestream_header(const uint8_t 
> *input_buffer, int inp
>  tag = AV_RL32(b);
>  b += 4;
>  if (tag == MKTAG('j', 'x', 'l', 'p')) {
> +if (b - input_buffer >= input_len - 4)
> +break;
>  b += 4;
> -size -= 4;
> +if (size) {
> +if (size < 4)
> +return AVERROR_INVALIDDATA;
> +size -= 4;
> +}

This looks like it should be using bytestream2. Is there a good reason
it is not?

-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH Resubmission] avformat/mov: Don't allocate unnecessarily large blocks of memory

2023-06-08 Thread Hendi

Attached this time, Thunderbird trashed the first one.From 46cef86a0ffd5f9e0bbf74c99e4ee32120823cb1 Mon Sep 17 00:00:00 2001
From: Hendi 
Date: Fri, 9 Jun 2023 01:13:25 +0200
Subject: [PATCH] avformat/mov: Don't allocate unnecessarily large blocks of
 memory

mov_try_read_block is regularly called with sizes such as 48 bytes,
but would allocate 1 MiB each time, hogging more and more memory
until playback ends.

Fixes #7641 and #9243.

Signed-off-by: Hendi 
---
 libavformat/mov.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index a8d004e02b..2e4df42256 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6662,6 +6662,9 @@ static int mov_try_read_block(AVIOContext *pb, size_t 
size, uint8_t **data)
 while (offset < size) {
 unsigned int new_size =
 alloc_size >= INT_MAX - block_size ? INT_MAX : alloc_size + 
block_size;
+if (size < new_size) {
+new_size = size;
+}
 uint8_t *new_buffer = av_fast_realloc(buffer, _size, new_size);
 unsigned int to_read = FFMIN(size, alloc_size) - offset;
 if (!new_buffer) {
-- 
2.40.0.windows.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avformat/mov: Don't allocate unnecessarily large blocks of memory

2023-06-08 Thread Hendi

mov_try_read_block is regularly called with sizes such as 48 bytes,
but would allocate 1 MiB each time, hogging more and more memory
until playback ends.

Fixes #7641 and #9243.

Signed-off-by: Hendi 
---
 libavformat/mov.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index a8d004e02b..2e4df42256 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6662,6 +6662,9 @@ static int mov_try_read_block(AVIOContext *pb, 
size_t size, uint8_t **data)

 while (offset < size) {
 unsigned int new_size =
 alloc_size >= INT_MAX - block_size ? INT_MAX : alloc_size 
+ block_size;

+if (size < new_size) {
+new_size = size;
+}
 uint8_t *new_buffer = av_fast_realloc(buffer, _size, 
new_size);

 unsigned int to_read = FFMIN(size, alloc_size) - offset;
 if (!new_buffer) {
--
2.40.0.windows.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avcodec: add VMX1 decoder

2023-06-08 Thread Paul B Mahol
Attached.
From 2e0bbbc73afeac43e8cb7e2d5c78647725c764ba Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Sun, 4 Jun 2023 20:30:59 +0200
Subject: [PATCH] avcodec: add VMX1 decoder

Signed-off-by: Paul B Mahol 
---
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/codec_desc.c |   7 +
 libavcodec/codec_id.h   |   1 +
 libavcodec/vmixdec.c| 288 
 libavformat/riff.c  |   1 +
 6 files changed, 299 insertions(+)
 create mode 100644 libavcodec/vmixdec.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 87a8b90037..2efab60d7d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -753,6 +753,7 @@ OBJS-$(CONFIG_VC2_ENCODER) += vc2enc.o vc2enc_dwt.o diractab.o
 OBJS-$(CONFIG_VCR1_DECODER)+= vcr1.o
 OBJS-$(CONFIG_VMDAUDIO_DECODER)+= vmdaudio.o
 OBJS-$(CONFIG_VMDVIDEO_DECODER)+= vmdvideo.o
+OBJS-$(CONFIG_VMIX_DECODER)+= vmixdec.o
 OBJS-$(CONFIG_VMNC_DECODER)+= vmnc.o
 OBJS-$(CONFIG_VNULL_DECODER)   += null.o
 OBJS-$(CONFIG_VNULL_ENCODER)   += null.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a98c300da4..11c136ef59 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -370,6 +370,7 @@ extern const FFCodec ff_vc1_v4l2m2m_decoder;
 extern const FFCodec ff_vc2_encoder;
 extern const FFCodec ff_vcr1_decoder;
 extern const FFCodec ff_vmdvideo_decoder;
+extern const FFCodec ff_vmix_decoder;
 extern const FFCodec ff_vmnc_decoder;
 extern const FFCodec ff_vp3_decoder;
 extern const FFCodec ff_vp4_decoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 41293a78dc..3e31a1eed6 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1953,6 +1953,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("RTV1 (RivaTuner Video)"),
 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_VMIX,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "vmix",
+.long_name = NULL_IF_CONFIG_SMALL("vMix Video"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 9a78cfabe2..d23549d7e0 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -323,6 +323,7 @@ enum AVCodecID {
 AV_CODEC_ID_PDV,
 AV_CODEC_ID_EVC,
 AV_CODEC_ID_RTV1,
+AV_CODEC_ID_VMIX,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the start of audio codecs
diff --git a/libavcodec/vmixdec.c b/libavcodec/vmixdec.c
new file mode 100644
index 00..a9cb704964
--- /dev/null
+++ b/libavcodec/vmixdec.c
@@ -0,0 +1,288 @@
+/*
+ * vMix decoder
+ * Copyright (c) 2023 Paul B Mahol
+ *
+ * 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 
+#include 
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include "decode.h"
+#define CACHED_BITSTREAM_READER !ARCH_X86_32
+#include "golomb.h"
+#include "get_bits.h"
+#include "idctdsp.h"
+#include "thread.h"
+
+typedef struct SliceContext {
+const uint8_t *dc_ptr;
+const uint8_t *ac_ptr;
+unsigned dc_size;
+unsigned ac_size;
+} SliceContext;
+
+typedef struct VMIXContext {
+int nb_slices;
+
+int16_t factors[64];
+uint8_t scan[64];
+
+SliceContext slices[255];
+
+IDCTDSPContext idsp;
+} VMIXContext;
+
+static const uint8_t quality[25] = {
+ 1,  2,  3,  4,  5,  6,  7,  8, 10, 12, 14, 16,
+18, 20, 22, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64,
+};
+
+static const uint8_t quant[64] = {
+16, 16, 19, 22, 22, 26, 26, 27,
+16, 16, 22, 22, 26, 27, 27, 29,
+19, 22, 26, 26, 27, 29, 29, 35,
+22, 24, 27, 27, 29, 32, 34, 38,
+26, 27, 29, 29, 32, 35, 38, 46,
+27, 29, 34, 34, 35, 40, 46, 56,
+29, 34, 34, 37, 40, 48, 56, 69,
+34, 37, 38, 40, 48, 58, 69, 83,
+};
+
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+VMIXContext *s = avctx->priv_data;
+
+

[FFmpeg-devel] [PATCH 3/3] avcodec/mpegvideo_dec: Add NULL pointer checks to MPV_motion_lowres()

2023-06-08 Thread Michael Niedermayer
This makes the null pointer checks match mpv_motion_internal()

Fixes: NULL pointer dereference
Fixes: 
59671/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG1VIDEO_fuzzer-4993004566609920
Fixes: 
59678/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEGVIDEO_fuzzer-4893168991338496

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/mpegvideo_dec.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index c87ca77ae6..fcca147cd6 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -885,10 +885,9 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
s->mv[dir][1][0], s->mv[dir][1][1],
block_s, mb_y);
 } else {
-if (s->picture_structure != s->field_select[dir][0] + 1 &&
-s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
+if (   s->picture_structure != s->field_select[dir][0] + 1 && 
s->pict_type != AV_PICTURE_TYPE_B && !s->first_field
+|| !ref_picture[0]) {
 ref_picture = s->current_picture_ptr->f->data;
-
 }
 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
0, 0, s->field_select[dir][0],
@@ -901,8 +900,9 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
 for (int i = 0; i < 2; i++) {
 uint8_t *const *ref2picture;
 
-if (s->picture_structure == s->field_select[dir][i] + 1 ||
-s->pict_type == AV_PICTURE_TYPE_B || s->first_field) {
+if ((s->picture_structure == s->field_select[dir][i] + 1 ||
+ s->pict_type == AV_PICTURE_TYPE_B || s->first_field) &&
+ref_picture[0]) {
 ref2picture = ref_picture;
 } else {
 ref2picture = s->current_picture_ptr->f->data;
@@ -933,6 +933,9 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
 pix_op = s->h264chroma.avg_h264_chroma_pixels_tab;
 }
 } else {
+if (!ref_picture[0]) {
+ref_picture = s->current_picture_ptr->f->data;
+}
 for (int i = 0; i < 2; i++) {
 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
0, 0, s->picture_structure != i + 1,
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/3] avcodec/mpegvideo_dec: consider interlaced lowres 4:2:0 chroma in edge emulation check better

2023-06-08 Thread Michael Niedermayer
Fixes: out of array read
Fixes: 
59673/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG1VIDEO_fuzzer-5194311374077952

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/mpegvideo_dec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 765ccd0ba4..c87ca77ae6 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -640,6 +640,7 @@ static av_always_inline void 
mpeg_motion_lowres(MpegEncContext *s,
 const int s_mask = (2 << lowres) - 1;
 const int h_edge_pos = s->h_edge_pos >> lowres;
 const int v_edge_pos = s->v_edge_pos >> lowres;
+int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;
 linesize   = s->current_picture.f->linesize[0] << field_based;
 uvlinesize = s->current_picture.f->linesize[1] << field_based;
 
@@ -702,7 +703,7 @@ static av_always_inline void 
mpeg_motion_lowres(MpegEncContext *s,
 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
 
 if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s,   0) 
|| uvsrc_y<0 ||
-(unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) 
{
+(unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - 
FFMAX(h, hcvdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y,
  linesize >> field_based, linesize >> 
field_based,
  17, 17 + field_based,
@@ -747,7 +748,6 @@ static av_always_inline void 
mpeg_motion_lowres(MpegEncContext *s,
 pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy);
 
 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
-int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;
 uvsx = (uvsx << 2) >> lowres;
 uvsy = (uvsy << 2) >> lowres;
 if (hc) {
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/3] avcodec/rka: use unsigned for buf0 additions

2023-06-08 Thread Michael Niedermayer
Fixes: signed integer overflow: -38912000 + -2109276160 cannot be represented 
in type 'int'
Fixes: 
59670/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RKA_fuzzer-4987563245699072

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/rka.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/rka.c b/libavcodec/rka.c
index 76dca52602..d56f4faee4 100644
--- a/libavcodec/rka.c
+++ b/libavcodec/rka.c
@@ -735,10 +735,10 @@ static int decode_filter(RKAContext *s, ChContext *ctx, 
ACoder *ac, int off, uns
 ctx->buf1[off] = (val + (sum >> bits)) * (1U << bits) +
 (((1U << bits) - 1U) & ctx->buf1[off + -1]);
 }
-ctx->buf0[off] = ctx->buf1[off] + ctx->buf0[off + -1];
+ctx->buf0[off] = ctx->buf1[off] + (unsigned)ctx->buf0[off + 
-1];
 } else {
 val *= 1U << ctx->cmode;
-sum += ctx->buf0[off + -1] + val;
+sum += ctx->buf0[off + -1] + (unsigned)val;
 switch (s->bps) {
 case 16: sum = av_clip_int16(sum); break;
 case  8: sum = av_clip_int8(sum);  break;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 5/5] avformat/jpegxl_anim_dec: avoid overrun with jxlp boxes in container

2023-06-08 Thread Leo Izen
This should avoid overrunning buffers with jxlp boxes if the size is
zero or if the size is so small the box is invalid.

Signed-off-by: Leo Izen 
---
 libavformat/jpegxl_anim_dec.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c
index 6ea6c46d8f..c9e4dcd5fc 100644
--- a/libavformat/jpegxl_anim_dec.c
+++ b/libavformat/jpegxl_anim_dec.c
@@ -76,8 +76,14 @@ static int jpegxl_collect_codestream_header(const uint8_t 
*input_buffer, int inp
 tag = AV_RL32(b);
 b += 4;
 if (tag == MKTAG('j', 'x', 'l', 'p')) {
+if (b - input_buffer >= input_len - 4)
+break;
 b += 4;
-size -= 4;
+if (size) {
+if (size < 4)
+return AVERROR_INVALIDDATA;
+size -= 4;
+}
 }
 
 if (tag == MKTAG('j', 'x', 'l', 'c') || tag == MKTAG('j', 'x', 'l', 
'p')) {
-- 
2.40.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/5] avformat/jpegxl_probe: inline various ret < 0 checks

2023-06-08 Thread Leo Izen
Inlines some ret < 0 checks to look like:
if ((ret = func()) < 0)
return ret;

which clarifies code slightly.

Signed-off-by: Leo Izen 
---
 libavformat/jpegxl_probe.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c
index 88492cb772..b4ab45518a 100644
--- a/libavformat/jpegxl_probe.c
+++ b/libavformat/jpegxl_probe.c
@@ -254,8 +254,7 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 uint64_t extensions;
 int ret;
 
-ret = init_get_bits8(gb, buf, buflen);
-if (ret < 0)
+if ((ret = init_get_bits8(gb, buf, buflen)) < 0)
 return ret;
 
 if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
@@ -281,8 +280,7 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 
 /* preview header */
 if (get_bits1(gb)) {
-ret = jpegxl_read_preview_header(gb);
-if (ret < 0)
+if ((ret = jpegxl_read_preview_header(gb)) < 0)
 return ret;
 }
 
@@ -309,8 +307,7 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 if (num_extra_channels > 4 && validate_level)
 return -1;
 for (uint32_t i = 0; i < num_extra_channels; i++) {
-ret = jpegxl_read_extra_channel_info(gb, validate_level);
-if (ret < 0)
+if ((ret = jpegxl_read_extra_channel_info(gb, validate_level)) < 0)
 return ret;
 if (get_bits_left(gb) < 1)
 return AVERROR_INVALIDDATA;
-- 
2.40.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/5] avformat/jpegxl_probe: Forward error codes

2023-06-08 Thread Leo Izen
From: Michael Niedermayer 

Signed-off-by: Michael Niedermayer 
---
 libavformat/jpegxl_probe.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c
index e15e9eee49..88492cb772 100644
--- a/libavformat/jpegxl_probe.c
+++ b/libavformat/jpegxl_probe.c
@@ -261,8 +261,8 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
 return -1;
 
-if (jpegxl_read_size_header(gb) < 0 && validate_level)
-return -1;
+if ((ret = jpegxl_read_size_header(gb)) < 0 && validate_level)
+return ret;
 
 all_default = get_bits1(gb);
 if (!all_default)
@@ -281,8 +281,9 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 
 /* preview header */
 if (get_bits1(gb)) {
-if (jpegxl_read_preview_header(gb) < 0)
-return -1;
+ret = jpegxl_read_preview_header(gb);
+if (ret < 0)
+return ret;
 }
 
 /* animation header */
@@ -308,8 +309,9 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 if (num_extra_channels > 4 && validate_level)
 return -1;
 for (uint32_t i = 0; i < num_extra_channels; i++) {
-if (jpegxl_read_extra_channel_info(gb, validate_level) < 0)
-return -1;
+ret = jpegxl_read_extra_channel_info(gb, validate_level);
+if (ret < 0)
+return ret;
 if (get_bits_left(gb) < 1)
 return AVERROR_INVALIDDATA;
 }
-- 
2.40.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/5] avformat/jpegxl_probe: check length instead of blindly reading

2023-06-08 Thread Leo Izen
From: Michael Niedermayer 

Enable the checked bitreader to avoid overread.
Also add a few checks in loops and between blocks so we exit instead of 
continued
execution.
Alternatively we could add manual checks so that no overread can happen. This 
would be
slightly faster but a bit more work and a bit more fragile

Fixes: Out of array accesses
Fixes: 
59640/clusterfuzz-testcase-minimized-ffmpeg_dem_JPEGXL_ANIM_fuzzer-6584117345779712

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/jpegxl_probe.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c
index 1d9c014f19..e15e9eee49 100644
--- a/libavformat/jpegxl_probe.c
+++ b/libavformat/jpegxl_probe.c
@@ -21,6 +21,7 @@
 
 #include "jpegxl_probe.h"
 
+#define UNCHECKED_BITSTREAM_READER 0
 #define BITSTREAM_READER_LE
 #include "libavcodec/get_bits.h"
 
@@ -293,6 +294,8 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 skip_bits_long(gb, 1);
 }
 }
+if (get_bits_left(gb) < 1)
+return AVERROR_INVALIDDATA;
 
 if (!all_default) {
 jpegxl_skip_bit_depth(gb);
@@ -307,6 +310,8 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 for (uint32_t i = 0; i < num_extra_channels; i++) {
 if (jpegxl_read_extra_channel_info(gb, validate_level) < 0)
 return -1;
+if (get_bits_left(gb) < 1)
+return AVERROR_INVALIDDATA;
 }
 
 xyb_encoded = get_bits1(gb);
@@ -336,8 +341,11 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, 
int buflen, int valid
 return -1;
 if (primaries == FF_JPEGXL_PR_CUSTOM) {
 /* ux/uy values for r,g,b */
-for (int i = 0; i < 6; i++)
+for (int i = 0; i < 6; i++) {
 jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 
19, 20, 21);
+if (get_bits_left(gb) < 1)
+return AVERROR_INVALIDDATA;
+}
 }
 }
 }
@@ -363,10 +371,14 @@ int ff_jpegxl_verify_codestream_header(const uint8_t 
*buf, int buflen, int valid
 skip_bits_long(gb, 16 + 16 + 1 + 16);
 
 extensions = jpegxl_u64(gb);
+if (get_bits_left(gb) < 1)
+return AVERROR_INVALIDDATA;
 if (extensions) {
 for (int i = 0; i < 64; i++) {
 if (extensions & (UINT64_C(1) << i))
 jpegxl_u64(gb);
+if (get_bits_left(gb) < 1)
+return AVERROR_INVALIDDATA;
 }
 }
 }
-- 
2.40.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/5] avformat/jpegxl_probe: Remove intermediate macro obfuscation around get_bits*()

2023-06-08 Thread Leo Izen
From: Michael Niedermayer 

Signed-off-by: Michael Niedermayer 
---
 libavformat/jpegxl_probe.c | 169 +++--
 1 file changed, 85 insertions(+), 84 deletions(-)

diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c
index a3845b037d..1d9c014f19 100644
--- a/libavformat/jpegxl_probe.c
+++ b/libavformat/jpegxl_probe.c
@@ -57,49 +57,50 @@ enum JpegXLPrimaries {
 FF_JPEGXL_PR_P3 = 11,
 };
 
-#define jxl_bits(n) get_bits_long(gb, (n))
-#define jxl_bits_skip(n) skip_bits_long(gb, (n))
-#define jxl_u32(c0, c1, c2, c3, u0, u1, u2, u3) jpegxl_u32(gb, \
-(const uint32_t[]){c0, c1, c2, c3}, (const uint32_t[]){u0, u1, u2, u3})
-#define jxl_u64() jpegxl_u64(gb)
-#define jxl_enum() jxl_u32(0, 1, 2, 18, 0, 0, 4, 6)
-
 /* read a U32(c_i + u(u_i)) */
-static uint32_t jpegxl_u32(GetBitContext *gb,
-   const uint32_t constants[4], const uint32_t 
ubits[4])
+static av_always_inline uint32_t jxl_u32(GetBitContext *gb,
+uint32_t c0, uint32_t c1, uint32_t c2, uint32_t c3,
+uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3)
 {
-uint32_t ret, choice = jxl_bits(2);
+const uint32_t constants[4] = {c0, c1, c2, c3};
+const uint32_t ubits[4] = {u0, u1, u2, u3};
+uint32_t ret, choice = get_bits(gb, 2);
 
 ret = constants[choice];
 if (ubits[choice])
-ret += jxl_bits(ubits[choice]);
+ret += get_bits_long(gb, ubits[choice]);
 
 return ret;
 }
 
+static av_always_inline uint32_t jxl_enum(GetBitContext *gb)
+{
+return jxl_u32(gb, 0, 1, 2, 18, 0, 0, 4, 6);
+}
+
 /* read a U64() */
 static uint64_t jpegxl_u64(GetBitContext *gb)
 {
 uint64_t shift = 12, ret;
 
-switch (jxl_bits(2)) {
+switch (get_bits(gb, 2)) {
 case 0:
 ret = 0;
 break;
 case 1:
-ret = 1 + jxl_bits(4);
+ret = 1 + get_bits(gb, 4);
 break;
 case 2:
-ret = 17 + jxl_bits(8);
+ret = 17 + get_bits(gb, 8);
 break;
 case 3:
-ret = jxl_bits(12);
-while (jxl_bits(1)) {
+ret = get_bits(gb, 12);
+while (get_bits1(gb)) {
 if (shift < 60) {
-ret |= (uint64_t)jxl_bits(8) << shift;
+ret |= (uint64_t)get_bits(gb, 8) << shift;
 shift += 8;
 } else {
-ret |= (uint64_t)jxl_bits(4) << shift;
+ret |= (uint64_t)get_bits(gb, 4) << shift;
 break;
 }
 }
@@ -142,18 +143,18 @@ static int jpegxl_read_size_header(GetBitContext *gb)
 {
 uint32_t width, height;
 
-if (jxl_bits(1)) {
+if (get_bits1(gb)) {
 /* small size header */
-height = (jxl_bits(5) + 1) << 3;
-width = jpegxl_width_from_ratio(height, jxl_bits(3));
+height = (get_bits(gb, 5) + 1) << 3;
+width = jpegxl_width_from_ratio(height, get_bits(gb, 3));
 if (!width)
-width = (jxl_bits(5) + 1) << 3;
+width = (get_bits(gb, 5) + 1) << 3;
 } else {
 /* large size header */
-height = 1 + jxl_u32(0, 0, 0, 0, 9, 13, 18, 30);
-width = jpegxl_width_from_ratio(height, jxl_bits(3));
+height = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30);
+width = jpegxl_width_from_ratio(height, get_bits(gb, 3));
 if (!width)
-width = 1 + jxl_u32(0, 0, 0, 0, 9, 13, 18, 30);
+width = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30);
 }
 if (width > (1 << 18) || height > (1 << 18)
 || (width >> 4) * (height >> 4) > (1 << 20))
@@ -170,18 +171,18 @@ static int jpegxl_read_preview_header(GetBitContext *gb)
 {
 uint32_t width, height;
 
-if (jxl_bits(1)) {
+if (get_bits1(gb)) {
 /* coded height and width divided by eight */
-height = jxl_u32(16, 32, 1, 33, 0, 0, 5, 9) << 3;
-width = jpegxl_width_from_ratio(height, jxl_bits(3));
+height = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3;
+width = jpegxl_width_from_ratio(height, get_bits(gb, 3));
 if (!width)
-width = jxl_u32(16, 32, 1, 33, 0, 0, 5, 9) << 3;
+width = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3;
 } else {
 /* full height and width coded */
-height = jxl_u32(1, 65, 321, 1345, 6, 8, 10, 12);
-width = jpegxl_width_from_ratio(height, jxl_bits(3));
+height = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12);
+width = jpegxl_width_from_ratio(height, get_bits(gb, 3));
 if (!width)
-width = jxl_u32(1, 65, 321, 1345, 6, 8, 10, 12);
+width = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12);
 }
 if (width > 4096 || height > 4096)
 return -1;
@@ -194,13 +195,13 @@ static int jpegxl_read_preview_header(GetBitContext *gb)
  */
 static void jpegxl_skip_bit_depth(GetBitContext *gb)
 {
-if (jxl_bits(1)) {
+if (get_bits1(gb)) {
 /* float samples */
-

[FFmpeg-devel] [PATCH 0/5] JPEG XL Animation Changes

2023-06-08 Thread Leo Izen
Three patches from michalni copied exactly as is from the ML just placed
here for clarity.

The two authored by me, the probe change is cosmetic, and the animation
dec change fixes the issue referenced a cvslog email: 
<20230608002033.GF870501@pb2>

Leo Izen (2):
  avformat/jpegxl_probe: inline various ret < 0 checks
  avformat/jpegxl_anim_dec: avoid overrun with jxlp boxes in container

Michael Niedermayer (3):
  avformat/jpegxl_probe: Remove intermediate macro obfuscation around
get_bits*()
  avformat/jpegxl_probe: check length instead of blindly reading
  avformat/jpegxl_probe: Forward error codes

 libavformat/jpegxl_anim_dec.c |   8 +-
 libavformat/jpegxl_probe.c| 198 ++
 2 files changed, 112 insertions(+), 94 deletions(-)

-- 
2.40.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 4/4] avcodec/webp: make init_canvas_frame static

2023-06-08 Thread Thilo Borgmann
---
 libavcodec/webp.c | 143 +++---
 1 file changed, 71 insertions(+), 72 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index bee43fcf19..d3e3f85dd3 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1337,7 +1337,77 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, 
AVFrame *p,
 }
 return ret;
 }
-int init_canvas_frame(WebPContext *s, int format, int key_frame);
+
+static int init_canvas_frame(WebPContext *s, int format, int key_frame)
+{
+AVFrame *canvas = s->canvas_frame.f;
+int height;
+int ret;
+
+// canvas is needed only for animation
+if (!(s->vp8x_flags & VP8X_FLAG_ANIMATION))
+return 0;
+
+// avoid init for non-key frames whose format and size did not change
+if (!key_frame &&
+canvas->data[0] &&
+canvas->format == format &&
+canvas->width  == s->canvas_width &&
+canvas->height == s->canvas_height)
+return 0;
+
+// canvas changes within IPPP sequences will loose thread sync
+// because of the ThreadFrame reallocation and will wait forever
+// so if frame-threading is used, forbid canvas changes and unlock
+// previous frames
+if (!key_frame && canvas->data[0]) {
+if (s->avctx->thread_count > 1) {
+av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The 
output will be damaged. Use -threads 1 to try decoding with best effort.\n");
+// unlock previous frames that have sent an _await() call
+ff_thread_report_progress(>canvas_frame, INT_MAX, 0);
+return AVERROR_PATCHWELCOME;
+} else {
+// warn for damaged frames
+av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The 
output will be damaged.\n");
+}
+}
+
+s->avctx->pix_fmt = format;
+canvas->format= format;
+canvas->width = s->canvas_width;
+canvas->height= s->canvas_height;
+
+// VP8 decoder changed the width and height in AVCodecContext.
+// Change it back to the canvas size.
+ret = ff_set_dimensions(s->avctx, s->canvas_width, s->canvas_height);
+if (ret < 0)
+return ret;
+
+ff_thread_release_ext_buffer(s->avctx, >canvas_frame);
+ret = ff_thread_get_ext_buffer(s->avctx, >canvas_frame, 
AV_GET_BUFFER_FLAG_REF);
+if (ret < 0)
+return ret;
+
+if (canvas->format == AV_PIX_FMT_ARGB) {
+height = canvas->height;
+memset(canvas->data[0], 0, height * canvas->linesize[0]);
+} else /* if (canvas->format == AV_PIX_FMT_YUVA420P) */ {
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(canvas->format);
+for (int comp = 0; comp < desc->nb_components; comp++) {
+int plane = desc->comp[comp].plane;
+
+if (comp == 1 || comp == 2)
+height = AV_CEIL_RSHIFT(canvas->height, desc->log2_chroma_h);
+else
+height = FFALIGN(canvas->height, 1 << desc->log2_chroma_h);
+
+memset(canvas->data[plane], s->transparent_yuva[plane],
+   height * canvas->linesize[plane]);
+}
+}
+
+return 0;
+}
 
 static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int 
size,
int *got_frame, int key_frame)
@@ -1577,77 +1647,6 @@ exif_end:
 return size;
 }
 
-int init_canvas_frame(WebPContext *s, int format, int key_frame)
-{
-AVFrame *canvas = s->canvas_frame.f;
-int height;
-int ret;
-
-// canvas is needed only for animation
-if (!(s->vp8x_flags & VP8X_FLAG_ANIMATION))
-return 0;
-
-// avoid init for non-key frames whose format and size did not change
-if (!key_frame &&
-canvas->data[0] &&
-canvas->format == format &&
-canvas->width  == s->canvas_width &&
-canvas->height == s->canvas_height)
-return 0;
-
-// canvas changes within IPPP sequences will loose thread sync
-// because of the ThreadFrame reallocation and will wait forever
-// so if frame-threading is used, forbid canvas changes and unlock
-// previous frames
-if (!key_frame && canvas->data[0]) {
-if (s->avctx->thread_count > 1) {
-av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The 
output will be damaged. Use -threads 1 to try decoding with best effort.\n");
-// unlock previous frames that have sent an _await() call
-ff_thread_report_progress(>canvas_frame, INT_MAX, 0);
-return AVERROR_PATCHWELCOME;
-} else {
-// warn for damaged frames
-av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The 
output will be damaged.\n");
-}
-}
-
-s->avctx->pix_fmt = format;
-canvas->format= format;
-canvas->width = s->canvas_width;
-canvas->height= s->canvas_height;
-
-// VP8 decoder changed the width and height in AVCodecContext.
-// Change it 

[FFmpeg-devel] [PATCH v1 3/4] libavcodec/webp: add support for animated WebP decoding

2023-06-08 Thread Thilo Borgmann
From: Josef Zlomek 

Fixes: 4907

Adds support for decoding of animated WebP.

The WebP decoder adds the animation related features according to the specs:
https://developers.google.com/speed/webp/docs/riff_container#animation
The frames of the animation may be smaller than the image canvas.
Therefore, the frame is decoded to a temporary frame,
then it is blended into the canvas, the canvas is copied to the output frame,
and finally the frame is disposed from the canvas.

The output to AV_PIX_FMT_YUVA420P/AV_PIX_FMT_YUV420P is still supported.
The background color is specified only as BGRA in the WebP file
so it is converted to YUVA if YUV formats are output.

Signed-off-by: Josef Zlomek 
---
 Changelog   |   1 +
 libavcodec/codec_desc.c |   3 +-
 libavcodec/version.h|   2 +-
 libavcodec/webp.c   | 714 
 4 files changed, 658 insertions(+), 62 deletions(-)

diff --git a/Changelog b/Changelog
index d51e03b8eb..31651b8c29 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@ version :
 - nlmeans_vulkan filter
 - RivaTuner video decoder
 - xfade_vulkan filter
+- animated WebP parser/decoder
 
 version 6.0:
 - Radiance HDR image support
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 41293a78dc..383d7c2394 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1259,8 +1259,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "webp",
 .long_name = NULL_IF_CONFIG_SMALL("WebP"),
-.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
- AV_CODEC_PROP_LOSSLESS,
+.props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS,
 .mime_types= MT("image/webp"),
 },
 {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 2618016a83..d6e0724326 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  17
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 15152ec8fb..bee43fcf19 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -35,12 +35,16 @@
  * Exif metadata
  * ICC profile
  *
+ * @author Josef Zlomek, Pexeso Inc. 
+ * Animation
+ *
  * Unimplemented:
- *   - Animation
  *   - XMP metadata
  */
 
+#include "libavcodec/packet.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/colorspace.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
@@ -178,6 +182,8 @@ typedef struct ImageContext {
 typedef struct WebPContext {
 VP8Context v;   /* VP8 Context used for lossy decoding 
*/
 GetBitContext gb;   /* bitstream reader for main image 
chunk */
+ThreadFrame canvas_frame;   /* ThreadFrame for canvas */
+AVFrame *frame; /* AVFrame for decoded frame */
 AVFrame *alpha_frame;   /* AVFrame for alpha data decompressed 
from VP8L */
 AVPacket *pkt;  /* AVPacket to be passed to the 
underlying VP8 decoder */
 AVCodecContext *avctx;  /* parent AVCodecContext */
@@ -189,9 +195,24 @@ typedef struct WebPContext {
 int alpha_data_size;/* alpha chunk data size */
 int has_exif;   /* set after an EXIF chunk has been 
processed */
 int has_iccp;   /* set after an ICCP chunk has been 
processed */
-int width;  /* image width */
-int height; /* image height */
-int lossless;   /* indicates lossless or lossy */
+int vp8x_flags; /* global flags from VP8X chunk */
+int canvas_width;   /* canvas width */
+int canvas_height;  /* canvas height */
+int anmf_flags; /* frame flags from ANMF chunk */
+int width;  /* frame width */
+int height; /* frame height */
+int pos_x;  /* frame position X */
+int pos_y;  /* frame position Y */
+int prev_anmf_flags;/* previous frame flags from ANMF 
chunk */
+int prev_width; /* previous frame width */
+int prev_height;/* previous frame height */
+int prev_pos_x; /* previous frame position X */
+int prev_pos_y; /* previous frame position Y */
+int await_progress; /* value of progress to wait for */
+uint8_t background_argb[4]; /* background color in ARGB format */
+uint8_t background_yuva[4]; /* background color 

[FFmpeg-devel] [PATCH v1 2/4] avcodec/webp_parser: parse each frame into one packet

2023-06-08 Thread Thilo Borgmann
---
 libavcodec/webp_parser.c | 132 ++-
 1 file changed, 90 insertions(+), 42 deletions(-)

diff --git a/libavcodec/webp_parser.c b/libavcodec/webp_parser.c
index bd5f94dac5..d10d06bd0e 100644
--- a/libavcodec/webp_parser.c
+++ b/libavcodec/webp_parser.c
@@ -25,13 +25,17 @@
 
 #include "libavutil/bswap.h"
 #include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
 
 #include "parser.h"
 
 typedef struct WebPParseContext {
 ParseContext pc;
+int frame;
+int first_frame;
 uint32_t fsize;
-uint32_t remaining_size;
+uint32_t remaining_file_size;
+uint32_t remaining_tag_size;
 } WebPParseContext;
 
 static int webp_parse(AVCodecParserContext *s, AVCodecContext *avctx,
@@ -41,62 +45,106 @@ static int webp_parse(AVCodecParserContext *s, 
AVCodecContext *avctx,
 WebPParseContext *ctx = s->priv_data;
 uint64_t state = ctx->pc.state64;
 int next = END_NOT_FOUND;
-int i = 0;
+int i, len;
 
-*poutbuf  = NULL;
-*poutbuf_size = 0;
-
-restart:
-if (ctx->pc.frame_start_found <= 8) {
-for (; i < buf_size; i++) {
+for (i = 0; i < buf_size;) {
+if (ctx->remaining_tag_size) {
+/* consuming tag */
+len = FFMIN(ctx->remaining_tag_size, buf_size - i);
+i += len;
+ctx->remaining_tag_size -= len;
+ctx->remaining_file_size -= len;
+} else {
+/* scan for the next tag or file */
 state = (state << 8) | buf[i];
-if (ctx->pc.frame_start_found == 0) {
-if ((state >> 32) == MKBETAG('R', 'I', 'F', 'F')) {
-ctx->fsize = av_bswap32(state);
-if (ctx->fsize > 15 && ctx->fsize <= UINT32_MAX - 10) {
-ctx->pc.frame_start_found = 1;
-ctx->fsize += 8;
+i++;
+
+if (!ctx->remaining_file_size) {
+/* scan for the next file */
+if (ctx->pc.frame_start_found == 4) {
+ctx->pc.frame_start_found = 0;
+if ((uint32_t) state == MKBETAG('W', 'E', 'B', 'P')) {
+if (ctx->frame || i != 12) {
+ctx->frame = 0;
+next = i - 12;
+state = 0;
+ctx->pc.frame_start_found = 0;
+break;
+}
+ctx->remaining_file_size = ctx->fsize - 4;
+ctx->first_frame = 1;
+continue;
 }
 }
-} else if (ctx->pc.frame_start_found == 8) {
-if ((state >> 32) != MKBETAG('W', 'E', 'B', 'P')) {
+if (ctx->pc.frame_start_found == 0) {
+if ((state >> 32) == MKBETAG('R', 'I', 'F', 'F')) {
+ctx->fsize = av_bswap32(state);
+if (ctx->fsize > 15 && ctx->fsize <= UINT32_MAX - 10) {
+ctx->fsize += (ctx->fsize & 1);
+ctx->pc.frame_start_found = 1;
+}
+}
+} else
+ctx->pc.frame_start_found++;
+} else {
+/* read the next tag */
+ctx->remaining_file_size--;
+if (ctx->remaining_file_size == 0) {
 ctx->pc.frame_start_found = 0;
 continue;
 }
 ctx->pc.frame_start_found++;
-ctx->remaining_size = ctx->fsize + i - 15;
-if (ctx->pc.index + i > 15) {
-next = i - 15;
-state = 0;
-break;
-} else {
-ctx->pc.state64 = 0;
-goto restart;
+if (ctx->pc.frame_start_found < 8)
+continue;
+
+switch (state >> 32) {
+case MKBETAG('A', 'N', 'M', 'F'):
+case MKBETAG('V', 'P', '8', ' '):
+case MKBETAG('V', 'P', '8', 'L'):
+if (ctx->frame) {
+ctx->frame = 0;
+next = i - 8;
+state = 0;
+ctx->pc.frame_start_found = 0;
+goto flush;
+}
+ctx->frame = 1;
+break;
+default:
+break;
 }
-} else if (ctx->pc.frame_start_found)
-ctx->pc.frame_start_found++;
-}
-ctx->pc.state64 = state;
-} else {
-if (ctx->remaining_size) {
-i = FFMIN(ctx->remaining_size, buf_size);
-ctx->remaining_size -= i;
-if (ctx->remaining_size)
-   

[FFmpeg-devel] [PATCH v1 1/4] avcodec/webp: move definitions into header

2023-06-08 Thread Thilo Borgmann
---
 libavcodec/webp.c | 17 +--
 libavcodec/webp.h | 55 +++
 2 files changed, 56 insertions(+), 16 deletions(-)
 create mode 100644 libavcodec/webp.h

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index d35cb66f8d..15152ec8fb 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -52,22 +52,7 @@
 #include "thread.h"
 #include "tiff_common.h"
 #include "vp8.h"
-
-#define VP8X_FLAG_ANIMATION 0x02
-#define VP8X_FLAG_XMP_METADATA  0x04
-#define VP8X_FLAG_EXIF_METADATA 0x08
-#define VP8X_FLAG_ALPHA 0x10
-#define VP8X_FLAG_ICC   0x20
-
-#define MAX_PALETTE_SIZE256
-#define MAX_CACHE_BITS  11
-#define NUM_CODE_LENGTH_CODES   19
-#define HUFFMAN_CODES_PER_META_CODE 5
-#define NUM_LITERAL_CODES   256
-#define NUM_LENGTH_CODES24
-#define NUM_DISTANCE_CODES  40
-#define NUM_SHORT_DISTANCES 120
-#define MAX_HUFFMAN_CODE_LENGTH 15
+#include "webp.h"
 
 static const uint16_t alphabet_sizes[HUFFMAN_CODES_PER_META_CODE] = {
 NUM_LITERAL_CODES + NUM_LENGTH_CODES,
diff --git a/libavcodec/webp.h b/libavcodec/webp.h
new file mode 100644
index 00..90baa71182
--- /dev/null
+++ b/libavcodec/webp.h
@@ -0,0 +1,55 @@
+/*
+ * WebP image format definitions
+ * Copyright (c) 2020 Pexeso Inc.
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * WebP image format definitions.
+ */
+
+#ifndef AVCODEC_WEBP_H
+#define AVCODEC_WEBP_H
+
+#define VP8X_FLAG_ANIMATION 0x02
+#define VP8X_FLAG_XMP_METADATA  0x04
+#define VP8X_FLAG_EXIF_METADATA 0x08
+#define VP8X_FLAG_ALPHA 0x10
+#define VP8X_FLAG_ICC   0x20
+
+#define ANMF_DISPOSAL_METHOD0x01
+#define ANMF_DISPOSAL_METHOD_UNCHANGED  0x00
+#define ANMF_DISPOSAL_METHOD_BACKGROUND 0x01
+
+#define ANMF_BLENDING_METHOD0x02
+#define ANMF_BLENDING_METHOD_ALPHA  0x00
+#define ANMF_BLENDING_METHOD_OVERWRITE  0x02
+
+#define MAX_PALETTE_SIZE256
+#define MAX_CACHE_BITS  11
+#define NUM_CODE_LENGTH_CODES   19
+#define HUFFMAN_CODES_PER_META_CODE 5
+#define NUM_LITERAL_CODES   256
+#define NUM_LENGTH_CODES24
+#define NUM_DISTANCE_CODES  40
+#define NUM_SHORT_DISTANCES 120
+#define MAX_HUFFMAN_CODE_LENGTH 15
+
+
+#endif /* AVCODEC_WEBP_H */
-- 
2.37.1 (Apple Git-137.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 0/4] webp: add support for animated WebP decoding

2023-06-08 Thread Thilo Borgmann
Follow-up to [1], the decoder only.

In [1] we found a hanging sample. In frame-threading, this led to an
infinite wait, damaged frames otherwise. So warn acordingly and do
best-effort in single-thread mode.

Also split into more patches to make reviewing easier.

[1] http://ffmpeg.org/pipermail/ffmpeg-devel/2023-April/308965.html

Josef Zlomek (1):
  libavcodec/webp: add support for animated WebP decoding

Thilo Borgmann (3):
  avcodec/webp: move definitions into header
  avcodec/webp_parser: parse each frame into one packet
  avcodec/webp: make init_canvas_frame static

 Changelog|   1 +
 libavcodec/codec_desc.c  |   3 +-
 libavcodec/version.h |   2 +-
 libavcodec/webp.c| 724 +++
 libavcodec/webp.h|  55 +++
 libavcodec/webp_parser.c | 132 ---
 6 files changed, 800 insertions(+), 117 deletions(-)
 create mode 100644 libavcodec/webp.h

-- 
2.37.1 (Apple Git-137.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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/2] lavc/riffenc: Fix msrle support on Windows 95

2023-06-08 Thread Tomas Härdin
tor 2023-06-08 klockan 13:27 +0200 skrev Paul B Mahol:
> But does this break it on other platforms?

That is a good question. What other RIFF decoders are there for which
MSRLE support is important and depends on behavior different from VfW?
mpv and vlc work just fine.

/Tomas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/hls: Forward stream metadata from subdemuxer

2023-06-08 Thread Armin Hasitzka
Hi all,

just checking; do you consider this for merge into the upstream? It does
feel like a lot of upside without any downside.

Thanks
Armin

On Tue, 23 May 2023 at 11:26, Armin Hasitzka  wrote:

> We found this when we were looking for language information that the
> mpegts demuxer knew about, but the HLS demuxer didn't (get forwarded).
>
> Best
> Armin
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/2] lavc/riffenc: Fix msrle support on Windows 95

2023-06-08 Thread Paul B Mahol
But does this break it on other platforms?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] lavc/msrleenc: Add msrle encoder

2023-06-08 Thread Tomas Härdin
Please check that I got the palette handling correct. Else this
producing output of similar size to the VfW encoder.

/Tomas
From ab9bb1aca7ddda8f4788b0a63460470fce021e72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Thu, 8 Jun 2023 11:57:53 +0200
Subject: [PATCH 2/2] lavc/msrleenc: Add msrle encoder

Keyframes are marked automagically
---
 MAINTAINERS|   1 +
 doc/encoders.texi  |  14 ++
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/msrleenc.c  | 303 +
 tests/fate/vcodec.mak  |   3 +
 tests/ref/vsynth/vsynth1-msrle |   4 +
 tests/ref/vsynth/vsynth2-msrle |   4 +
 tests/ref/vsynth/vsynth3-msrle |   4 +
 tests/ref/vsynth/vsynth_lena-msrle |   4 +
 10 files changed, 339 insertions(+)
 create mode 100644 libavcodec/msrleenc.c
 create mode 100644 tests/ref/vsynth/vsynth1-msrle
 create mode 100644 tests/ref/vsynth/vsynth2-msrle
 create mode 100644 tests/ref/vsynth/vsynth3-msrle
 create mode 100644 tests/ref/vsynth/vsynth_lena-msrle

diff --git a/MAINTAINERS b/MAINTAINERS
index 07852486e4..3584a68442 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -210,6 +210,7 @@ Codecs:
   mqc*  Nicolas Bertrand
   msmpeg4.c, msmpeg4data.h  Michael Niedermayer
   msrle.c   Mike Melanson
+  msrleenc.cTomas Härdin
   msvideo1.cMike Melanson
   nuv.c Reimar Doeffinger
   nvdec*, nvenc*Timo Rothenpieler
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 20cb8a1421..25d6b7f09e 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3061,6 +3061,20 @@ Video encoders can take input in either of nv12 or yuv420p form
 (some encoders support both, some support only either - in practice,
 nv12 is the safer choice, especially among HW encoders).
 
+@section Microsoft RLE
+
+Microsoft RLE aka MSRLE encoder.
+Only 8-bit palette mode supported.
+Compatible with Windows 3.1 and Windows 95.
+
+@subsection Options
+
+@table @option
+@item g @var{integer}
+Keyframe interval.
+A keyframe is inserted at least every @code{-g} frames, sometimes sooner.
+@end table
+
 @section mpeg2
 
 MPEG-2 video encoder.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 87a8b90037..2c88dd65d5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -552,6 +552,7 @@ OBJS-$(CONFIG_MSA1_DECODER)+= mss3.o
 OBJS-$(CONFIG_MSCC_DECODER)+= mscc.o
 OBJS-$(CONFIG_MSNSIREN_DECODER)+= siren.o
 OBJS-$(CONFIG_MSP2_DECODER)+= msp2dec.o
+OBJS-$(CONFIG_MSRLE_ENCODER)   += msrleenc.o
 OBJS-$(CONFIG_MSRLE_DECODER)   += msrle.o msrledec.o
 OBJS-$(CONFIG_MSS1_DECODER)+= mss1.o mss12.o
 OBJS-$(CONFIG_MSS2_DECODER)+= mss2.o mss12.o mss2dsp.o wmv2data.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a98c300da4..5d4889b968 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -228,6 +228,7 @@ extern const FFCodec ff_msmpeg4v3_encoder;
 extern const FFCodec ff_msmpeg4v3_decoder;
 extern const FFCodec ff_msmpeg4_crystalhd_decoder;
 extern const FFCodec ff_msp2_decoder;
+extern const FFCodec ff_msrle_encoder;
 extern const FFCodec ff_msrle_decoder;
 extern const FFCodec ff_mss1_decoder;
 extern const FFCodec ff_mss2_decoder;
diff --git a/libavcodec/msrleenc.c b/libavcodec/msrleenc.c
new file mode 100644
index 00..17d40cbd6a
--- /dev/null
+++ b/libavcodec/msrleenc.c
@@ -0,0 +1,303 @@
+/*
+ * Copyright (c) 2023 Tomas Härdin
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * MSRLE encoder
+ * @see https://wiki.multimedia.cx/index.php?title=Microsoft_RLE
+ */
+
+// TODO: pal4 mode?
+
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+
+typedef struct MSRLEContext {
+const AVClass *class;
+int curframe;
+AVFrame *last_frame;
+} MSRLEContext;
+
+static av_cold int msrle_encode_init(AVCodecContext *avctx)
+{
+avctx->bits_per_coded_sample = 8;
+return 0;
+}
+
+static void write_run(AVCodecContext *avctx, uint8_t 

[FFmpeg-devel] [PATCH 1/2] lavc/riffenc: Fix msrle support on Windows 95

2023-06-08 Thread Tomas Härdin
This is important for the GoldSrc community among others.

/Tomas
From c5c2d535b3e5dc94b063e13359e475e9ce18e1b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Thu, 8 Jun 2023 11:55:28 +0200
Subject: [PATCH 1/2] lavc/riffenc: Fix msrle support on Windows 95

---
 libavformat/riffenc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index 179b0f12cb..3325419b94 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -239,14 +239,16 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par,
 /* depth */
 avio_wl16(pb, par->bits_per_coded_sample ? par->bits_per_coded_sample : 24);
 /* compression type */
-avio_wl32(pb, par->codec_tag);
+// MSRLE compatibility with Media Player 3.1 and Windows 95
+avio_wl32(pb, par->codec_id == AV_CODEC_ID_MSRLE ? 1 : par->codec_tag);
 avio_wl32(pb, (par->width * par->height * (par->bits_per_coded_sample ? par->bits_per_coded_sample : 24)+7) / 8);
 avio_wl32(pb, 0);
 avio_wl32(pb, 0);
 /* Number of color indices in the color table that are used.
  * A value of 0 means 2^biBitCount indices, but this doesn't work
  * with Windows Media Player and files containing xxpc chunks. */
-avio_wl32(pb, pal_avi ? 1 << par->bits_per_coded_sample : 0);
+// MSRLE on Windows 95 requires a zero here
+avio_wl32(pb, pal_avi && par->codec_id != AV_CODEC_ID_MSRLE ? 1 << par->bits_per_coded_sample : 0);
 avio_wl32(pb, 0);
 
 if (!ignore_extradata) {
-- 
2.30.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v5 5/5] lavfi/format: add a hwmap auto conversion filter

2023-06-08 Thread Wu, Tong1
>On 25 Apr 2023, at 9:26, Tong Wu wrote:
>
>> When two formats lists cannot be merged, a scale filter is
>> auto-inserted. However, when it comes to hardware map, we have to
>> manually add a hwmap filter to do the conversion. This patch introduces
>> an auto hwmap filter to do the hwmap conversion automatically.
>>
>
>Thanks for trying to improve this!
>
>I've recently done quite a bit of experimentation with hardware
>filters and at least for the Cuda - Vulkan - Cuda case, hwmap
>was useless, and I was told I need to use hwupload instead, so I wonder
>what cases this would help with?

Thanks for the reply!

Actually we are using hwmap filter to do vaapi<->qsv, d3d11<->qsv conversions.

For the use case I have replied in another mail. I'll just copy here again.
For example,
ffmpeg -init_hw_device d3d11va=d3d11 -init_hw_device qsv=qsv@d3d11 -
hwaccel d3d11va -hwaccel_output_format d3d11 -i input.mp4 -vf
"hwmap=derive_device=qsv:extra_hw_frames=16,format=qsv" -c:v h264_qsv
output.mp4

Now we don't have to explicitly specify hwmap. The auto filter mechanism will
try to insert a hwmap filter automatically. The command line will be much
simpler.

ffmpeg -init_hw_device d3d11va=d3d11 -init_hw_device qsv=qsv@d3d11 -
hwaccel d3d11va -hwaccel_output_format d3d11 -i input.mp4 -c:v h264_qsv
output.mp4



>
>I just fear that, especially given the bad error messages hwmap gives,
>this will just implicitly insert it because it seemingly works but then
>just fail to actually do the job and give an absolutely indescriptive
>error to the user for a filter they did not even insert themselves.

Yes I agree with that. However, we already have an auto scale filter in the 
framework.
It will always be inserted when two filters cannot be linked.

In my opinion, I'm just kinda appending another filter. It should be no harmful 
to the original framework. The only way you can get to this auto hwmap filter 
is that you already fail to insert scale filter and the program will return 
error. That's the current situation. With this patch set, those failed cmdlines 
could still fail but some cmdlines like above could pass. It just give it 
another chance to run and simplify the cmdlines.

Regards,
Tong


>
>> Signed-off-by: Tong Wu 
>> ---
>>  libavfilter/avfiltergraph.c | 3 ++-
>>  libavfilter/formats.c   | 4 
>>  2 files changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
>> index 8af0467bc5..b2b627ad6a 100644
>> --- a/libavfilter/avfiltergraph.c
>> +++ b/libavfilter/avfiltergraph.c
>> @@ -402,7 +402,8 @@ static int insert_auto_filter(AVFilterContext
>**convert, AVFilterGraph *graph,
>>  AVFilterContext *ctx;
>>  AVFilterLink *inlink, *outlink;
>>  char inst_name[30];
>> -const char *opts = FF_FIELD_AT(char *, neg-
>>conversion_filters[conv_step].conversion_opts_offset, *graph);
>> +const char *opts = neg-
>>conversion_filters[conv_step].conversion_opts_offset == 0 ? NULL :
>> +   FF_FIELD_AT(char *, neg-
>>conversion_filters[conv_step].conversion_opts_offset, *graph);
>>  const char *name = neg->conversion_filters[conv_step].conversion_filter;
>>
>>  if (!(filter = avfilter_get_by_name(name))) {
>> diff --git a/libavfilter/formats.c b/libavfilter/formats.c
>> index c8e20e5b20..fee10fa0ee 100644
>> --- a/libavfilter/formats.c
>> +++ b/libavfilter/formats.c
>> @@ -331,6 +331,10 @@ static const AVFilterFormatsFilter filters_video[] = {
>>  .conversion_filter = "scale",
>>  .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
>>  },
>> +{
>> +.conversion_filter = "hwmap",
>> +.conversion_opts_offset = 0,
>> +}
>>  };
>>
>>  static const AVFilterFormatsFilter filters_audio[] = {
>> --
>> 2.39.1.windows.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-requ...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/qsvdec: respect AVCodecContext->{width, height}

2023-06-08 Thread zhilizhao(赵志立)


> On Jun 8, 2023, at 13:47, Xiang, Haihao 
>  wrote:
> 
> From: Haihao Xiang 
> 
> width and height may be known from the container
> 
> Signed-off-by: Haihao Xiang 
> ---
> libavcodec/qsvdec.c | 6 ++
> 1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index da700f25e9..5325030ea1 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -910,6 +910,7 @@ static int qsv_process_data(AVCodecContext *avctx, 
> QSVContext *q,
> }
> 
> if (q->reinit_flag || !q->session || !q->initialized) {
> +int reset_crop = !q->session;
> mfxFrameAllocRequest request;
> memset(, 0, sizeof(request));
> 
> @@ -929,6 +930,11 @@ static int qsv_process_data(AVCodecContext *avctx, 
> QSVContext *q,
> avctx->coded_width  = param.mfx.FrameInfo.Width;
> avctx->coded_height = param.mfx.FrameInfo.Height;
> 
> +if (reset_crop && avctx->width && avctx->height) {
> +param.mfx.FrameInfo.CropW = avctx->width;
> +param.mfx.FrameInfo.CropH = avctx->height;
> +}
> +

I can see two issues here:

1. Reset CropW/CropH from container without reset CropX/CropY might create some
mismatch.

2. Width/Height from container can be larger than coded_width/coded_height. For
example, mp4 container can apply a scaling after decoding. So decoder should 
only
care about ES, while user can apply the info from container after decoding, 
like 
rotation, scaling and cropping. But it’s complex in practice.

I don’t have idea for these issues.

> ret = MFXVideoDECODE_QueryIOSurf(q->session, , );
> if (ret < 0)
> return ff_qsv_print_error(avctx, ret, "Error querying IO 
> surface");
> -- 
> 2.34.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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] vulkan build fix

2023-06-08 Thread Wang Bin
2023-06-08T02:04:18.3926210Z CC libavcodec/vulkan_decode.o
2023-06-08T02:04:18.5384903Z src/libavcodec/vulkan_decode.c:148:26:
error: incompatible pointer to integer conversion assigning to
'VkImageView' (aka 'unsigned long long') from 'void *'
[-Wint-conversion]
2023-06-08T02:04:18.5388615Z vkpic->img_view_ref  = NULL;
2023-06-08T02:04:18.5391395Z  ^ 


0001-vulkan-fix-msvc-arm32-build.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".