Re: [FFmpeg-devel] Ffmpeg/ffprobe not work well with a DASH stream

2022-11-18 Thread Steven Liu
Chang, Xiangzhong  于2022年11月17日周四 22:00写道:
>
> Hi,
>
> Thank you so much for this amazing project. I’ve found this project has been 
> extremely useful for me.
> I’ve found out that ffmpeg/ffplay does not work well with one of our DASH 
> streams. In comparison, I’ve tried the following players
>
>   1.  ExoPlayer
>   2.  DASH-JS 
> player
>   3.  Bitmovin JS 
> player
>
> I was using the following script trying to probe/transcoding one of our DASH 
> stream.
> ```
> ffprobe_g  -loglevel debug 
> "https://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/manifest.mpd?abs_begin=2022-11-16T08:00:00Z&is_live&no_dolby";

(base) liuqi05:ffmpeg liuqi$
~/multimedia/upstream_ffmpeg/ufbuild/ffprobe
"https://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/manifest.mpd?abs_begin=2022-11-16T08:00:00Z&is_live&no_dolby";
ffprobe(70115,0x113793600) malloc: nano zone abandoned due to
inability to preallocate reserved vm space.
ffprobe version N-109033-g86157f5a25 Copyright (c) 2007-2022 the
FFmpeg developers
  built with Apple clang version 13.1.6 (clang-1316.0.21.2.5)
  configuration: --prefix=/usr/local/ --libdir=/usr/local/lib/
--cc=clang --enable-htmlpages --enable-libx264 --enable-gpl
--extra-ldflags='-I/usr/local/opt/openssl/include/ -O0 -g3
-fsanitize=address -Wno-error -fPIC -I/usr/local/include'
--extra-ldflags='-O0 -g3 -fsanitize=address -Wno-error -fPIC
-L/usr/local/lib -L/usr/local/opt/openssl/lib' --enable-libfreetype
--enable-fontconfig --enable-libspeex --enable-libopus --enable-libzmq
--enable-libx265 --enable-libass --enable-videotoolbox
--disable-optimizations --enable-audiotoolbox --enable-opengl
--disable-stripping --samples=../../fate-suite/
--enable-encoder=hevc_videotoolbox --enable-hwaccel=hevc_videotoolbox
--enable-hwaccel=h264_videotoolbox --enable-openssl --enable-nonfree
--disable-shared --enable-libfdk_aac --enable-libxml2
--enable-libmp3lame --enable-libaom
  libavutil  57. 42.100 / 57. 42.100
  libavcodec 59. 52.100 / 59. 52.100
  libavformat59. 34.101 / 59. 34.101
  libavdevice59.  8.101 / 59.  8.101
  libavfilter 8. 50.100 /  8. 50.100
  libswscale  6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc56.  7.100 / 56.  7.100
[dash @ 0x61700080] DTS discontinuity in stream 0: packet 99 with
DTS 150189356926262, packet 100 with DTS 150189360168062
Input #0, dash, from
'https://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/manifest.mpd?abs_begin=2022-11-16T08:00:00Z&is_live&no_dolby':
  Duration: N/A, start: 1668770630.554022, bitrate: N/A
  Program 0
  Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn (default)
Metadata:
  variant_bitrate : 500
  id  : video-stream-1
  Stream #0:1: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn (default)
Metadata:
  variant_bitrate : 300
  id  : video-stream-2
  Stream #0:2: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1024x576 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn (default)
Metadata:
  variant_bitrate : 175
  id  : video-stream-3
  Stream #0:3: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv,
bt709), 640x360 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn (default)
Metadata:
  variant_bitrate : 100
  id  : video-stream-4
  Stream #0:4: Video: h264 (Constrained Baseline) (avc1 / 0x31637661),
yuv420p(tv, bt709), 448x252 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k
tbn (default)
Metadata:
  variant_bitrate : 30
  id  : video-stream-5
  Stream #0:5(nor): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp (default)
Metadata:
  variant_bitrate : 192000
  id  : audio-stream-1
(base) liuqi05:ffmpeg liuqi$


> ```
>
> The following log have drawn my attention. It seems like ffprobe has failed 
> to download some file chunks.
> ```
> [dash @ 0x55b477e86880] DASH request for url 
> 'https://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/video-stream-1-150182387590546.mp4',
>  offset 0
> [tcp @ 0x55b477f09080] Starting connection attempt to 84.208.9.142 port 443
> [tcp @ 0x55b477f09080] Successfully connected to 84.208.9.142 port 443
> [tcp @ 0x55b477ed0f00] Starting connection attempt to 84.208.9.21 port 443
> [tcp @ 0x55b477ed0f00] Successfully connected to 84.208.9.21 port 443
> [https @ 0x55b477eee1c0] HTTP error 404 Not Found
> ```
>
> However, when I was using wget to download it, all works out
> ```
> hhk9417@HC994R6KQD:~/Desktop$ wget 
> https://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/video-stream-1-15018238759054

Re: [FFmpeg-devel] Ffmpeg/ffprobe not work well with a DASH stream

2022-11-18 Thread Chang, Xiangzhong
Thank you, Steve, I’ve synced my code base to your commit#. I tried to 
configure the code as much like yours as possible. But mine is a Linux box on 
HP laptop. For me, the result remains the same �C ffprobe_g was unable to 
detect the stream type.


chang@640g2:~/git-root/FFmpeg$ ./ffprobe_g --version

ffprobe version N-109033-g86157f5a25 Copyright (c) 2007-2022 the FFmpeg 
developers

  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

  configuration: --disable-optimizations --disable-shared --disable-stripping 
--enable-debug --enable-debug=3 --enable-demuxer=dash --enable-ffplay 
--enable-filter=delogo --enable-fontconfig --enable-gpl --enable-htmlpages 
--enable-libaom --enable-libfdk-aac --enable-libfreetype --enable-libopus 
--enable-libspeex --enable-libv4l2 --enable-libv4l2 --enable-libx264 
--enable-libx265 --enable-libx265 --enable-libxml2 --enable-libzmq 
--enable-nonfree --enable-openssl --enable-pthreads --enable-pthreads 
--enable-shared --enable-vaapi --enable-vaapi --enable-vdpau --enable-xlib 
--enable-zlib

  libavutil  57. 42.100 / 57. 42.100

  libavcodec 59. 52.100 / 59. 52.100

  libavformat59. 34.101 / 59. 34.101

  libavdevice59.  8.101 / 59.  8.101

  libavfilter 8. 50.100 /  8. 50.100

  libswscale  6.  8.112 /  6.  8.112

  libswresample   4.  9.100 /  4.  9.100

  libpostproc56.  7.100 / 56.  7.100



You have to specify one input file.

Use -h to get full help or, even better, run 'man ffprobe'.

[1]+  Terminated  ./ffprobe_g -loglevel trace 
http://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/manifest.mpd?abs_begin=2022-11-16T08:00:00Z

chang@640g2:~/git-root/FFmpeg$ ./ffprobe_g -loglevel trace 
http://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/manifest.mpd?abs_begin=2022-11-16T08:00:00Z&is_live&no_dolby

…

[http @ 0x55a993990f00] HTTP error 404 Not Found

[dash @ 0x55a9939677c0] Failed to open fragment of playlist







The following indicates ffprobe_g is linking to the correct runtime library



chang@640g2:~/git-root/FFmpeg$ ldd ./ffprobe_g

linux-vdso.so.1 (0x7ffc75b94000)

libavdevice.so.59 => ./libavdevice/libavdevice.so.59 (0x7fa234b6)

libavfilter.so.8 => ./libavfilter/libavfilter.so.8 (0x7fa234528000)

libavformat.so.59 => ./libavformat/libavformat.so.59 (0x7fa2341e5000)

libavcodec.so.59 => ./libavcodec/libavcodec.so.59 (0x7fa232a88000)

libpostproc.so.56 => ./libpostproc/libpostproc.so.56 (0x7fa232a67000)

libswresample.so.4 => ./libswresample/libswresample.so.4 
(0x7fa232a3f000)

libswscale.so.6 => ./libswscale/libswscale.so.6 (0x7fa232894000)

libavutil.so.57 => ./libavutil/libavutil.so.57 (0x7fa23267f000)






From: ffmpeg-devel  on behalf of Steven Liu 

Date: Friday, 18 November 2022 at 12:27
To: FFmpeg development discussions and patches 
Subject: Re: [FFmpeg-devel] Ffmpeg/ffprobe not work well with a DASH stream
Chang, Xiangzhong  于2022年11月17日周四 22:00写道:
>
> Hi,
>
> Thank you so much for this amazing project. I’ve found this project has been 
> extremely useful for me.
> I’ve found out that ffmpeg/ffplay does not work well with one of our DASH 
> streams. In comparison, I’ve tried the following players
>
>   1.  ExoPlayer
>   2.  DASH-JS 
> player
>   3.  Bitmovin JS 
> player
>
> I was using the following script trying to probe/transcoding one of our DASH 
> stream.
> ```
> ffprobe_g  -loglevel debug 
> "https://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/manifest.mpd?abs_begin=2022-11-16T08:00:00Z&is_live&no_dolby";

(base) liuqi05:ffmpeg liuqi$
~/multimedia/upstream_ffmpeg/ufbuild/ffprobe
"https://director.livecdn.teliaplay.net/notvm/mso/TV_1HD/dash/manifest.mpd?abs_begin=2022-11-16T08:00:00Z&is_live&no_dolby";
ffprobe(70115,0x113793600) malloc: nano zone abandoned due to
inability to preallocate reserved vm space.
ffprobe version N-109033-g86157f5a25 Copyright (c) 2007-2022 the
FFmpeg developers
  built with Apple clang version 13.1.6 (clang-1316.0.21.2.5)
  configuration: --prefix=/usr/local/ --libdir=/usr/local/lib/
--cc=clang --enable-htmlpages --enable-libx264 --enable-gpl
--extra-ldflags='-I/usr/local/opt/openssl/include/ -O0 -g3
-fsanitize=address -Wno-error -fPIC -I/usr/local/include'
--extra-ldflags='-O0 -g3 -fsanitize=address -Wno-error -fPIC
-L/usr/local/lib -L/usr/local/opt/openssl/lib' --enable-libfreetype
--enable-fontconfig --enable-libspeex --enable-libopus --enable-libzmq
--enable-libx265 --enable-libass --enable-videotoolbox
--disable-optimizations --enable-audiotoolbox --enable-opengl
--disable-stripping --samples=../../fate-suite/
--enable-encoder=hevc_videotoolbox --enable-hwaccel=hevc_videotoolbox
--enable-hwaccel=h264_videotoolbox --enable-openssl --e

[FFmpeg-devel] [PATCH] avcodec/vp8: Fix wrong vpx_rac_is_end() check

2022-11-18 Thread Ronald S. Bultje
From: Hirokazu Honda 

The check of vpx_rac_is_end check(s) are added originally from
1afd246960202917e244c844c534e9c1e3c323f5. It causes a regression
of some vp8 stream. b6b9ac5698c8f911841b469af77199153278c55c fixes
the regression by a sort of band-aid way. This fixes the wrongness
of the original commit. vpx_rac_is_end() should be called against
the bool decoder for the vp8 headr context, not one for each
coefficient. Reference is vp8_dixie_tokens_process_row() in token.c
in spec 20.16.

Fixes: Ticket 8069
Fixes: regression of 1afd246960202917e244c844c534e9c1e3c323f5.
Fixes: b6b9ac5698c8f911841b469af77199153278c55c

Signed-off-by: Hirokazu Honda 
Signed-off-by: Ronald S. Bultje 
---
 libavcodec/vp8.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 67f36d8933..db2419deaf 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -2404,7 +2404,8 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 int num_jobs = s->num_jobs;
 const VP8Frame *prev_frame = s->prev_frame;
 VP8Frame *curframe = s->curframe;
-VPXRangeCoder *c  = &s->coeff_partition[mb_y & (s->num_coeff_partitions - 
1)];
+VPXRangeCoder *coeff_c  = &s->coeff_partition[mb_y & 
(s->num_coeff_partitions - 1)];
+
 VP8Macroblock *mb;
 uint8_t *dst[3] = {
 curframe->tf.f->data[0] + 16 * mb_y * s->linesize,
@@ -2412,7 +2413,7 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 curframe->tf.f->data[2] +  8 * mb_y * s->uvlinesize
 };
 
-if (vpx_rac_is_end(c))
+if (vpx_rac_is_end(&s->c))
  return AVERROR_INVALIDDATA;
 
 if (mb_y == 0)
@@ -2443,7 +2444,7 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 td->mv_bounds.mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
 
 for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
-if (vpx_rac_is_end(c))
+if (vpx_rac_is_end(&s->c))
 return AVERROR_INVALIDDATA;
 // Wait for previous thread to read mb_x+2, and reach mb_y-1.
 if (prev_td != td) {
@@ -2470,8 +2471,11 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 
 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS);
 
-if (!mb->skip)
-decode_mb_coeffs(s, td, c, mb, s->top_nnz[mb_x], td->left_nnz, 
is_vp7);
+if (!mb->skip) {
+if (vpx_rac_is_end(coeff_c))
+return AVERROR_INVALIDDATA;
+decode_mb_coeffs(s, td, coeff_c, mb, s->top_nnz[mb_x], 
td->left_nnz, is_vp7);
+}
 
 if (mb->mode <= MODE_I4x4)
 intra_predict(s, td, dst, mb, mb_x, mb_y, is_vp7);
-- 
2.38.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/vp8: Fix wrong vpx_rac_is_end() check

2022-11-18 Thread Ronald S. Bultje
From: Hirokazu Honda 

The check of vpx_rac_is_end check(s) are added originally from
1afd246960202917e244c844c534e9c1e3c323f5. It causes a regression
of some vp8 stream. b6b9ac5698c8f911841b469af77199153278c55c fixes
the regression by a sort of band-aid way. This fixes the wrongness
of the original commit. vpx_rac_is_end() should be called against
the bool decoder for the vp8 headr context, not one for each
coefficient. Reference is vp8_dixie_tokens_process_row() in token.c
in spec 20.16.

Fixes: Ticket 8069
Fixes: regression of 1afd246960202917e244c844c534e9c1e3c323f5.
Fixes: b6b9ac5698c8f911841b469af77199153278c55c

Co-authored-by: Ronald S. Bultje 
Signed-off-by: Hirokazu Honda 
Signed-off-by: Ronald S. Bultje 
---
 libavcodec/vp8.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 67f36d8933..db2419deaf 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -2404,7 +2404,8 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 int num_jobs = s->num_jobs;
 const VP8Frame *prev_frame = s->prev_frame;
 VP8Frame *curframe = s->curframe;
-VPXRangeCoder *c  = &s->coeff_partition[mb_y & (s->num_coeff_partitions - 
1)];
+VPXRangeCoder *coeff_c  = &s->coeff_partition[mb_y & 
(s->num_coeff_partitions - 1)];
+
 VP8Macroblock *mb;
 uint8_t *dst[3] = {
 curframe->tf.f->data[0] + 16 * mb_y * s->linesize,
@@ -2412,7 +2413,7 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 curframe->tf.f->data[2] +  8 * mb_y * s->uvlinesize
 };
 
-if (vpx_rac_is_end(c))
+if (vpx_rac_is_end(&s->c))
  return AVERROR_INVALIDDATA;
 
 if (mb_y == 0)
@@ -2443,7 +2444,7 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 td->mv_bounds.mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
 
 for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
-if (vpx_rac_is_end(c))
+if (vpx_rac_is_end(&s->c))
 return AVERROR_INVALIDDATA;
 // Wait for previous thread to read mb_x+2, and reach mb_y-1.
 if (prev_td != td) {
@@ -2470,8 +2471,11 @@ static av_always_inline int 
decode_mb_row_no_filter(AVCodecContext *avctx, void
 
 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS);
 
-if (!mb->skip)
-decode_mb_coeffs(s, td, c, mb, s->top_nnz[mb_x], td->left_nnz, 
is_vp7);
+if (!mb->skip) {
+if (vpx_rac_is_end(coeff_c))
+return AVERROR_INVALIDDATA;
+decode_mb_coeffs(s, td, coeff_c, mb, s->top_nnz[mb_x], 
td->left_nnz, is_vp7);
+}
 
 if (mb->mode <= MODE_I4x4)
 intra_predict(s, td, dst, mb, mb_x, mb_y, is_vp7);
-- 
2.38.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/2] avfilter/vf_libplacebo: default to normalize_sar=0

2022-11-18 Thread Niklas Haas
From: Niklas Haas 

As a result of a typo in the source code, this option was completely
non-functional. In order to fix it, without breaking the current default
(and, upon reconsideration, probably preferred) behavior, explicitly
change this default to 0.
---
 doc/filters.texi| 7 ---
 libavfilter/version.h   | 2 +-
 libavfilter/vf_libplacebo.c | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index e4da63cf48..d576e46d79 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -15581,9 +15581,10 @@ will be performed.
 Work the same as the identical @ref{scale} filter options.
 
 @item normalize_sar
-If enabled (the default), output frames will always have a pixel aspect ratio
-of 1:1. If disabled, any aspect ratio mismatches, including those from e.g.
-anamorphic video sources, are forwarded to the output pixel aspect ratio.
+If enabled, output frames will always have a pixel aspect ratio of 1:1. This
+will introduce padding/cropping as necessary. If disabled (the default), any
+aspect ratio mismatches, including those from e.g. anamorphic video sources,
+are forwarded to the output pixel aspect ratio.
 
 @item pad_crop_ratio
 Specifies a ratio (between @code{0.0} and @code{1.0}) between padding and
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 436c2b8b17..1553e7fecf 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFILTER_VERSION_MINOR  50
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101
 
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index fa9a7675d1..d52833263d 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -626,7 +626,7 @@ static const AVOption libplacebo_options[] = {
 { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, STATIC, 
"force_oar" },
 { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, STATIC, 
"force_oar" },
 { "force_divisible_by", "enforce that the output resolution is divisible 
by a defined integer when force_original_aspect_ratio is used", 
OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 256, STATIC },
-{ "normalize_sar", "force SAR normalization to 1:1", 
OFFSET(normalize_sar), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, STATIC },
+{ "normalize_sar", "force SAR normalization to 1:1", 
OFFSET(normalize_sar), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, STATIC },
 { "pad_crop_ratio", "ratio between padding and cropping when normalizing 
SAR (0=pad, 1=crop)", OFFSET(pad_crop_ratio), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 
0.0, 1.0, DYNAMIC },
 
 {"colorspace", "select colorspace", OFFSET(colorspace), AV_OPT_TYPE_INT, 
{.i64=-1}, -1, AVCOL_SPC_NB-1, DYNAMIC, "colorspace"},
-- 
2.38.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/2] avfilter/vf_libplacebo: fix normalize_sar calculation

2022-11-18 Thread Niklas Haas
From: Niklas Haas 

This previous expression multiplied a constant (outlink->h) that was
guaranteed to be 0 at this point, thus making it always a no-op.

Fix the calculation, and also properly reset the SAR to 1:1 as is now
necessary (the failure to do so previously hid this bug's existence).
---
 libavfilter/vf_libplacebo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index d52833263d..921cdb36fd 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -576,12 +576,13 @@ static int libplacebo_config_output(AVFilterLink *outlink)
s->force_original_aspect_ratio,
s->force_divisible_by);
 
-scale_sar = (AVRational){outlink->h * inlink->w, *out_w * *out_h};
+scale_sar = (AVRational){*out_h * inlink->w, *out_w * inlink->h};
 if (inlink->sample_aspect_ratio.num)
 scale_sar = av_mul_q(scale_sar, inlink->sample_aspect_ratio);
 
 if (s->normalize_sar) {
 /* Apply all SAR during scaling, so we don't need to set the out SAR */
+outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
 s->target_sar = scale_sar;
 } else {
 /* This is consistent with other scale_* filters, which only
-- 
2.38.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/av1_vaapi: add direct film grain mode

2022-11-18 Thread Ruijing Dong
Adding direct film grain mode for av1 decoder, which
outputs alongside film grain.

AV_HWACCEL_FLAG_DIRECT_FILM_GRAIN is the new flag
introduced to enable this path.

issue:
By using AMD av1 decoder via VAAPI, when used with film
grain content, the output displays black screen with
incorrect frame order.

The issue being discussed in here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/6903#note_1613807

example:
This flag can be used in ffmpeg command:

ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128
  -hwaccel_flags 8
  -i input_with_film_gram.obu
  output_with_film_grain.yuv

Signed-off-by: Ruijing Dong 
---
 libavcodec/avcodec.h   | 17 +
 libavcodec/vaapi_av1.c |  6 --
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3edd8e2636..9420e7820d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2253,6 +2253,23 @@ typedef struct AVHWAccel {
  */
 #define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2)
 
+/**
+ * The film grain synthesis could be seperate from decoding process.
+ * The downstream device would apply the film grain parameters seperately.
+ * The desired film grain parameters can be found in SEI section in H264
+ * or H265 bitstreams.
+ *
+ * In AV1, film grain is mandatorily specified, av1 decoders like AMD
+ * av1 decoder process film grain content internally, and the output
+ * includes applied film grain. For the purpose of supporting these av1
+ * decoders, this flag needs to be utilized.
+ *
+ * @warning If the stream has no film grain content, this flag will
+ *  be ignored in the supported av1 decoders. It is advised
+ *  that this flag should only be used in av1 decoders
+ *  that support it.
+ */
+#define AV_HWACCEL_FLAG_DIRECT_FILM_GRAIN (1 << 3)
 /**
  * @}
  */
diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index d0339b2705..6db910f2bf 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -127,6 +127,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
 int8_t bit_depth_idx;
 int err = 0;
 int apply_grain = !(avctx->export_side_data & 
AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain;
+int direct_film_grain = avctx->hwaccel_flags & 
AV_HWACCEL_FLAG_DIRECT_FILM_GRAIN;
 uint8_t remap_lr_type[4] = {AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, 
AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ};
 uint8_t segmentation_feature_signed[AV1_SEG_LVL_MAX] = {1, 1, 1, 1, 1, 0, 
0, 0};
 uint8_t segmentation_feature_max[AV1_SEG_LVL_MAX] = {255, 
AV1_MAX_LOOP_FILTER,
@@ -136,7 +137,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
 if (bit_depth_idx < 0)
 goto fail;
 
-if (apply_grain) {
+if (apply_grain && !direct_film_grain) {
 if (ctx->tmp_frame->buf[0])
 ff_thread_release_buffer(avctx, ctx->tmp_frame);
 err = ff_thread_get_buffer(avctx, ctx->tmp_frame, 
AV_GET_BUFFER_FLAG_REF);
@@ -375,6 +376,7 @@ static int vaapi_av1_end_frame(AVCodecContext *avctx)
 VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
 
 int apply_grain = !(avctx->export_side_data & 
AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain;
+int direct_film_grain = avctx->hwaccel_flags & 
AV_HWACCEL_FLAG_DIRECT_FILM_GRAIN;
 int ret;
 ret = ff_vaapi_decode_issue(avctx, pic);
 if (ret < 0)
@@ -385,7 +387,7 @@ static int vaapi_av1_end_frame(AVCodecContext *avctx)
 if (ctx->ref_tab[i].frame->buf[0])
 ff_thread_release_buffer(avctx, ctx->ref_tab[i].frame);
 
-if (apply_grain) {
+if (apply_grain && !direct_film_grain) {
 ret = av_frame_ref(ctx->ref_tab[i].frame, ctx->tmp_frame);
 if (ret < 0)
 return ret;
-- 
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] [PATCH] avformat/file: add fd protocol

2022-11-18 Thread Zhao Zhili
From: Zhao Zhili 

Unlike the pipe protocol, fd protocol has seek support if it
corresponding to a regular file.
---
Sometimes it's the only way to access files via file descriptor, e.g.,
requesting a shared file on Android:
https://developer.android.com/training/secure-file-sharing/request-file

 doc/protocols.texi  | 24 +++
 libavformat/Makefile|  1 +
 libavformat/file.c  | 51 +
 libavformat/protocols.c |  1 +
 libavformat/version.h   |  4 ++--
 5 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 5e9198e67c..d9f2d2dec3 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -275,6 +275,30 @@ For example, to convert a GIF file given inline with 
@command{ffmpeg}:
 ffmpeg -i 
"data:image/gif;base64,R0lGODdhCAAIAMIE//8AAP//AP///ywACAAIAAADF0gEDLojDgdGiJdJqUX02iB4E8Q9jUMkADs="
 smiley.png
 @end example
 
+@section fd
+
+File descriptor access protocol.
+
+The accepted syntax is:
+@example
+fd:[@var{number}]
+@end example
+
+@var{number} is the number corresponding to a file descriptor. Unlike the pipe
+protocol, fd protocol has seek support if it corresponding to a regular file.
+If @var{number} is not specified, by default the stdout file descriptor will
+be used for writing, stdin for reading.
+
+This protocol accepts the following options:
+
+@table @option
+@item blocksize
+Set I/O operation maximum block size, in bytes. Default value is
+@code{INT_MAX}, which results in not limiting the requested block size.
+Setting this value reasonably low improves user termination request reaction
+time, which is valuable if data transmission is slow.
+@end table
+
 @section file
 
 File access protocol.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index d7f198bf39..1452216e29 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -647,6 +647,7 @@ OBJS-$(CONFIG_DATA_PROTOCOL) += data_uri.o
 OBJS-$(CONFIG_FFRTMPCRYPT_PROTOCOL)  += rtmpcrypt.o rtmpdigest.o rtmpdh.o
 OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL)   += rtmphttp.o
 OBJS-$(CONFIG_FILE_PROTOCOL) += file.o
+OBJS-$(CONFIG_FD_PROTOCOL)   += file.o
 OBJS-$(CONFIG_FTP_PROTOCOL)  += ftp.o urldecode.o
 OBJS-$(CONFIG_GOPHER_PROTOCOL)   += gopher.o
 OBJS-$(CONFIG_GOPHERS_PROTOCOL)  += gopher.o
diff --git a/libavformat/file.c b/libavformat/file.c
index 6103c37b34..765ad21d67 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -109,6 +109,13 @@ static const AVClass pipe_class = {
 .version= LIBAVUTIL_VERSION_INT,
 };
 
+static const AVClass fd_class = {
+.class_name = "fd",
+.item_name  = av_default_item_name,
+.option = pipe_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
 static int file_read(URLContext *h, unsigned char *buf, int size)
 {
 FileContext *c = h->priv_data;
@@ -412,3 +419,47 @@ const URLProtocol ff_pipe_protocol = {
 };
 
 #endif /* CONFIG_PIPE_PROTOCOL */
+
+#if CONFIG_FD_PROTOCOL
+
+static int fd_open(URLContext *h, const char *filename, int flags)
+{
+FileContext *c = h->priv_data;
+int fd;
+char *final;
+struct stat st;
+
+av_strstart(filename, "fd:", &filename);
+
+fd = strtol(filename, &final, 10);
+if((filename == final) || *final ) {/* No digits found, or something like 
10ab */
+if (flags & AVIO_FLAG_WRITE) {
+fd = 1;
+} else {
+fd = 0;
+}
+}
+#if HAVE_SETMODE
+setmode(fd, O_BINARY);
+#endif
+if (fstat(fd, &st) < 0)
+return AVERROR(errno);
+h->is_streamed = !(S_ISREG(st.st_mode) || S_ISBLK(st.st_mode));
+c->fd = fd;
+return 0;
+}
+
+const URLProtocol ff_fd_protocol = {
+.name= "fd",
+.url_open= fd_open,
+.url_read= file_read,
+.url_write   = file_write,
+.url_seek= file_seek,
+.url_get_file_handle = file_get_handle,
+.url_check   = file_check,
+.priv_data_size  = sizeof(FileContext),
+.priv_data_class = &fd_class,
+.default_whitelist   = "crypto,data"
+};
+
+#endif /* CONFIG_FD_PROTOCOL */
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 8b7d1b940f..82cb1033e4 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -29,6 +29,7 @@ extern const URLProtocol ff_concat_protocol;
 extern const URLProtocol ff_concatf_protocol;
 extern const URLProtocol ff_crypto_protocol;
 extern const URLProtocol ff_data_protocol;
+extern const URLProtocol ff_fd_protocol;
 extern const URLProtocol ff_ffrtmpcrypt_protocol;
 extern const URLProtocol ff_ffrtmphttp_protocol;
 extern const URLProtocol ff_file_protocol;
diff --git a/libavformat/version.h b/libavformat/version.h
index 7c9d50b7b3..f5a7f579b3 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,8 +31,8 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSI

[FFmpeg-devel] hashing audio streams beyond pcm_s16le

2022-11-18 Thread Peter B.

Hello everyone :)

I was wondering about the behavior of FFmpeg's hashing muxer for audio 
streams:


For example:
With a 32bit float (f32le) source, FFmpeg seems to be able to generate a 
hash for the f32le source - but only if I explicitly know (and then 
tell) FFmpeg to do so.

By default, I get the hash of a pcm_s16le version (see examples below).

I remember it defaults to "pcm_s16le" (also mentioned in 
https://trac.ffmpeg.org/wiki/framemd5%20Intro%20and%20HowTo), but why is 
that so?


And would it be possible to generate the hash of the source audio, 
without having to know what raw/uncompressed type it is?
I would like to be able to use the hash to compare lossless conversion 
of the content between different audio formats (eg vs FLAC and PCM).




Thank you very much in advance :)
Peter B.



Example:

# pcm_f32le defaults to pcm_s16le hash:
$ ffmpeg-git -loglevel quiet -i drums3.wav -f streamhash -hash md5 -
0,a,MD5=08170d6e02fbccc07b61fbf1d7476057

# ...as shown here:
$ ffmpeg-git -loglevel quiet -i drums3.wav -c:a pcm_s16le -f streamhash 
-hash md5 -

0,a,MD5=08170d6e02fbccc07b61fbf1d7476057

#
$ ffmpeg-git -loglevel quiet -i drums3.wav -c:a pcm_f32le -f streamhash 
-hash md5 -

0,a,MD5=1444cdc20cb8ea30874114cb53729797

$ ffmpeg-git -loglevel quiet -i drums3.wav -c:a copy -f streamhash -hash 
md5 -

0,a,MD5=1444cdc20cb8ea30874114cb53729797



$ ffmpeg-git -i drums3.wav -hash md5 -

ffmpeg version N-109029-g1800a0da09 Copyright (c) 2000-2022 the FFmpeg 
developers

  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree 
--enable-version3 --enable-postproc --enable-ffplay --enable-swscale 
--enable-avfilter --enable-pthreads --enable-bzlib --enable-zlib 
--enable-decoder=png --enable-encoder=png --enable-openssl 
--samples=../fate-suite --enable-libfreetype --enable-libopenjpeg 
--disable-decoder=jpeg2000 --enable-libvpx --enable-libvorbis 
--enable-libx264 --enable-libx265

  libavutil  57. 42.100 / 57. 42.100
  libavcodec 59. 52.100 / 59. 52.100
  libavformat    59. 34.101 / 59. 34.101
  libavdevice    59.  8.101 / 59.  8.101
  libavfilter 8. 50.100 /  8. 50.100
  libswscale  6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    56.  7.100 / 56.  7.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, wav, from 'drums3.wav':
  Duration: 00:00:54.25, bitrate: 1536 kb/s
  Stream #0:0: Audio: pcm_f32le ([3][0][0][0] / 0x0003), 48000 Hz, 1 
channels, flt, 1536 kb/s





___
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/4] avcodec/tiff: Ignore tile_count

2022-11-18 Thread Michael Niedermayer
Fixes: out of array access
Fixes: 
52427/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-4849108968144896

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

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index cde318d5e5..b962dce5a2 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -994,7 +994,7 @@ static int dng_decode_tiles(AVCodecContext *avctx, AVFrame 
*frame,
 tile_count_y = (s->height + s->tile_length - 1) / s->tile_length;
 
 /* Iterate over the number of tiles */
-for (tile_idx = 0; tile_idx < s->tile_count; tile_idx++) {
+for (tile_idx = 0; tile_idx < tile_count_x * tile_count_y; tile_idx++) {
 tile_x = tile_idx % tile_count_x;
 tile_y = tile_idx / tile_count_x;
 
-- 
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/4] avformat/id3v2: Check taglen in read_uslt()

2022-11-18 Thread Michael Niedermayer
Fixes: Timeout (read mostly the same data repeatly)
Fixes: 
52457/clusterfuzz-testcase-minimized-ffmpeg_dem_ALP_fuzzer-6610706313379840

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

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 191a305ffb..cb31864045 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -377,10 +377,10 @@ static void read_uslt(AVFormatContext *s, AVIOContext 
*pb, int taglen,
 lang[3] = '\0';
 taglen -= 3;
 
-if (decode_str(s, pb, encoding, &descriptor, &taglen) < 0)
+if (decode_str(s, pb, encoding, &descriptor, &taglen) < 0 || taglen < 0)
 goto error;
 
-if (decode_str(s, pb, encoding, &text, &taglen) < 0)
+if (decode_str(s, pb, encoding, &text, &taglen) < 0 || taglen < 0)
 goto error;
 
 // FFmpeg does not support hierarchical metadata, so concatenate the keys.
-- 
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 3/4] avcodec/mobiclip: Check input size before (re)allocation

2022-11-18 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
52566/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOBICLIP_fuzzer-4913160050311168

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

diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c
index aca462428c..c3b2383dbc 100644
--- a/libavcodec/mobiclip.c
+++ b/libavcodec/mobiclip.c
@@ -1216,6 +1216,9 @@ static int mobiclip_decode(AVCodecContext *avctx, AVFrame 
*rframe,
 AVFrame *frame = s->pic[s->current_pic];
 int ret;
 
+if (avctx->height/16 * (avctx->width/16) * 2 > 8LL*FFALIGN(pkt->size, 2))
+return AVERROR_INVALIDDATA;
+
 av_fast_padded_malloc(&s->bitstream, &s->bitstream_size,
   pkt->size);
 
-- 
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 4/4] avcodec/vqcdec: Check for end of input in decode_vectors()

2022-11-18 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
52695/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VQC_fuzzer-4882310386548736

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

diff --git a/libavcodec/vqcdec.c b/libavcodec/vqcdec.c
index 5d1a03158c..18cd99462e 100644
--- a/libavcodec/vqcdec.c
+++ b/libavcodec/vqcdec.c
@@ -137,7 +137,7 @@ static void seed_codebooks(VqcContext * s, const int * seed)
 }
 }
 
-static void decode_vectors(VqcContext * s, const uint8_t * buf, int size, int 
width, int height)
+static int decode_vectors(VqcContext * s, const uint8_t * buf, int size, int 
width, int height)
 {
 GetBitContext gb;
 uint8_t * vectors = s->vectors;
@@ -155,9 +155,11 @@ static void decode_vectors(VqcContext * s, const uint8_t * 
buf, int size, int wi
 *dst++ = get_bits(&gb, 8);
 
 while (show_bits(&gb, 2) != 2) {
-
 if (dst >= vectors_end - 1)
-return;
+return 0;
+
+if (get_bits_left(&gb) < 4)
+return AVERROR_INVALIDDATA;
 
 if (!show_bits(&gb, 4)) {
 *dst++ = 0;
@@ -182,6 +184,8 @@ static void decode_vectors(VqcContext * s, const uint8_t * 
buf, int size, int wi
 skip_bits(&gb, 2);
 vectors += 32;
 }
+
+return 0;
 }
 
 static void load_coeffs(VqcContext * s, const uint8_t * v, int width, int 
coeff_width)
@@ -392,7 +396,9 @@ static int vqc_decode_frame(AVCodecContext *avctx, AVFrame 
* rframe,
 avpriv_request_sample(avctx, "gamma=0x%x, contrast=0x%x\n", gamma, 
contrast);
 
 seed_codebooks(s, seed);
-decode_vectors(s, buf + 7, avpkt->size - 7, avctx->width, avctx->height);
+ret = decode_vectors(s, buf + 7, avpkt->size - 7, avctx->width, 
avctx->height);
+if (ret < 0)
+return ret;
 decode_frame(s, avctx->width, avctx->height);
 
 if ((ret = av_frame_ref(rframe, s->frame)) < 0)
-- 
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".


Re: [FFmpeg-devel] [PATCH 4/4] avcodec/vqcdec: Check for end of input in decode_vectors()

2022-11-18 Thread Peter Ross
On Fri, Nov 18, 2022 at 10:09:18PM +0100, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 
> 52695/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VQC_fuzzer-4882310386548736
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/vqcdec.c | 14 ++
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/vqcdec.c b/libavcodec/vqcdec.c
> index 5d1a03158c..18cd99462e 100644
> --- a/libavcodec/vqcdec.c
> +++ b/libavcodec/vqcdec.c
> @@ -137,7 +137,7 @@ static void seed_codebooks(VqcContext * s, const int * 
> seed)
>  }
>  }
>  
> -static void decode_vectors(VqcContext * s, const uint8_t * buf, int size, 
> int width, int height)
> +static int decode_vectors(VqcContext * s, const uint8_t * buf, int size, int 
> width, int height)
>  {
>  GetBitContext gb;
>  uint8_t * vectors = s->vectors;
> @@ -155,9 +155,11 @@ static void decode_vectors(VqcContext * s, const uint8_t 
> * buf, int size, int wi
>  *dst++ = get_bits(&gb, 8);
>  
>  while (show_bits(&gb, 2) != 2) {
> -
>  if (dst >= vectors_end - 1)
> -return;
> +return 0;
> +
> +if (get_bits_left(&gb) < 4)
> +return AVERROR_INVALIDDATA;
>  
>  if (!show_bits(&gb, 4)) {
>  *dst++ = 0;
> @@ -182,6 +184,8 @@ static void decode_vectors(VqcContext * s, const uint8_t 
> * buf, int size, int wi
>  skip_bits(&gb, 2);
>  vectors += 32;
>  }
> +
> +return 0;
>  }
>  
>  static void load_coeffs(VqcContext * s, const uint8_t * v, int width, int 
> coeff_width)
> @@ -392,7 +396,9 @@ static int vqc_decode_frame(AVCodecContext *avctx, 
> AVFrame * rframe,
>  avpriv_request_sample(avctx, "gamma=0x%x, contrast=0x%x\n", gamma, 
> contrast);
>  
>  seed_codebooks(s, seed);
> -decode_vectors(s, buf + 7, avpkt->size - 7, avctx->width, avctx->height);
> +ret = decode_vectors(s, buf + 7, avpkt->size - 7, avctx->width, 
> avctx->height);
> +if (ret < 0)
> +return ret;
>  decode_frame(s, avctx->width, avctx->height);

please apply

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
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 3/4] avcodec/mobiclip: Check input size before (re)allocation

2022-11-18 Thread Shiyou Yin
Please ignore fail info form loongarch64 patchwork temporarily.
I have stoped the service from Nov 16th, but there are still result post to 
patchwork.
Have mailed to Andriy to help analyze this problem together.

> 2022年11月19日 05:09,Michael Niedermayer  写道:
> 
> Fixes: Timeout
> Fixes: 
> 52566/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOBICLIP_fuzzer-4913160050311168
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
> libavcodec/mobiclip.c | 3 +++
> 1 file changed, 3 insertions(+)
> 
> diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c
> index aca462428c..c3b2383dbc 100644
> --- a/libavcodec/mobiclip.c
> +++ b/libavcodec/mobiclip.c
> @@ -1216,6 +1216,9 @@ static int mobiclip_decode(AVCodecContext *avctx, 
> AVFrame *rframe,
> AVFrame *frame = s->pic[s->current_pic];
> int ret;
> 
> +if (avctx->height/16 * (avctx->width/16) * 2 > 8LL*FFALIGN(pkt->size, 2))
> +return AVERROR_INVALIDDATA;
> +
> av_fast_padded_malloc(&s->bitstream, &s->bitstream_size,
>   pkt->size);
> 
> -- 
> 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 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/7] avcodec/pnmenc: Check av_image_get_buffer_size()

2022-11-18 Thread Andreas Rheinhardt
Fixes the crash in ticket #10050.
Also ensure that we don't overflow before ff_get_encode_buffer().

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/pnmenc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c
index 9eb663306d..c998dd410c 100644
--- a/libavcodec/pnmenc.c
+++ b/libavcodec/pnmenc.c
@@ -42,7 +42,10 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 int size = av_image_get_buffer_size(avctx->pix_fmt,
 avctx->width, avctx->height, 1);
 
-if ((ret = ff_get_encode_buffer(avctx, pkt, size + 200, 0)) < 0)
+if (size < 0)
+return size;
+
+if ((ret = ff_get_encode_buffer(avctx, pkt, size + 200U, 0)) < 0)
 return ret;
 
 bytestream_start =
-- 
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] [PATCH 2/7] avcodec/flashsvenc: Account for header in packet size

2022-11-18 Thread Andreas Rheinhardt
Fixes ticket #10053.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/flashsvenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index 35793400fa..9d065bb92d 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -229,7 +229,8 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 I_frame = 1;
 }
 
-if ((res = ff_alloc_packet(avctx, pkt, s->image_width * s->image_height * 
3)) < 0)
+res = ff_alloc_packet(avctx, pkt, 4U + s->image_width * s->image_height * 
3);
+if (res < 0)
 return res;
 
 pkt->size = encode_bitstream(s, p, pkt->data, pkt->size, opt_w * 16, opt_h 
* 16,
-- 
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] [PATCH 3/7] avcodec/flashsvenc: Remove unused buffer

2022-11-18 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/flashsvenc.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index 9d065bb92d..0618b2aa1b 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -60,7 +60,6 @@ typedef struct FlashSVContext {
 uint8_t*previous_frame;
 int image_width, image_height;
 int block_width, block_height;
-uint8_t*encbuffer;
 int block_size;
 int last_key_frame;
 uint8_t tmpblock[3 * 256 * 256];
@@ -91,7 +90,6 @@ static av_cold int flashsv_encode_end(AVCodecContext *avctx)
 {
 FlashSVContext *s = avctx->priv_data;
 
-av_freep(&s->encbuffer);
 av_freep(&s->previous_frame);
 
 return 0;
@@ -114,13 +112,6 @@ static av_cold int flashsv_encode_init(AVCodecContext 
*avctx)
 s->image_width  = avctx->width;
 s->image_height = avctx->height;
 
-s->encbuffer = av_mallocz(s->image_width * s->image_height * 3);
-
-if (!s->encbuffer) {
-av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
-return AVERROR(ENOMEM);
-}
-
 return 0;
 }
 
-- 
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] [PATCH 4/7] avcodec/flashsvenc: Use const where appropriate

2022-11-18 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/flashsvenc.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index 0618b2aa1b..18dfde0e24 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -66,15 +66,14 @@ typedef struct FlashSVContext {
 } FlashSVContext;
 
 static int copy_region_enc(const uint8_t *sptr, uint8_t *dptr, int dx, int dy,
-   int h, int w, int stride, uint8_t *pfptr)
+   int h, int w, int stride, const uint8_t *pfptr)
 {
 int i, j;
-uint8_t *npfptr;
 int diff = 0;
 
 for (i = dx + h; i > dx; i--) {
 const uint8_t *nsptr = sptr + i * stride + dy * 3;
-npfptr = pfptr + i * stride + dy * 3;
+const uint8_t *npfptr = pfptr + i * stride + dy * 3;
 for (j = 0; j < w * 3; j++) {
 diff|= npfptr[j] ^ nsptr[j];
 dptr[j]  = nsptr[j];
@@ -118,7 +117,7 @@ static av_cold int flashsv_encode_init(AVCodecContext 
*avctx)
 
 static int encode_bitstream(FlashSVContext *s, const AVFrame *p, uint8_t *buf,
 int buf_size, int block_width, int block_height,
-uint8_t *previous_frame, int *I_frame)
+const uint8_t *previous_frame, int *I_frame)
 {
 
 PutBitContext pb;
@@ -194,7 +193,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 {
 FlashSVContext * const s = avctx->priv_data;
 const AVFrame * const p = pict;
-uint8_t *pfptr;
+const uint8_t *pfptr;
 int res;
 int I_frame = 0;
 int opt_w = 4, opt_h = 4;
-- 
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] [PATCH 5/7] avcodec/flashsvenc: Change check for first frame

2022-11-18 Thread Andreas Rheinhardt
AVCodecContext.frame_number is actually only incremented
in case encoding was successfull; if e.g. the ff_alloc_packet()
below fails, it won't be incremented and therefore it is possible
for the previous_frame buffer to be allocated for multiple
first frames, leaking every one except the last.
So check for whether there already is a previous frame instead.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/flashsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index 18dfde0e24..f42ef73b37 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -199,7 +199,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 int opt_w = 4, opt_h = 4;
 
 /* First frame needs to be a keyframe */
-if (avctx->frame_number == 0) {
+if (!s->previous_frame) {
 s->previous_frame = av_mallocz(FFABS(p->linesize[0]) * 
s->image_height);
 if (!s->previous_frame) {
 av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
-- 
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] [PATCH 6/7] avcodec/flashsvenc: Avoid copying frame

2022-11-18 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/flashsvenc.c | 36 +++-
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index f42ef73b37..3c3d9c8813 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -48,6 +48,8 @@
 #include 
 #include 
 
+#include "libavutil/buffer.h"
+
 #include "avcodec.h"
 #include "codec_internal.h"
 #include "encode.h"
@@ -58,6 +60,7 @@
 typedef struct FlashSVContext {
 AVCodecContext *avctx;
 uint8_t*previous_frame;
+AVBufferRef*prev_frame_buf;
 int image_width, image_height;
 int block_width, block_height;
 int block_size;
@@ -89,7 +92,7 @@ static av_cold int flashsv_encode_end(AVCodecContext *avctx)
 {
 FlashSVContext *s = avctx->priv_data;
 
-av_freep(&s->previous_frame);
+av_buffer_unref(&s->prev_frame_buf);
 
 return 0;
 }
@@ -193,26 +196,19 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 {
 FlashSVContext * const s = avctx->priv_data;
 const AVFrame * const p = pict;
-const uint8_t *pfptr;
 int res;
 int I_frame = 0;
 int opt_w = 4, opt_h = 4;
 
 /* First frame needs to be a keyframe */
-if (!s->previous_frame) {
-s->previous_frame = av_mallocz(FFABS(p->linesize[0]) * 
s->image_height);
-if (!s->previous_frame) {
-av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
+if (!s->prev_frame_buf) {
+s->prev_frame_buf = av_buffer_ref(pict->buf[0]);
+if (!s->prev_frame_buf)
 return AVERROR(ENOMEM);
-}
+s->previous_frame = pict->data[0];
 I_frame = 1;
 }
 
-if (p->linesize[0] < 0)
-pfptr = s->previous_frame - (s->image_height - 1) * p->linesize[0];
-else
-pfptr = s->previous_frame;
-
 /* Check the placement of keyframes */
 if (avctx->gop_size > 0 &&
 avctx->frame_number >= s->last_key_frame + avctx->gop_size) {
@@ -224,15 +220,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 return res;
 
 pkt->size = encode_bitstream(s, p, pkt->data, pkt->size, opt_w * 16, opt_h 
* 16,
- pfptr, &I_frame);
-
-//save the current frame
-if (p->linesize[0] > 0)
-memcpy(s->previous_frame, p->data[0], s->image_height * 
p->linesize[0]);
-else
-memcpy(s->previous_frame,
-   p->data[0] + p->linesize[0] * (s->image_height - 1),
-   s->image_height * FFABS(p->linesize[0]));
+ s->previous_frame, &I_frame);
 
 //mark the frame type so the muxer can mux it correctly
 if (I_frame) {
@@ -244,6 +232,12 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 pkt->flags |= AV_PKT_FLAG_KEY;
 *got_packet = 1;
 
+//save the current frame
+res = av_buffer_replace(&s->prev_frame_buf, pict->buf[0]);
+if (res < 0)
+return res;
+s->previous_frame = pict->data[0];
+
 return 0;
 }
 
-- 
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] [PATCH 7/7] avcodec/flashsvenc: Avoid unnecessary variable

2022-11-18 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/flashsvenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index 3c3d9c8813..89119733df 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -195,7 +195,6 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 const AVFrame *pict, int *got_packet)
 {
 FlashSVContext * const s = avctx->priv_data;
-const AVFrame * const p = pict;
 int res;
 int I_frame = 0;
 int opt_w = 4, opt_h = 4;
@@ -219,7 +218,8 @@ static int flashsv_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 if (res < 0)
 return res;
 
-pkt->size = encode_bitstream(s, p, pkt->data, pkt->size, opt_w * 16, opt_h 
* 16,
+pkt->size = encode_bitstream(s, pict, pkt->data, pkt->size,
+ opt_w * 16, opt_h * 16,
  s->previous_frame, &I_frame);
 
 //mark the frame type so the muxer can mux it correctly
-- 
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".