[FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling

2025-02-05 Thread Jack Lau via ffmpeg-devel
From: Jack Lau 

The `dec_ctx->time_base` was incorrectly default set by avcodec_open2(), while 
`enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could 
cause incorrect video duration in the output.

This patch corrects the issue by adjusting the `enc_ctx->time_base` calculation 
to account for `ticks_per_frame`, ensuring that the time base is consistent 
between the decoder and encoder contexts.
---
 doc/examples/transcoding.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 013f89fc7d..09c2ad4b62 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -172,7 +172,7 @@ static int open_output_file(const char *filename)
 else
 enc_ctx->pix_fmt = dec_ctx->pix_fmt;
 /* video time_base can be set to whatever is handy and 
supported by encoder */
-enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+enc_ctx->time_base = av_inv_q(av_mul_q(dec_ctx->framerate, 
(AVRational){dec_ctx->ticks_per_frame, 1}));
 } else {
 enc_ctx->sample_rate = dec_ctx->sample_rate;
 ret = av_channel_layout_copy(&enc_ctx->ch_layout, 
&dec_ctx->ch_layout);
@@ -180,7 +180,7 @@ static int open_output_file(const char *filename)
 return ret;
 /* take first format from list of supported formats */
 enc_ctx->sample_fmt = encoder->sample_fmts[0];
-enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+enc_ctx->time_base = (AVRational){1, dec_ctx->sample_rate};
 }
 
 if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
-- 
2.48.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] examples/transcoding: Fix time_base handling

2025-02-05 Thread Jack Lau
Hello.

I found one better method to fix this issue. Firstly, i think the problem
caused by incorrectly setting enc_ctx->time_base, so i refer to the
implementation in avcodec_open2()

361 #if FF_API_AVCTX_TIMEBASE
362if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
363 avctx->time_base = av_inv_q(av_mul_q(avctx->framerate,
(AVRational){avctx->ticks_per_frame, 1}));
364 #endif

this is new version code and i submit it in new mail, it can be reviewed in
https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_7adfe69819d49d96fa8bc2c9e688ccec2...@qq.com/
-enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+enc_ctx->time_base = av_inv_q(av_mul_q(dec_ctx->framerate,
(AVRational){dec_ctx->ticks_per_frame, 1}));

-enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+enc_ctx->time_base = (AVRational){1, dec_ctx->sample_rate};

but there is new issue in andriy/configure_x86 check:

error: Failed to merge in the changes.

i think it's maybe the mistake of branch? this patch is for release/5.1
branch rather than master branch.

Could any one give me some advice please so that i can fix it?


On Wed, Feb 5, 2025 at 11:25 AM Jack Lau  wrote:

> To be clear, i want to give an example, i use a 10s duration, 30fps video.
> The ifmt_ctx->streams[stream_index]->time_base is same as
> ofmt_ctx->streams[stream_index]->time_base after initializing.
> The stream->dec_ctx->time_base is default 0,60 but
> stream->enc_ctx->time_base is set to av_inv_q(dec_ctx->framerate) so it's
> 0,30
>
> 174 /* video time_base can be set to whatever is handy and
> supported by encoder */
> 175 enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
>
> so the twice rescale is this:
> input pkt in_tb: 15360   out_tb: 60
> output pkt in_tb: 30 out_tb: 15360
>
> so i get one 20s duration and 15fps video(audio duration is normal because
> the input's audio sample ratio is 44100)
>
> So i think the problem is that the enc_ctx->time_base shouldn't set to
> av_inv_q(dec_ctx->framerate)
>
> On Wed, Feb 5, 2025 at 10:29 AM Jack Lau  wrote:
>
>>
>> AVCodecContext.time_base is not used for decoding.
>>
>>
>>
>> Thank you for your reply. I understand that time_base is not used during
>> decoding, but the transcoding code calls av_packet_rescale_ts twice,
>> once before decoding and once after encoding, as shown below:
>>
>> 540 if (filter_ctx[stream_index].filter_graph) {
>> 541 StreamContext *stream = &stream_ctx[stream_index];
>> 542
>> 543 av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the
>> frame\n");
>> 544
>> 545 av_packet_rescale_ts(packet,
>>
>>
>> 546
>>  ifmt_ctx->streams[stream_index]->time_base,
>> 547  stream->dec_ctx->time_base);
>> 548 ret = avcodec_send_packet(stream->dec_ctx, packet);
>>
>> 448 /* prepare packet for muxing */
>>
>>
>> 449 enc_pkt->stream_index = stream_index;
>> 450 av_packet_rescale_ts(enc_pkt,
>> 451  stream->enc_ctx->time_base,
>> 452
>>  ofmt_ctx->streams[stream_index]->time_base);
>> 453
>> 454 av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
>> 455 /* mux encoded frame */
>> 456 ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
>>
>> If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can
>> lead to incorrect packet duration, which in turn causes issues with the
>> output file's duration.
>>
>
___
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/mxfdec: Check edit unit for overflow in mxf_set_current_edit_unit()

2025-02-05 Thread Michael Niedermayer
Fixes: signed integer overflow: 9223372036854775807 + 1 cannot be represented 
in type 'long'
Fixes: 
392672068/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-6232335892152320

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

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 6bc8980d9c1..3b87063c3f2 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -3956,7 +3956,7 @@ static int64_t mxf_set_current_edit_unit(MXFContext *mxf, 
AVStream *st, int64_t
 int64_t new_edit_unit;
 MXFIndexTable *t = mxf_find_index_table(mxf, track->index_sid);
 
-if (!t || track->wrapping == UnknownWrapped)
+if (!t || track->wrapping == UnknownWrapped || edit_unit > INT64_MAX - 
track->edit_units_per_packet)
 return -1;
 
 if (mxf_edit_unit_absolute_offset(mxf, t, edit_unit + 
track->edit_units_per_packet, track->edit_rate, NULL, &next_ofs, NULL, 0) < 0 &&
-- 
2.48.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/libx264: Fix deprecation warnings on pix_fmts

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/allcodecs.c |  6 ++---
 libavcodec/libx264.c   | 53 +-
 2 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4e1b1c9b45..d2ec4c3045 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -811,9 +811,9 @@ extern const FFCodec ff_libvvenc_encoder;
 /* preferred over libwebp */
 extern const FFCodec ff_libwebp_anim_encoder;
 extern const FFCodec ff_libwebp_encoder;
-extern const FFCodec ff_libx262_encoder;
-extern const FFCodec ff_libx264_encoder;
-extern const FFCodec ff_libx264rgb_encoder;
+extern FFCodec ff_libx262_encoder;
+extern FFCodec ff_libx264_encoder;
+extern FFCodec ff_libx264rgb_encoder;
 extern FFCodec ff_libx265_encoder;
 extern const FFCodec ff_libxeve_encoder;
 extern const FFCodec ff_libxevd_decoder;
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 409f45fc7d..c4bc7c48f5 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1607,6 +1607,12 @@ static const FFCodecDefault x264_defaults[] = {
 { NULL },
 };
 
+static int X264_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags, const void **out,
+ int *out_num);
+
 #if CONFIG_LIBX264_ENCODER
 static const AVClass x264_class = {
 .class_name = "libx264",
@@ -1615,7 +1621,7 @@ static const AVClass x264_class = {
 .version= LIBAVUTIL_VERSION_INT,
 };
 
-const FFCodec ff_libx264_encoder = {
+FFCodec ff_libx264_encoder = {
 .p.name   = "libx264",
 CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
 .p.type   = AVMEDIA_TYPE_VIDEO,
@@ -1633,13 +1639,13 @@ const FFCodec ff_libx264_encoder = {
 .flush= X264_flush,
 .close= X264_close,
 .defaults = x264_defaults,
-.p.pix_fmts   = pix_fmts_all,
 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
 .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
 #if X264_BUILD < 158
   | FF_CODEC_CAP_NOT_INIT_THREADSAFE
 #endif
   ,
+.get_supported_config = X264_get_supported_config,
 };
 #endif
 
@@ -1651,7 +1657,7 @@ static const AVClass rgbclass = {
 .version= LIBAVUTIL_VERSION_INT,
 };
 
-const FFCodec ff_libx264rgb_encoder = {
+FFCodec ff_libx264rgb_encoder = {
 .p.name = "libx264rgb",
 CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
 .p.type = AVMEDIA_TYPE_VIDEO,
@@ -1659,7 +1665,6 @@ const FFCodec ff_libx264rgb_encoder = {
 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
   AV_CODEC_CAP_OTHER_THREADS |
   AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
-.p.pix_fmts = pix_fmts_8bit_rgb,
 .p.priv_class   = &rgbclass,
 .p.wrapper_name = "libx264",
 .priv_data_size = sizeof(X264Context),
@@ -1672,6 +1677,7 @@ const FFCodec ff_libx264rgb_encoder = {
   | FF_CODEC_CAP_NOT_INIT_THREADSAFE
 #endif
   ,
+.get_supported_config = X264_get_supported_config,
 };
 #endif
 
@@ -1683,7 +1689,7 @@ static const AVClass X262_class = {
 .version= LIBAVUTIL_VERSION_INT,
 };
 
-const FFCodec ff_libx262_encoder = {
+FFCodec ff_libx262_encoder = {
 .p.name   = "libx262",
 CODEC_LONG_NAME("libx262 MPEG2VIDEO"),
 .p.type   = AVMEDIA_TYPE_VIDEO,
@@ -1691,7 +1697,6 @@ const FFCodec ff_libx262_encoder = {
 .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
 AV_CODEC_CAP_OTHER_THREADS |
 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
-.p.pix_fmts   = pix_fmts_8bit,
 .color_ranges = AVCOL_RANGE_MPEG,
 .p.priv_class = &X262_class,
 .p.wrapper_name   = "libx264",
@@ -1702,5 +1707,41 @@ const FFCodec ff_libx262_encoder = {
 .defaults = x264_defaults,
 .caps_internal= FF_CODEC_CAP_NOT_INIT_THREADSAFE |
 FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
+.get_supported_config = X264_get_supported_config,
 };
 #endif
+
+static int X264_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags, const void **out,
+ int *out_num)
+{
+if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
+#if CONFIG_LIBX264_ENCODER
+if (codec == &ff_libx264_encoder.p) {
+*out = pix_fmts_all;
+*out_num = FF_ARRAY_ELEMS(pix_fmts_all) - 1;
+return 0;
+}
+#endif
+
+#if CONFIG_LIBX264RGB_ENCODER
+if (codec == &ff

Re: [FFmpeg-devel] [PATCH v3 3/3] avcodec/hevc: Add alpha layer support

2025-02-05 Thread Zhao Zhili


> On Feb 5, 2025, at 23:33, James Almer  wrote:
> 
> On 2/5/2025 12:10 PM, Zhao Zhili wrote:
>> From: Zhao Zhili 
>> Signed-off-by: Zhao Zhili 
>> ---
>>  libavcodec/hevc/hevcdec.c | 72 ++-
>>  libavcodec/hevc/hevcdec.h |  2 ++
>>  libavcodec/hevc/refs.c| 11 +-
>>  3 files changed, 83 insertions(+), 2 deletions(-)
> 
> I tried with https://0x0.st/X7Vx.mov and https://0x0.st/8KCA.mp4, and neither 
> seem to output the alpha plane.

The first sample is a early release from apple, with error in vps extension.

I don’t know where the second sample comes from, it’s blank when playback with 
QuickTime Player. The bitstream has a lot of error.

Here is a sample encoded with videotoolbox

./ffmpeg -i bunny.mp4 -i basketball.mp4 \
-filter_complex '[1:v][0:v]alphamerge,format=bgra[vout]’ -\
c:v hevc_videotoolbox -pix_fmt bgra -alpha_quality 0.5 \
-t 10 -map '[vout]' -tag:v hvc1 alpha.mp4 

https://drive.google.com/file/d/1SK6gnMNlWODeTySpetNAKgNeqt69DQDz/view?usp=drive_link

> 
> ___
> 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 2/3] avcodec/libx264: Set FFCodec.pix_fmts field and fix deprecation warning

2025-02-05 Thread Andreas Rheinhardt
Zhao Zhili:
> From: Zhao Zhili 
> 
> We can fix deprecation warning by not set p.pix_fmts, and copy
> FFCodec.pix_fmts to FFCodec.p.pix_fmts in av_codec_init_static().
> However, that method requires non-const FFCodec. So I decided to
> set pix_fmts and p.pix_fmts both, and disable deprecation warning
> explicitly.
> ---
>  libavcodec/libx264.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 409f45fc7d..9b8b32ef4e 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -1633,7 +1633,10 @@ const FFCodec ff_libx264_encoder = {
>  .flush= X264_flush,
>  .close= X264_close,
>  .defaults = x264_defaults,
> +.pix_fmts = pix_fmts_all,
> +FF_DISABLE_DEPRECATION_WARNINGS
>  .p.pix_fmts   = pix_fmts_all,
> +FF_ENABLE_DEPRECATION_WARNINGS
>  .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
>  .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
>  #if X264_BUILD < 158
> @@ -1659,7 +1662,10 @@ const FFCodec ff_libx264rgb_encoder = {
>  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>AV_CODEC_CAP_OTHER_THREADS |
>AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> +.pix_fmts   = pix_fmts_8bit_rgb,
> +FF_DISABLE_DEPRECATION_WARNINGS
>  .p.pix_fmts = pix_fmts_8bit_rgb,
> +FF_ENABLE_DEPRECATION_WARNINGS
>  .p.priv_class   = &rgbclass,
>  .p.wrapper_name = "libx264",
>  .priv_data_size = sizeof(X264Context),
> @@ -1691,7 +1697,10 @@ const FFCodec ff_libx262_encoder = {
>  .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>  AV_CODEC_CAP_OTHER_THREADS |
>  AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> +.pix_fmts = pix_fmts_8bit,
> +FF_DISABLE_DEPRECATION_WARNINGS
>  .p.pix_fmts   = pix_fmts_8bit,
> +FF_ENABLE_DEPRECATION_WARNINGS
>  .color_ranges = AVCOL_RANGE_MPEG,
>  .p.priv_class = &X262_class,
>  .p.wrapper_name   = "libx264",

Only Clang emits these deprecation warnings; and IIRC GCC does not
support disabling deprecation warnings inside a definition like this
(compilation failure). The deprecation warnings can instead be fixed
like in fdff1b9cbfd8cf5a9810c29efa4baf13a4786742.

- Andreas

___
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 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data

2025-02-05 Thread Michael Niedermayer
On Mon, Feb 03, 2025 at 07:35:46PM -0300, James Almer wrote:
> Signed-off-by: James Almer 
> ---
>  libavcodec/hevc/hevcdec.c | 55 ++-
>  1 file changed, 54 insertions(+), 1 deletion(-)

seems to fail to build
libavcodec/hevc/hevcdec.c: In function ‘hevc_sei_to_context’:
libavcodec/hevc/hevcdec.c:4060:15: error: too few arguments to function 
‘ff_frame_new_side_data_from_buf_ext’
 4060 | ret = ff_frame_new_side_data_from_buf_ext(avctx, 
&avctx->decoded_side_data, &avctx->nb_decoded_side_data,
  |   ^~~

[...]

thx

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
than the original author, trying to rewrite it will not make it better.


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 v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data

2025-02-05 Thread James Almer

On 2/5/2025 6:07 PM, Michael Niedermayer wrote:

On Mon, Feb 03, 2025 at 07:35:46PM -0300, James Almer wrote:

Signed-off-by: James Almer 
---
  libavcodec/hevc/hevcdec.c | 55 ++-
  1 file changed, 54 insertions(+), 1 deletion(-)


seems to fail to build
libavcodec/hevc/hevcdec.c: In function ‘hevc_sei_to_context’:
libavcodec/hevc/hevcdec.c:4060:15: error: too few arguments to function 
‘ff_frame_new_side_data_from_buf_ext’
  4060 | ret = ff_frame_new_side_data_from_buf_ext(avctx, 
&avctx->decoded_side_data, &avctx->nb_decoded_side_data,
   |   ^~~


Do you happen to have 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20250204211256.10228-1-jamr...@gmail.com/ 
also in your tree? That's a separate patchset and currently incompatible 
with this one.




OpenPGP_signature.asc
Description: OpenPGP digital 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".


[FFmpeg-devel] [PATCH 1/3] avcodec/codec_internal: Add pix_fmts and supported_framerates fields to FFCodec

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

These fields in AVCodec are deprecated. For most codecs, it's
cumbersome to implement get_supported_config only to export pix_fmts.
---
 libavcodec/avcodec.c| 6 ++
 libavcodec/codec_internal.h | 9 +
 2 files changed, 15 insertions(+)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index e7e2c09222..f41d66d04f 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -765,11 +765,17 @@ int ff_default_get_supported_config(const AVCodecContext 
*avctx,
 const void **out_configs,
 int *out_num_configs)
 {
+const FFCodec *codec2 = ffcodec(codec);
+
 switch (config) {
 FF_DISABLE_DEPRECATION_WARNINGS
 case AV_CODEC_CONFIG_PIX_FORMAT:
+if (codec2->pix_fmts)
+WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec2->pix_fmts, enum 
AVPixelFormat, AV_PIX_FMT_NONE);
 WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts, enum AVPixelFormat, 
AV_PIX_FMT_NONE);
 case AV_CODEC_CONFIG_FRAME_RATE:
+if (codec2->supported_framerates)
+WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec2->supported_framerates, 
AVRational, {0});
 WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates, 
AVRational, {0});
 case AV_CODEC_CONFIG_SAMPLE_RATE:
 WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->supported_samplerates, int, 0);
diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index 5b2db74590..a5ca72f2b6 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -274,6 +274,15 @@ typedef struct FFCodec {
 unsigned flags,
 const void **out_configs,
 int *out_num_configs);
+/**
+ * Supported pixel format
+ *
+ * Can be null. If get_supported_config is null and this field isn't
+ * null, it will be used by ff_default_get_supported_config.
+ */
+const enum AVPixelFormat *pix_fmts;
+
+const AVRational *supported_framerates;
 } FFCodec;
 
 /**
-- 
2.46.0

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

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


Re: [FFmpeg-devel] [PATCH 2/2] avformat/hls: .ts is always ok even if its a mov/mp4

2025-02-05 Thread Michael Niedermayer
Hi

On Wed, Feb 05, 2025 at 07:41:39PM +0100, Michael Niedermayer wrote:
> Hi Kacper
> 
> On Tue, Feb 04, 2025 at 12:45:14PM +0100, Kacper Michajlow wrote:
> [...]
> > security benefits. I get it. Someone needed to hit their KPI by
> > submitting CVEs, and they found a marginally applicable case of a
> > highly unrealistic attack scenario.
> 
> I think you mis judge the (un)realism of this attack
> 
> prior to the patches, i can give you a m3u8 file and it will store
> any local file in the output video
> 
> This is not even just a matter of video streaming services,
> With a bit of social engeneering you can likely get people to
> do that.
> "Hey i found this odd file that encodes to different gibberish
>  on each machien, iam an artist, doing an art project, can you
>  just quickly reencode this and send me the mkv it generates ?"
> 
> Who would think that above will effectively give the attacker full
> access to your machiene. unless you run this in a sandbox that has
> no access to sensitve files

Ive tried to write an exploit for this and luckily it is not
that simple.

We can use data:// to feed both data and extension to force a demuxer
of our choice to be used

We can use crypto: to encrypt the extracted data so the user has no clue
what is extracted

And we dont need to have any probe succeed on the file we read.
The tty_extensions check also is not helping as it is not run on the target

I can read any file but only if it has a extension on the allowed_extensions
list or allowed_extensions is set to ALL.
This makes this luckily indeed difficult to exploit, i failed to find a
way to bypass this. But there are several close ones
concatdec uses data:// if we open it that way
file:// is subject to teh allowed_extensions check
other things like references in other demuxers i have not tried

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact


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] avformat/unix: Set is_streamed to true

2025-02-05 Thread Leo Izen

On 2/6/25 2:00 AM, dank074 wrote:

Currently when a Unix Domain Socket is used as input there is a loss of data 
when data is consumed from the stream. Setting is_streamed to true fixes this, 
since the unix domain socket is now treated like a consumable stream.

Fixes: #9346
Signed-off-by: dank074 
---
  libavformat/unix.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/unix.c b/libavformat/unix.c
index 5704155cf0..2de4023835 100644
--- a/libavformat/unix.c
+++ b/libavformat/unix.c
@@ -89,7 +89,7 @@ static int unix_open(URLContext *h, const char *filename, int 
flags)
  }
  
  s->fd = fd;

-
+h->is_streamed = 1;
  return 0;
  
  fail:


The patch looks fine as-is but two style nitpicks:

- we like to have a full blank line between the return statement and the 
one before it, so you should add this line of code right after the line 
s->fd = fd; but not remove the blank line that was there
- commit messages should be capped at 72 characters per line for 
historical reasons, so please insert newline characters in the commit 
message


If there's no other objections I will push this patch and make both of 
these changes on my end, preserving authorship before I do, if that is 
okay with you.


- Leo Izen (Traneptora)

___
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] ffv1dec: fix threaded decode failures

2025-02-05 Thread Lynne

On 05/02/2025 17:26, Lynne wrote:

On 05/02/2025 15:51, James Almer wrote:

On 2/5/2025 11:47 AM, Lynne wrote:

Fixes 7187eadf8c0f0c640f1d23811c55fad0cba60aa5

The issue is that while avctx->pix_fmt is synchronized between
threads, f->pix_fmt was not.

Fixes fate-vsynth1-ffv1-2pass10 with THREADS=2.


Can confirm "make fate-vsynth{1,2,3,_lena} THREADS=2" (as well as 
higher thread count) passes with this patch.



---
  libavcodec/ffv1dec.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index fcf3d525ac..0284845503 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1114,6 +1114,7 @@ static int update_thread_context(AVCodecContext 
*dst, const AVCodecContext *src)

  fdst->plane_count = fsrc->plane_count;
  fdst->ac  = fsrc->ac;
  fdst->colorspace  = fsrc->colorspace;
+    fdst->pix_fmt = fsrc->pix_fmt;
  fdst->ec  = fsrc->ec;
  fdst->intra   = fsrc->intra;



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


Thanks.
I'll push this soon unless there are objections.

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


Pushed, thanks.


OpenPGP_0xA2FEA5F03F034464.asc
Description: OpenPGP public key


OpenPGP_signature.asc
Description: OpenPGP digital 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".


[FFmpeg-devel] [PATCH] avformat/unix: Set is_streamed to true

2025-02-05 Thread dank074
Currently when a Unix Domain Socket is used as input there is a loss of data 
when data is consumed from the stream. Setting is_streamed to true fixes this, 
since the unix domain socket is now treated like a consumable stream.

Fixes: #9346
Signed-off-by: dank074 
---
 libavformat/unix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/unix.c b/libavformat/unix.c
index 5704155cf0..2de4023835 100644
--- a/libavformat/unix.c
+++ b/libavformat/unix.c
@@ -89,7 +89,7 @@ static int unix_open(URLContext *h, const char *filename, int 
flags)
 }
 
 s->fd = fd;
-
+h->is_streamed = 1;
 return 0;
 
 fail:
-- 
2.45.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] [PATCH v2 1/2] x86: aacencdsp: Fix negating signed values in aac_quantize_bands

2025-02-05 Thread Martin Storsjö
Previously, we would do OR with the sign bit, forcing the output
to a negative value, while we want to negate it, by inverting the
sign bit.
---
 libavcodec/x86/aacencdsp.asm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/x86/aacencdsp.asm b/libavcodec/x86/aacencdsp.asm
index 86eaebcbe5..8e435b7d2a 100644
--- a/libavcodec/x86/aacencdsp.asm
+++ b/libavcodec/x86/aacencdsp.asm
@@ -96,7 +96,7 @@ cglobal aac_quantize_bands, 5, 5, 6, out, in, scaled, size, 
is_signed, maxval, Q
 addps m2, m1
 minps m2, m3
 andps m5, m4, [inq+sizeq]
-orps  m2, m5
+xorps m2, m5
 cvttps2dq m2, m2
 mova  [outq+sizeq], m2
 add   sizeq, mmsize
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH v2 2/2] checkasm: aacencdsp: Actually test nonzero values in quant_bands

2025-02-05 Thread Martin Storsjö
Previously, we read elements from ff_aac_pow34sf_tab; however
that table is initialized to zero; one needs to call
ff_aac_float_common_init() to make sure that the table is
initialized.

However, given the range of the input values, a large number of
entries in ff_aac_pow34sf_tab would give results outside of the
range for signed 32 bit integers. As the largest aac_cb_maxval
entry is 16, it seems more reasonable to produce values within
an order of mangitude of that value.

(When hitting INT_MIN, implementations may end up with different
results depending on whether the value is negated as a float or
as an int. This corner case is irrelevant in practice as this
is way outside of the expected value range here.)

Coincidentally, this fixes linking checkasm with Apple's older
linker. (In Xcode 15, Apple switched to a new linker. The one in
older toolchains seems to have a bug where it won't figure out to
load object files from a static library, if the only symbol
referenced in the object file is a "common" symbol, i.e. one for
a zero-initialized variable. This issue can also be reproduced with
newer Apple toolchains by passing -Wl,-ld_classic to the linker.)
---
 tests/checkasm/aacencdsp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/checkasm/aacencdsp.c b/tests/checkasm/aacencdsp.c
index 5308a2ac03..713284211c 100644
--- a/tests/checkasm/aacencdsp.c
+++ b/tests/checkasm/aacencdsp.c
@@ -67,7 +67,7 @@ static void test_abs_pow34(AACEncDSPContext *s)
 static void test_quant_bands(AACEncDSPContext *s)
 {
 int maxval = randomize_elem(aac_cb_maxval);
-float q34 = randomize_elem(ff_aac_pow34sf_tab);
+float q34 = (float)rnd() / (UINT_MAX / 1024);
 float rounding = (rnd() & 1) ? ROUND_TO_ZERO : ROUND_STANDARD;
 LOCAL_ALIGNED_16(float, in, [BUF_SIZE]);
 LOCAL_ALIGNED_16(float, scaled, [BUF_SIZE]);
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH v3 2/3] avcodec/hevc/ps: Add basic HEVC_SCALABILITY_AUXILIARY support

2025-02-05 Thread James Almer

On 2/5/2025 12:10 PM, Zhao Zhili wrote:

-skip_bits1(gb); /* direct_depenency_all_layers_flag */
-direct_dep_type = get_bits_long(gb, direct_dep_type_len);
-if (direct_dep_type > HEVC_DEP_TYPE_BOTH) {
-av_log(avctx, AV_LOG_WARNING, "Unsupported direct_dep_type: %d\n",
-   direct_dep_type);
-return AVERROR_PATCHWELCOME;
+/* direct_depenency_all_layers_flag */
+if (get_bits1(gb)) {
+direct_dep_type = get_bits_long(gb, direct_dep_type_len);
+if (direct_dep_type > HEVC_DEP_TYPE_BOTH) {
+av_log(avctx, AV_LOG_WARNING, "Unsupported direct_dep_type: %d\n",
+   direct_dep_type);
+return AVERROR_PATCHWELCOME;
+}
  }


direct_dep_type is also coded if direct_depenency_all_layers_flag is 
false when (if I'm reading the spec right) vps->num_direct_ref_layers[1] 
is not 0.




OpenPGP_signature.asc
Description: OpenPGP digital 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 v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data

2025-02-05 Thread Michael Niedermayer
On Wed, Feb 05, 2025 at 06:16:35PM -0300, James Almer wrote:
> On 2/5/2025 6:07 PM, Michael Niedermayer wrote:
> > On Mon, Feb 03, 2025 at 07:35:46PM -0300, James Almer wrote:
> > > Signed-off-by: James Almer 
> > > ---
> > >   libavcodec/hevc/hevcdec.c | 55 ++-
> > >   1 file changed, 54 insertions(+), 1 deletion(-)
> > 
> > seems to fail to build
> > libavcodec/hevc/hevcdec.c: In function ‘hevc_sei_to_context’:
> > libavcodec/hevc/hevcdec.c:4060:15: error: too few arguments to function 
> > ‘ff_frame_new_side_data_from_buf_ext’
> >   4060 | ret = ff_frame_new_side_data_from_buf_ext(avctx, 
> > &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
> >|   ^~~
> 
> Do you happen to have 
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20250204211256.10228-1-jamr...@gmail.com/
> also in your tree? That's a separate patchset and currently incompatible
> with this one.

yes i had this locally too

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



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] checkasm: aacencdsp: Actually initialize ff_aac_pow34sf_tab

2025-02-05 Thread Martin Storsjö

On Sun, 2 Feb 2025, Michael Niedermayer wrote:


On Wed, Jan 29, 2025 at 11:58:54AM +0200, Martin Storsjö wrote:

This table is zero initialized by default, and has to be
explicitly initialized.

Coincidentally, this fixes linking checkasm with Apple's older
linker. (In Xcode 15, Apple switched to a new linker. The one in
older toolchains seems to have a bug where it won't figure out to
load object files from a static library, if the only symbol
referenced in the object file is a "common" symbol, i.e. one for
a zero-initialized variable. This issue can also be reproduced with
newer Apple toolchains by passing -Wl,-ld_classic to the linker.)
---
 tests/checkasm/aacencdsp.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)


this sometimes fails

make -j32 fate-checkasm-aacencdsp

TESTcheckasm-aacencdsp
make -j32 fate-checkasm-aacencdsp

TESTcheckasm-aacencdsp
Test checkasm-aacencdsp failed. Look at tests/data/fate/checkasm-aacencdsp.err 
for details.
make: *** [tests/Makefile:311: fate-checkasm-aacencdsp] Error 1

checkasm: using random seed 3314560428
SSE:
- aacencdsp.abs_pow34   [OK]
SSE2:
  quant_bands_signed_sse2 (aacencdsp.c:94)
- aacencdsp.quant_bands [FAILED]
AVX:
- aacencdsp.quant_bands [OK]
checkasm: 1 of 5 tests have failed
threads=1
make: *** [tests/Makefile:311: fate-checkasm-aacencdsp] Error 1


Indeed, it turns out that the existing x86 assembly is kinda buggy; I sent 
a new patchset now, which runs correctly in checkasm with at least a 
couple thousand different seeds, tested on x86, aarch64 and riscv (with 
qemu).


// Martin
___
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] Up to Date DeckLink Support broken in FFMPEG

2025-02-05 Thread ffmpeg
Hi Folks

It seems like the current decklink code in FFMPEG is no longer fully compatible 
with the latest Decklink drivers
The behaviour seen is that output via DeckLink starts OK but very quickly 
stalls. Apparently its related to the callbacks.
I believe this broken with BMD drivers 13.3 and later

Has anyone here already fixed the FFMPEG code to work again ?   

If no-one has attempted this fix, I will give it a go, but if someone is ahead 
of me please let me know

Thanks !!!

Mark.

___
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 v2 2/2] random_seed: Improve behaviour with small timer increments with high precision timers

2025-02-05 Thread Martin Storsjö
On a Zen 5, on Ubuntu 24.04 (with CLOCKS_PER_SEC 100), the
value of clock() in this loop increments by 0 most of the time,
and when it does increment, it usually increments by 1 compared
to the previous round.

Due to the "last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t"
expression, we only manage to take one step forward in this loop
(incrementing i) if clock() increments by 2, while it incremented
by 0 in the previous iteration (last_td).

This is similar to the change done in
c4152fc42e480c41efb7f761b1bbe5f0bc43d5bc, to speed it up on
systems with very small CLOCKS_PER_SEC. However in this case,
CLOCKS_PER_SEC is still very large, but the machine is fast enough
to hit every clock increment repeatedly.

For this case, use the number of repetitions of each timer value
as entropy source; require a change in the number of repetitions
in order to proceed to the next buffer index.

This helps the fate-random-seed test to actually terminate within
a reasonable time on such a system (where it previously could hang,
running for many minutes).
---
 libavutil/random_seed.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index ca084b40da..adb7b1f717 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -83,6 +83,7 @@ static uint32_t get_generic_seed(void)
 static uint32_t buffer[512] = { 0 };
 unsigned char digest[20];
 uint64_t last_i = i;
+int last_repeat = 0, cur_repeat = 0;
 
 av_assert0(sizeof(tmp) >= av_sha_size);
 
@@ -101,8 +102,21 @@ static uint32_t get_generic_seed(void)
 int incremented_i = 0;
 int cur_td = t - last_t;
 if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) < t) {
+// If the timer incremented by more than 2*last_td at once,
+// we may e.g. have had a context switch. If the timer resolution
+// is high (CLOCKS_PER_SEC > 1000), require that the timer
+// incremented by more than 1. If the timer resolution is low,
+// it is enough that the timer incremented at all.
 buffer[++i & 511] += cur_td % 3294638521U;
 incremented_i = 1;
+} else if (t != last_t && cur_repeat > 0 && last_repeat > 0 &&
+   cur_repeat != last_repeat) {
+// If the timer resolution is high, and we get the same timer
+// value multiple times, use variances in the number of repeats
+// of each timer value as entropy. If the number of repeats 
changed,
+// proceed to the next index.
+buffer[++i & 511] += (cur_repeat + last_repeat) % 3294638521U;
+incremented_i = 1;
 } else {
 buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (cur_td % 
3294638521U);
 }
@@ -110,6 +124,12 @@ static uint32_t get_generic_seed(void)
 if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - 
last_i > 8)
 break;
 }
+if (t == last_t) {
+cur_repeat++;
+} else {
+last_repeat = cur_repeat;
+cur_repeat = 0;
+}
 last_t = t;
 last_td = cur_td;
 if (!init_t)
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH v2 1/2] random_seed: Reorder if clauses for gathering entropy

2025-02-05 Thread Martin Storsjö
Make it easier to add more cases.

This should be a pure refactoring, with no functional changes.
---
 libavutil/random_seed.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 8a4e4f1fc0..ca084b40da 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -98,17 +98,20 @@ static uint32_t get_generic_seed(void)
 
 for (;;) {
 clock_t t = clock();
-if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t) {
-last_td = t - last_t;
-buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (last_td 
% 3294638521U);
+int incremented_i = 0;
+int cur_td = t - last_t;
+if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) < t) {
+buffer[++i & 511] += cur_td % 3294638521U;
+incremented_i = 1;
 } else {
-last_td = t - last_t;
-buffer[++i & 511] += last_td % 3294638521U;
-if ((t - init_t) >= CLOCKS_PER_SEC>>5)
-if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - 
last_i > 8)
-break;
+buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (cur_td % 
3294638521U);
+}
+if (incremented_i && (t - init_t) >= CLOCKS_PER_SEC>>5) {
+if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - 
last_i > 8)
+break;
 }
 last_t = t;
+last_td = cur_td;
 if (!init_t)
 init_t = t;
 }
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH] random_seed: Limit the time taken by get_generic_seed

2025-02-05 Thread Martin Storsjö

On Fri, 31 Jan 2025, Michael Niedermayer wrote:


diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 8a4e4f1fc0..8f969060a0 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -83,6 +83,7 @@ static uint32_t get_generic_seed(void)
 static uint32_t buffer[512] = { 0 };
 unsigned char digest[20];
 uint64_t last_i = i;
+int cur_iters = 0;

 av_assert0(sizeof(tmp) >= av_sha_size);

@@ -98,11 +99,13 @@ static uint32_t get_generic_seed(void)

 for (;;) {
 clock_t t = clock();
-if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t) {
+if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t && cur_iters < 
128) {
 last_td = t - last_t;
 buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (last_td 
% 3294638521U);
+cur_iters++;
 } else {
 last_td = t - last_t;
+cur_iters = 0;


Iam concerned this could negatively impact entropy
The "else" should be run when a interrupt/task switch occured.
If that doesnt occur in 128 iterations that doesnt gurantee the entropy
has increased.

If there are only 0 and 1, ideally we should look at the distribution and
go to the else when the pattern differs from the past / has some signs of
randomness


Ok, I've somewhat tried to implement this, please take a look.

// Martin

___
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] lavf/mxfenc: Make write_desc return int

2025-02-05 Thread Tomas Härdin
tis 2024-11-12 klockan 18:49 +0100 skrev Tomas Härdin:
> fre 2024-11-08 klockan 11:29 +0100 skrev Tomas Härdin:
> > Passes fate-mxf
> 
> Will push in a day or two

.. or a month or two. Tested and pushed.

/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 v3 3/3] avcodec/hevc: Add alpha layer support

2025-02-05 Thread James Almer

On 2/5/2025 12:10 PM, Zhao Zhili wrote:

From: Zhao Zhili 

Signed-off-by: Zhao Zhili 
---
  libavcodec/hevc/hevcdec.c | 72 ++-
  libavcodec/hevc/hevcdec.h |  2 ++
  libavcodec/hevc/refs.c| 11 +-
  3 files changed, 83 insertions(+), 2 deletions(-)


I tried with https://0x0.st/X7Vx.mov and https://0x0.st/8KCA.mp4, and 
neither seem to output the alpha plane.




OpenPGP_signature.asc
Description: OpenPGP digital 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] ffv1dec: fix threaded decode failures

2025-02-05 Thread Lynne

On 05/02/2025 15:51, James Almer wrote:

On 2/5/2025 11:47 AM, Lynne wrote:

Fixes 7187eadf8c0f0c640f1d23811c55fad0cba60aa5

The issue is that while avctx->pix_fmt is synchronized between
threads, f->pix_fmt was not.

Fixes fate-vsynth1-ffv1-2pass10 with THREADS=2.


Can confirm "make fate-vsynth{1,2,3,_lena} THREADS=2" (as well as higher 
thread count) passes with this patch.



---
  libavcodec/ffv1dec.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index fcf3d525ac..0284845503 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1114,6 +1114,7 @@ static int update_thread_context(AVCodecContext 
*dst, const AVCodecContext *src)

  fdst->plane_count = fsrc->plane_count;
  fdst->ac  = fsrc->ac;
  fdst->colorspace  = fsrc->colorspace;
+    fdst->pix_fmt = fsrc->pix_fmt;
  fdst->ec  = fsrc->ec;
  fdst->intra   = fsrc->intra;



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


Thanks.
I'll push this soon unless there are objections.


OpenPGP_0xA2FEA5F03F034464.asc
Description: OpenPGP public key


OpenPGP_signature.asc
Description: OpenPGP digital 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 2/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors

2025-02-05 Thread Marth64
I know `if ((ret = av_do_something()) <0)` pattern has been frowned
upon recently but besides that it LGTM.
___
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/3] avcodec/osq: avoid undefined negation

2025-02-05 Thread Michael Niedermayer
On Tue, Feb 04, 2025 at 12:16:59AM -0300, James Almer wrote:
> On 2/3/2025 11:58 PM, Michael Niedermayer wrote:
> > Fixes: negation of -2147483648 cannot be represented in type 'int32_t' (aka 
> > 'int'); cast to an unsigned type to negate this value to itself
> > Fixes: 
> > 390646659/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-5040277374435328
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >   libavcodec/osq.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/osq.c b/libavcodec/osq.c
> > index 83b4a9d618d..5c7826778dc 100644
> > --- a/libavcodec/osq.c
> > +++ b/libavcodec/osq.c
> > @@ -190,7 +190,7 @@ static uint32_t get_urice(GetBitContext *gb, int k)
> >   static int32_t get_srice(GetBitContext *gb, int x)
> >   {
> > -int32_t y = get_urice(gb, x);
> > +uint32_t y = get_urice(gb, x);
> >   return get_bits1(gb) ? -y : y;
> 
> Does -y here work as intended now that y is unsigned?

why would it not ?

subtraction is the same operation for signed (twos complement) and unsigned

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle


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] Up to Date DeckLink Support broken in FFMPEG

2025-02-05 Thread Marth64
+ 1 to Leo
I have this card installed and active and can help validate.
___
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] ffv1dec: fix threaded decode failures

2025-02-05 Thread James Almer

On 2/5/2025 11:47 AM, Lynne wrote:

Fixes 7187eadf8c0f0c640f1d23811c55fad0cba60aa5

The issue is that while avctx->pix_fmt is synchronized between
threads, f->pix_fmt was not.

Fixes fate-vsynth1-ffv1-2pass10 with THREADS=2.


Can confirm "make fate-vsynth{1,2,3,_lena} THREADS=2" (as well as higher 
thread count) passes with this patch.



---
  libavcodec/ffv1dec.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index fcf3d525ac..0284845503 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1114,6 +1114,7 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
  fdst->plane_count = fsrc->plane_count;
  fdst->ac  = fsrc->ac;
  fdst->colorspace  = fsrc->colorspace;
+fdst->pix_fmt = fsrc->pix_fmt;
  
  fdst->ec  = fsrc->ec;

  fdst->intra   = fsrc->intra;




OpenPGP_signature.asc
Description: OpenPGP digital 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 2/2] avformat/hls: .ts is always ok even if its a mov/mp4

2025-02-05 Thread Michael Niedermayer
Hi Traneptora

On Tue, Feb 04, 2025 at 06:35:07PM -0500, Leo Izen wrote:
> 
> 
> On 1/28/25 4:44 PM, Michael Niedermayer wrote:
> > Hi
> > 
> > On Tue, Jan 28, 2025 at 10:12:30PM +0200, Jan Ekström wrote:
> > > On Tue, Jan 28, 2025 at 4:24 PM Michael Niedermayer
> > >  wrote:
> > > > 
> > > > Maybe fixes: 11435
> > > > 
> > > 
> > > Do I understand correctly that the root issue that's being attempted
> > > to be fixed by the initial patch set is that unusual demuxers were
> > > possible to have been probed and opened through the HLS meta demuxer?
> > > In that case I would say that instead of trying to make very nebulous
> > > and easily breakable extension based checking, maybe this demuxer
> > > should just limit its default usable input formats?
> > > 
> > > To my knowledge the officially utilized container formats for HLS are
> > > MPEG-TS, MP4-likes (fragmented mp4) and raw audio formats such as AAC,
> > > MP3 or AC-3. One could check what hls.js or ExoPlayer support, and
> > > that should be a generally mostly encompassing thing that does not
> > > depend on what extensions are in use. Adding an AVOption to add
> > > additional formats without code changes would then allow for some
> > > outliers to be added by users.
> > 
> > there is extended M3U
> > https://en.wikipedia.org/wiki/M3U
> > 
> > that allows a wide range of things in it
> > 
> > our hls demuxer can read these, if we limit to mpeg-ts/mp4 we would remove
> > support for these.
> > 
> 
> From reading this, it seems like we're using the same demuxer for both HLS
> streams (specified informationally in RFC 8216) as well as for generic m3u
> playlists, and changes to the HLS implementation for security reasons also
> change the M3U demuxer.
> 

> Why don't we just separate this into two different demuxers/protocols?

yes, i was thinking the same, we should do this for git master

thx


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



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] [PATCHv2] avcodec/leaddec: support format 0x1006

2025-02-05 Thread Peter Ross
On Sun, Jan 19, 2025 at 08:49:50PM +1100, Peter Ross wrote:
> Fixes ticket #10658.
> ---
> 
> Tested with some different vertical resolution alignments.
> 
> When the vertical resolution is not aligned to macroblock height, the
> reference encoder & decoder performs buggy placement of the initial
> field. Its an internal bug, but because the encoder and decoder are
> aligned, end-user does not see it.
> 
> FFmpeg decoder does not reproduce this behaviour.

will apply soon

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
___
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] Up to Date DeckLink Support broken in FFMPEG

2025-02-05 Thread Leo Izen

On 2/5/25 4:44 PM, ffm...@gallery.co.uk wrote:

Hi Folks

It seems like the current decklink code in FFMPEG is no longer fully compatible 
with the latest Decklink drivers
The behaviour seen is that output via DeckLink starts OK but very quickly 
stalls. Apparently its related to the callbacks.
I believe this broken with BMD drivers 13.3 and later

Has anyone here already fixed the FFMPEG code to work again ?

If no-one has attempted this fix, I will give it a go, but if someone is ahead 
of me please let me know

Thanks !!!

Mark.



Feel free to take a look. The last change to the decklink code in FFmpeg 
was authored last april (not counting minor one-line bugfixes and the 
like) and as far as I am aware nobody is currently working on that so 
you wouldn't be redoing someone else's work.


- Leo Izen (Traneptora)

___
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/8] libavformat/flacdec: Export samples md5 as metadata

2025-02-05 Thread Tomas Härdin

From e1c4dfa4cc7a574f6fac76c11591547d3cd90ad2 Mon Sep 17 00:00:00 2001
From: Mattias Wadman 
Date: Mon, 11 Oct 2021 15:38:13 +0200
Subject: [PATCH 3/8] libavformat/flacdec: Export samples md5 as metadata

Will be used by mal to compare metadat md5 with decoded samples md5.

Part of fixing https://jira.spotify.net/browse/GOL-681
---
 libavformat/flacdec.c | 6 ++
 tests/ref/fate/cover-art-aiff-id3v2-remux | 5 +++--
 tests/ref/fate/cover-art-flac-remux   | 1 +
 tests/ref/fate/id3v2-utf16-bom| 5 +++--
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 3c317acaee..9f65c25864 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -33,6 +33,7 @@
 #include "replaygain.h"
 
 #define SEEKPOINT_SIZE 18
+#define MD5_BYTE_SIZE 16
 
 typedef struct FLACDecContext {
 FFRawDemuxerContext rawctx;
@@ -109,6 +110,7 @@ static int flac_read_header(AVFormatContext *s)
 if (metadata_type == FLAC_METADATA_TYPE_STREAMINFO) {
 uint32_t samplerate;
 uint64_t samples;
+char md5hex[MD5_BYTE_SIZE*2+1]; // hex representation plus null terminator
 
 /* STREAMINFO can only occur once */
 if (found_streaminfo) {
@@ -133,6 +135,10 @@ static int flac_read_header(AVFormatContext *s)
 if (samples > 0)
 st->duration = samples;
 }
+
+ff_data_to_hex(md5hex, st->codecpar->extradata+18, MD5_BYTE_SIZE, 1 /* lowercase */);
+md5hex[sizeof(md5hex)-1] = '\0';
+av_dict_set(&s->metadata, "samples_md5", md5hex, 0);
 } else if (metadata_type == FLAC_METADATA_TYPE_CUESHEET) {
 uint8_t isrc[13];
 uint64_t start;
diff --git a/tests/ref/fate/cover-art-aiff-id3v2-remux b/tests/ref/fate/cover-art-aiff-id3v2-remux
index a59ba37c65..57c5a9f387 100644
--- a/tests/ref/fate/cover-art-aiff-id3v2-remux
+++ b/tests/ref/fate/cover-art-aiff-id3v2-remux
@@ -1,5 +1,5 @@
-330ad2bf538e91a31752b38024461df1 *tests/data/fate/cover-art-aiff-id3v2-remux.aiff
-608914 tests/data/fate/cover-art-aiff-id3v2-remux.aiff
+d8caddad3af3879f5957f71adcaedd23 *tests/data/fate/cover-art-aiff-id3v2-remux.aiff
+608970 tests/data/fate/cover-art-aiff-id3v2-remux.aiff
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: pcm_s16be
@@ -68,6 +68,7 @@ TAG:comment=Composer
 [/STREAM]
 [FORMAT]
 TAG:artist=Мельница
+TAG:samples_md5=03462731b2dba8e6a9da639b07054121
 TAG:RATING=0
 TAG:album=Ангелофрения
 TAG:title=Дороги
diff --git a/tests/ref/fate/cover-art-flac-remux b/tests/ref/fate/cover-art-flac-remux
index fa91975881..109bf7395e 100644
--- a/tests/ref/fate/cover-art-flac-remux
+++ b/tests/ref/fate/cover-art-flac-remux
@@ -90,6 +90,7 @@ TAG:comment=Publisher/Studio logotype
 TAG:title=White King Granulated Soap
 [/STREAM]
 [FORMAT]
+TAG:samples_md5=496206705f222f9a63bf23dc874d9d71
 TAG:major_brand=M4A 
 TAG:minor_version=0
 TAG:compatible_brands=M4A mp42isom
diff --git a/tests/ref/fate/id3v2-utf16-bom b/tests/ref/fate/id3v2-utf16-bom
index dd2566de2b..a1adb4730d 100644
--- a/tests/ref/fate/id3v2-utf16-bom
+++ b/tests/ref/fate/id3v2-utf16-bom
@@ -1,5 +1,5 @@
-9b8bfdf87a8d3d089819ef9f6f264ec4 *tests/data/fate/id3v2-utf16-bom.aiff
-885482 tests/data/fate/id3v2-utf16-bom.aiff
+b712d97d4ab0cfd77d79235c312c438a *tests/data/fate/id3v2-utf16-bom.aiff
+885538 tests/data/fate/id3v2-utf16-bom.aiff
 #tb 0: 1/9
 #media_type 0: video
 #codec_id 0: mjpeg
@@ -31,6 +31,7 @@ TAG:comment=Other
 [/STREAM]
 [FORMAT]
 TAG:artist=Мельница
+TAG:samples_md5=03462731b2dba8e6a9da639b07054121
 TAG:RATING=0
 TAG:album=Ангелофрения
 TAG:title=Дороги
-- 
2.39.5

___
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/8] rtmp: Set correct message stream id when writing as server

2025-02-05 Thread Tomas Härdin
This one is difficult to test. Any ideas?

/Tomas
From c8689abcbf9bf85e1f7775a347b6bc994679cb77 Mon Sep 17 00:00:00 2001
From: Jonathan Murray 
Date: Thu, 31 Mar 2022 16:23:17 +0200
Subject: [PATCH 5/8] rtmp: Set correct message stream id when writing as
 server

rtmp_write is used both for writing outputs as a server. The
rt->listen flag determines which mode we're running in.

Previously, when running as a server, the message stream id would
always be set to 0 for media/metadata messages. This is surprising
given that we have both responded to "createStream()" with a value
of 1 and sent a "Stream Begin 1" to the client. Furthermore, some
client libraries (Red5) seem to trip up on receiving
"@setDataFrame" on stream 0 (and may be correct to assume that
this message would be sent on stream 1).
---
 libavformat/rtmpproto.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 4095ae9421..846376e668 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -3049,7 +3049,12 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
  pkttype, ts, pktsize)) < 0)
 return ret;
 
-rt->out_pkt.extra = rt->stream_id;
+// If rt->listen, then we're running as a a server and should
+// use the ID that we've sent in Stream Begin and in the
+// _result to createStream.
+// Otherwise, we're running as a client and should use the ID
+// that we've received in the createStream from the server.
+rt->out_pkt.extra = (rt->listen) ? rt->nb_streamid : rt->stream_id;
 rt->flv_data = rt->out_pkt.data;
 }
 
-- 
2.39.5

___
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/8] avformat/flacdec: Return correct error-codes on read-failure

2025-02-05 Thread Tomas Härdin

From c81e350d5419cf02f029ce006d94f257bc18fb97 Mon Sep 17 00:00:00 2001
From: Ulrik 
Date: Thu, 26 Jan 2023 17:51:02 +0100
Subject: [PATCH 4/8] avformat/flacdec: Return correct error-codes on
 read-failure

Forward errors from `avio_read` directly. When `avio_read` sees EOF before
expected bytes can be read, consistently return `AVERROR_INVALIDDATA`

We used to return `AVERROR(AVERROR_INVALIDDATA)` when failing to read
metadata block headers. `AVERROR_INVALIDDATA` is already negative, so
wrapping in `AVERROR` leads to double-negation.

We used to return `AVERROR(EIO)` when failing to read extended metadata.
However, many times, the IO-layer is not at fault, the input data is simply
corrupted (truncated), so we return `AVERROR_INVALIDDATA` here as well.

---

Tomas: changed to use AVERROR_EOF
---
 libavformat/flacdec.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 9f65c25864..77dcc620a4 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -81,8 +81,13 @@ static int flac_read_header(AVFormatContext *s)
 
 /* process metadata blocks */
 while (!avio_feof(s->pb) && !metadata_last) {
-if (avio_read(s->pb, header, 4) != 4)
-return AVERROR_INVALIDDATA;
+ret = avio_read(s->pb, header, 4);
+if (ret < 0) {
+return ret;
+} else if (ret != 4) {
+return AVERROR_EOF;
+}
+
 flac_parse_block_header(header, &metadata_last, &metadata_type,
&metadata_size);
 switch (metadata_type) {
@@ -96,8 +101,11 @@ static int flac_read_header(AVFormatContext *s)
 if (!buffer) {
 return AVERROR(ENOMEM);
 }
-if (avio_read(s->pb, buffer, metadata_size) != metadata_size) {
-RETURN_ERROR(AVERROR(EIO));
+ret = avio_read(s->pb, buffer, metadata_size);
+if (ret < 0) {
+RETURN_ERROR(ret);
+} else if (ret != metadata_size) {
+RETURN_ERROR(AVERROR_EOF);
 }
 break;
 /* skip metadata block for unsupported types */
-- 
2.39.5

___
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/8] avformat/http: Return EIO for prematurely broken connection

2025-02-05 Thread Tomas Härdin
Rebased and trimmed down Spotify patchset. Does not include the mfra or
ID3v2 stuff since those are turning out to be bigger tasks

/Tomas
From c808ca473529ca952c42f00d12aa50ade38850d8 Mon Sep 17 00:00:00 2001
From: Ulrik 
Date: Mon, 27 Jul 2020 11:46:56 +0200
Subject: [PATCH 1/8] avformat/http: Return EIO for prematurely broken
 connection

Currently, a prematurely broken connection normally leads to the same
EOF, as a completed successful transfer. However, enabling reconnect
changes this logic, and leads to the return of EIO.

This patch unifies that logic, leading to the return of EIO for premature
disconnect, regardless of setting of "reconnect".
---
 libavformat/http.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index ec60bc0b17..65ea5d993c 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "config.h"
 #include "config_components.h"
 
@@ -1747,6 +1749,7 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
 read_ret = http_buf_read(h, buf, size);
 while (read_ret < 0) {
 uint64_t target = h->is_streamed ? 0 : s->off;
+bool is_premature = s->filesize > 0 && s->off < s->filesize;
 
 if (read_ret == AVERROR_EXIT)
 break;
@@ -1754,9 +1757,13 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
 if (h->is_streamed && !s->reconnect_streamed)
 break;
 
-if (!(s->reconnect && s->filesize > 0 && s->off < s->filesize) &&
-!(s->reconnect_at_eof && read_ret == AVERROR_EOF))
-break;
+if (!(s->reconnect && is_premature) &&
+!(s->reconnect_at_eof && read_ret == AVERROR_EOF)) {
+if (is_premature)
+return AVERROR(EIO);
+else
+break;
+}
 
 if (reconnect_delay > s->reconnect_delay_max || (s->reconnect_max_retries >= 0 && conn_attempts > s->reconnect_max_retries) ||
 reconnect_delay_total > s->reconnect_delay_total_max)
-- 
2.39.5

___
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/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors

2025-02-05 Thread Tomas Härdin

From 18a64198487582e9ef3246e7490d919ee19af595 Mon Sep 17 00:00:00 2001
From: Jonathan Murray 
Date: Wed, 9 Jun 2021 12:00:24 +0200
Subject: [PATCH 2/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding
 errors

WMA files that fail to decode due to incoherent block lengths and
frame lengths currently result in a "Operation not permitted".
After this change, they will instead result in "Invalid data found
when processing input".

Several other error cases are also changed from returning -1.

As we change the error propagation logic in wma_decode_frame and
wma_decode_superframe, previous occurrences of returning
AVERROR_INVALIDDATA are also affected by this. This includes
"total_gain overread" and a "channel exponents_initialized" check.

---

Tomas: changed some -1's to AVERROR_INVALIDDATA
---
 libavcodec/wmadec.c | 40 
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 3427e482dc..c24fff5522 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -368,7 +368,7 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
 if ((unsigned) last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {
 av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
last_exp);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 v  = ptab[last_exp];
 iv = iptab[last_exp];
@@ -439,8 +439,10 @@ static void wma_window(WMACodecContext *s, float *out)
 }
 
 /**
- * @return 0 if OK. 1 if last block of frame. return -1 if
- * unrecoverable error.
+ * @return
+ * 0 if OK.
+ * 1 if last block of frame.
+ * AVERROR if unrecoverable error.
  */
 static int wma_decode_block(WMACodecContext *s)
 {
@@ -468,7 +470,7 @@ static int wma_decode_block(WMACodecContext *s)
 av_log(s->avctx, AV_LOG_ERROR,
"prev_block_len_bits %d out of range\n",
s->frame_len_bits - v);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 s->prev_block_len_bits = s->frame_len_bits - v;
 v  = get_bits(&s->gb, n);
@@ -476,7 +478,7 @@ static int wma_decode_block(WMACodecContext *s)
 av_log(s->avctx, AV_LOG_ERROR,
"block_len_bits %d out of range\n",
s->frame_len_bits - v);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 s->block_len_bits = s->frame_len_bits - v;
 } else {
@@ -489,7 +491,7 @@ static int wma_decode_block(WMACodecContext *s)
 av_log(s->avctx, AV_LOG_ERROR,
"next_block_len_bits %d out of range\n",
s->frame_len_bits - v);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 s->next_block_len_bits = s->frame_len_bits - v;
 } else {
@@ -501,14 +503,14 @@ static int wma_decode_block(WMACodecContext *s)
 
 if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){
 av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 /* now check if the block length is coherent with the frame length */
 s->block_len = 1 << s->block_len_bits;
 if ((s->block_pos + s->block_len) > s->frame_len) {
 av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 if (channels == 2)
@@ -590,7 +592,7 @@ static int wma_decode_block(WMACodecContext *s)
 if (s->channel_coded[ch]) {
 if (s->use_exp_vlc) {
 if (decode_exp_vlc(s, ch) < 0)
-return -1;
+return AVERROR_INVALIDDATA;
 } else {
 decode_exp_lsp(s, ch);
 }
@@ -802,7 +804,7 @@ static int wma_decode_frame(WMACodecContext *s, float **samples,
 for (;;) {
 ret = wma_decode_block(s);
 if (ret < 0)
-return -1;
+return ret;
 if (ret)
 break;
 }
@@ -879,8 +881,10 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
 return AVERROR_INVALIDDATA;
 
 if ((s->last_superframe_len + buf_size - 1) >
-MAX_CODED_SUPERFRAME_SIZE)
+MAX_CODED_SUPERFRAME_SIZE) {
+ret = AVERROR_INVALIDDATA;
 goto fail;
+}
 
 q   = s->last_superframe + s->last_superframe_len;
 len = buf_size - 1;
@@ -911,14 +915,17 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
 av_log(avctx, AV_LOG_ERROR,
"Invalid last frame bit offset %d > buf size %d (%d)\n",
bit_offset, get_bits_left(&s->gb), buf_size);
+ret 

[FFmpeg-devel] [PATCH 7/8] avformat/mp3dec: Subtract known padding from duration

2025-02-05 Thread Tomas Härdin

From 6dca5b958693588d74081e8fa29f05a5f257c841 Mon Sep 17 00:00:00 2001
From: Ulrik Mikaelsson 
Date: Tue, 22 Aug 2023 13:55:14 +0200
Subject: [PATCH 7/8] avformat/mp3dec: Subtract known padding from duration

When an Info-tag is present, marking initial and trailing samples as
padding, those samples should not be included in the calculation of track
duration.

This solves a surprising user experience where converting a WAV->MP3->WAV,
ffprobe will show the duration of the mp3 as slightly longer than both the
input and the output.

As a result, the estimated duration and imprecise seek-results of some
FATE-tests have been updated.
---
 libavformat/mp3dec.c | 20 ++--
 tests/ref/fate/gapless-mp3-side-data |  4 ++--
 tests/ref/seek/extra-mp3 |  8 
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index dac91205d9..31eeb68ebb 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -52,6 +52,7 @@ typedef struct {
 int usetoc;
 unsigned frames; /* Total number of frames in file */
 unsigned header_filesize;   /* Total number of bytes in the stream */
+unsigned frame_duration;   /* Frame duration in st->time_base */
 int is_cbr;
 } MP3DecContext;
 
@@ -341,6 +342,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
 
 mp3->frames = 0;
 mp3->header_filesize   = 0;
+mp3->frame_duration = av_rescale_q(spf, (AVRational){1, c.sample_rate}, st->time_base);
 
 mp3_parse_info_tag(s, st, &c, spf);
 mp3_parse_vbri_tag(s, st, base);
@@ -351,11 +353,18 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
 /* Skip the vbr tag frame */
 avio_seek(s->pb, base + vbrtag_size, SEEK_SET);
 
-if (mp3->frames)
-st->duration = av_rescale_q(mp3->frames, (AVRational){spf, c.sample_rate},
+if (mp3->frames) {
+int64_t full_duration_samples;
+
+full_duration_samples = mp3->frames * (int64_t)spf;
+st->duration = av_rescale_q(full_duration_samples - mp3->start_pad - mp3->end_pad,
+(AVRational){1, c.sample_rate},
 st->time_base);
-if (mp3->header_filesize && mp3->frames && !mp3->is_cbr)
-st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate, mp3->frames * (int64_t)spf);
+
+if (mp3->header_filesize && !mp3->is_cbr)
+st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate,
+full_duration_samples);
+}
 
 return 0;
 }
@@ -586,8 +595,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
 return best_pos;
 
 if (mp3->is_cbr && ie == &ie1 && mp3->frames && mp3->header_filesize > 0) {
-int frame_duration = av_rescale(st->duration, 1, mp3->frames);
-ie1.timestamp = frame_duration * av_rescale(best_pos - si->data_offset, mp3->frames, mp3->header_filesize);
+ie1.timestamp = mp3->frame_duration * av_rescale(best_pos - si->data_offset, mp3->frames, mp3->header_filesize);
 }
 
 avpriv_update_cur_dts(s, st, ie->timestamp);
diff --git a/tests/ref/fate/gapless-mp3-side-data b/tests/ref/fate/gapless-mp3-side-data
index 49ebc32dc8..878425f092 100644
--- a/tests/ref/fate/gapless-mp3-side-data
+++ b/tests/ref/fate/gapless-mp3-side-data
@@ -593,5 +593,5 @@ packet|codec_type=audio|stream_index=0|pts=217866240|pts_time=15.438367|dts=2178
 packet|codec_type=audio|stream_index=0|pts=218234880|pts_time=15.464490|dts=218234880|dts_time=15.464490|duration=368640|duration_time=0.026122|size=418|pos=248882|flags=K__|data_hash=CRC32:fbc83c3c
 packet|codec_type=audio|stream_index=0|pts=218603520|pts_time=15.490612|dts=218603520|dts_time=15.490612|duration=368640|duration_time=0.026122|size=418|pos=249300|flags=K__|data_hash=CRC32:d5fb5f9c|side_datum/skip_samples:side_data_type=Skip Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=303|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
 packet|codec_type=audio|stream_index=0|pts=218972160|pts_time=15.516735|dts=218972160|dts_time=15.516735|duration=368640|duration_time=0.026122|size=418|pos=249718|flags=K__|data_hash=CRC32:3789f3cf|side_datum/skip_samples:side_data_type=Skip Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=1152|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
-stream|index=0|codec_name=mp3|profile=unknown|codec_type=audio|codec_tag_string=[0][0][0][0]|codec_tag=0x|sample_fmt=fltp|sample_rate=44100|channels=2|channel_layout=stereo|bits_per_sample=0|initial_padding=0|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/14112000|start_pts=353600|start_time=0.025057|duration_ts=219340800|duration=15.542857|bit_rate=128000|max_bit_rate=N/A|bits_per_

[FFmpeg-devel] [PATCH 6/8] GOL-1361: Remove invalid CTTS sample_offset check

2025-02-05 Thread Tomas Härdin
I trust that ticket #385 has a FATE test these days

/Tomas
From 8c105c5953c494402749eb27d2eb6a7a2393f855 Mon Sep 17 00:00:00 2001
From: ekir 
Date: Tue, 18 Apr 2023 17:31:43 +0200
Subject: [PATCH 6/8] GOL-1361: Remove invalid CTTS sample_offset check

We checked in this places:
* In 8.6.1.3 of ISO/IEC 14496-12 about the CTTS box
* In Apples MOV spec: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP4939-CH204-SW19
---
 libavformat/mov.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2c8be51063..89bfb52d2e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3697,13 +3697,6 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",
 count, duration);
 
-if (FFNABS(duration) < -(1<<28) && i+2fc, AV_LOG_WARNING, "CTTS invalid\n");
-av_freep(&sc->ctts_data);
-sc->ctts_count = 0;
-return 0;
-}
-
 if (i+2fc);
 }
-- 
2.39.5

___
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 8/8] Make mime-type award a bonus probe score

2025-02-05 Thread Tomas Härdin
Seems reasonable to me and passes FATE

/Tomas
From ecc3459990f2871fd907f96fe66362b8fea41bd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20Zeb=C3=BChr?= 
Date: Tue, 21 Nov 2023 14:16:49 +0100
Subject: [PATCH 8/8] Make mime-type award a bonus probe score

This changes the default behaviour of ffmpeg where content-type headers
on an input gives an absolut probe score (of 75) to instead give a bonus
score (of 30). This gives the probe a better chance to arrive at the
correct format by (hopefully) giving a large enough bonus to push edge
cases in the right direction (MPEG-PS vs MP3, I am looking at you) while
also not adversly punishing clearer cases (raw ADTS marked as
"audio/mpeg" for example).

This patch was regression tested against 20 million recent podcast
submissions (after content-type propagation was added to
original-storage), and 50k Juno vodcasts submissions (dito). No adverse
effects observed (but the bonus may still need tweaking if other edge
cases are detected in production).
---
 libavformat/avformat.h   | 2 +-
 libavformat/format.c | 8 
 libavformat/libopenmpt.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6abdb6d480..498c557a3c 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -459,7 +459,7 @@ typedef struct AVProbeData {
 #define AVPROBE_SCORE_STREAM_RETRY (AVPROBE_SCORE_MAX/4-1)
 
 #define AVPROBE_SCORE_EXTENSION  50 ///< score for file extension
-#define AVPROBE_SCORE_MIME   75 ///< score for file mime type
+#define AVPROBE_SCORE_MIME_BONUS 30 ///< score added for matching mime type
 #define AVPROBE_SCORE_MAX   100 ///< maximum score
 
 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
diff --git a/libavformat/format.c b/libavformat/format.c
index e65a6fc05e..71018ea6ab 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -212,10 +212,10 @@ const AVInputFormat *av_probe_input_format3(const AVProbeData *pd,
 score = AVPROBE_SCORE_EXTENSION;
 }
 if (av_match_name(lpd.mime_type, fmt1->mime_type)) {
-if (AVPROBE_SCORE_MIME > score) {
-av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to %d due to MIME type\n", fmt1->name, score, AVPROBE_SCORE_MIME);
-score = AVPROBE_SCORE_MIME;
-}
+int old_score = score;
+score += AVPROBE_SCORE_MIME_BONUS;
+if (score > AVPROBE_SCORE_MAX) score = AVPROBE_SCORE_MAX;
+av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to %d due to MIME type\n", fmt1->name, old_score, score);
 }
 if (score > score_max) {
 score_max = score;
diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
index 736af7caf2..dee975c9c2 100644
--- a/libavformat/libopenmpt.c
+++ b/libavformat/libopenmpt.c
@@ -244,7 +244,7 @@ static int read_probe_openmpt(const AVProbeData *p)
  * AVPROBE_SCORE_MAX in order to reduce the impact in the rare
  * cases of false positives.
  */
-return AVPROBE_SCORE_MIME + 1;
+return (AVPROBE_SCORE_MAX * 3) / 4 + 1;
 } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) {
 if (probe_openmpt_extension(p) > 0) {
 return AVPROBE_SCORE_RETRY;
-- 
2.39.5

___
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] fate/libswresample: add a test downmixing with a custom order layout

2025-02-05 Thread James Almer
Signed-off-by: James Almer 
---
 tests/fate/libswresample.mak   | 8 
 tests/filtergraphs/custom_rematrix | 1 +
 2 files changed, 9 insertions(+)
 create mode 100644 tests/filtergraphs/custom_rematrix

diff --git a/tests/fate/libswresample.mak b/tests/fate/libswresample.mak
index a1e5ab91fa..aa4438a4bd 100644
--- a/tests/fate/libswresample.mak
+++ b/tests/fate/libswresample.mak
@@ -1097,5 +1097,13 @@ fate-swr-audioconvert: CMP = stddev
 fate-swr-audioconvert: FUZZ = 0
 
 FATE_SWR += $(FATE_SWR_AUDIOCONVERT-yes)
+
+FATE_SWR_CUSTOM_REMATRIX-$(call FILTERDEMDECENCMUX, ARESAMPLE CHANNELMAP 
AFORMAT, WAV, PCM_S16LE, PCM_S16LE, PCM_S16LE) += fate-swr-custom-rematrix
+fate-swr-custom-rematrix: tests/data/asynth-44100-8.wav 
tests/data/filtergraphs/custom_rematrix
+fate-swr-custom-rematrix: CMD = md5 -i 
$(TARGET_PATH)/tests/data/asynth-44100-8.wav -/filter_complex 
$(TARGET_PATH)/tests/data/filtergraphs/custom_rematrix -map [OUT] -f s16le
+fate-swr-custom-rematrix: CMP = oneline
+fate-swr-custom-rematrix: REF = 2a14a44deb4ae26e3b474ddbfbc048f8
+
+FATE_SWR += $(FATE_SWR_CUSTOM_REMATRIX-yes)
 FATE_FFMPEG += $(FATE_SWR)
 fate-swr: $(FATE_SWR)
diff --git a/tests/filtergraphs/custom_rematrix 
b/tests/filtergraphs/custom_rematrix
new file mode 100644
index 00..8579b43867
--- /dev/null
+++ b/tests/filtergraphs/custom_rematrix
@@ -0,0 +1 @@
+[0:a]aresample,channelmap=0|1|2|3|6|7|4|5:8 channels 
(FL+FR+FC+LFE+SL+SR+BL+BR),aresample,aformat=cl=stereo[OUT];
-- 
2.48.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 6/7] avformat: add s337m support in mpegts, wav and mxf stereo tracks

2025-02-05 Thread Tomas Härdin
ons 2024-12-04 klockan 15:14 +0100 skrev ffnicol...@sfr.fr:
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -634,7 +634,7 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, 
> AVStream *st, AVPacket *pkt,
>  for (; end_ptr - buf_ptr >= st->codecpar->ch_layout.nb_channels * 4; ) {
>  for (int i = 0; i < st->codecpar->ch_layout.nb_channels; i++) {
>  uint32_t sample = bytestream_get_le32(&buf_ptr);
> -    if (st->codecpar->bits_per_coded_sample == 24)
> +    if (av_get_bits_per_sample(st->codecpar->codec_id) == 24)
>  bytestream_put_le24(&data_ptr, (sample >> 4) & 0xff);
>  else
>  bytestream_put_le16(&data_ptr, (sample >> 12) & 0x);
> @@ -3080,7 +3080,12 @@ static int mxf_parse_structural_metadata(MXFContext 
> *mxf)
>  } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
>  sti->need_parsing = AVSTREAM_PARSE_FULL;
>  }
> -    st->codecpar->bits_per_coded_sample = 
> av_get_bits_per_sample(st->codecpar->codec_id);
> +    if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE
> + || st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) {
> +    FFStream *const sti = ffstream(st);
> +    sti->request_probe = AVPROBE_SCORE_EXTENSION;
> +    sti->need_parsing  = AVSTREAM_PARSE_FULL;
> +    }

Looks OK

Sorry for the late review

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


[FFmpeg-devel] [PATCH] ffv1dec: fix threaded decode failures

2025-02-05 Thread Lynne
Fixes 7187eadf8c0f0c640f1d23811c55fad0cba60aa5

The issue is that while avctx->pix_fmt is synchronized between
threads, f->pix_fmt was not.

Fixes fate-vsynth1-ffv1-2pass10 with THREADS=2.
---
 libavcodec/ffv1dec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index fcf3d525ac..0284845503 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1114,6 +1114,7 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 fdst->plane_count = fsrc->plane_count;
 fdst->ac  = fsrc->ac;
 fdst->colorspace  = fsrc->colorspace;
+fdst->pix_fmt = fsrc->pix_fmt;
 
 fdst->ec  = fsrc->ec;
 fdst->intra   = fsrc->intra;
-- 
2.47.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] avformat/mxfdec: Check edit unit for overflow in mxf_set_current_edit_unit()

2025-02-05 Thread Tomas Härdin
ons 2025-02-05 klockan 12:56 +0100 skrev Michael Niedermayer:
> Fixes: signed integer overflow: 9223372036854775807 + 1 cannot be
> represented in type 'long'
> Fixes: 392672068/clusterfuzz-testcase-minimized-
> ffmpeg_dem_MXF_fuzzer-6232335892152320
> 
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index 6bc8980d9c1..3b87063c3f2 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -3956,7 +3956,7 @@ static int64_t
> mxf_set_current_edit_unit(MXFContext *mxf, AVStream *st, int64_t
>  int64_t new_edit_unit;
>  MXFIndexTable *t = mxf_find_index_table(mxf, track->index_sid);
>  
> -    if (!t || track->wrapping == UnknownWrapped)
> +    if (!t || track->wrapping == UnknownWrapped || edit_unit >
> INT64_MAX - track->edit_units_per_packet)

Looks OK

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


[FFmpeg-devel] [PATCH v3 2/3] avcodec/hevc/ps: Add basic HEVC_SCALABILITY_AUXILIARY support

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

Only implementing what's needed for HEVC with alpha.

Signed-off-by: Zhao Zhili 
---
 libavcodec/hevc/hevc.h |   5 ++
 libavcodec/hevc/ps.c   | 126 +
 libavcodec/hevc/ps.h   |   4 ++
 3 files changed, 98 insertions(+), 37 deletions(-)

diff --git a/libavcodec/hevc/hevc.h b/libavcodec/hevc/hevc.h
index b2229fda40..710786a89d 100644
--- a/libavcodec/hevc/hevc.h
+++ b/libavcodec/hevc/hevc.h
@@ -170,4 +170,9 @@ enum HEVCScalabilityMask {
 HEVC_SCALABILITY_MASK_MAX   = 0x,
 };
 
+enum HEVCAuxId {
+HEVC_AUX_ALPHA = 1,
+HEVC_AUX_DEPTH = 2,
+};
+
 #endif /* AVCODEC_HEVC_HEVC_H */
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 861a6bb0a2..a77c697c08 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -460,14 +460,17 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
   uint64_t layer1_id_included)
 {
 PTL ptl_dummy;
-uint8_t max_sub_layers[HEVC_MAX_LAYERS];
+uint8_t max_sub_layers[HEVC_MAX_LAYERS] = {1, 1};
+uint8_t dimension_id_len[16] = {0};
+uint8_t dimension_id[16] = {0};
+unsigned n;
 
-int splitting_flag, dimension_id_len, view_id_len, num_add_olss, 
num_scalability_types,
+int splitting_flag, view_id_len, num_add_olss, num_scalability_types,
 default_output_layer_idc, direct_dep_type_len, direct_dep_type,
 sub_layers_max_present, sub_layer_flag_info_present_flag, nb_ptl;
 unsigned non_vui_extension_length;
 
-if (vps->vps_max_layers == 1 || vps->vps_num_layer_sets == 1) {
+if (vps->vps_max_layers == 1) {
 av_log(avctx, AV_LOG_VERBOSE, "Ignoring VPS extensions with a single 
layer\n");
 return 0;
 }
@@ -520,7 +523,8 @@ static int decode_vps_ext(GetBitContext *gb, AVCodecContext 
*avctx, HEVCVPS *vps
  */
 vps->nb_layers = 2;
 
-if (parse_ptl(gb, avctx, 0, &ptl_dummy, vps->vps_max_sub_layers) < 0)
+if (vps->vps_base_layer_internal_flag &&
+parse_ptl(gb, avctx, 0, &ptl_dummy, vps->vps_max_sub_layers) < 0)
 return AVERROR_INVALIDDATA;
 
 splitting_flag = get_bits1(gb);
@@ -529,20 +533,25 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 if (!num_scalability_types) {
 av_log(avctx, AV_LOG_ERROR, "Missing scalability mask\n");
 return AVERROR_INVALIDDATA;
-} else if (num_scalability_types > 1) {
-av_log(avctx, AV_LOG_ERROR, "Scalability number %d not supported\n",
-   num_scalability_types);
-return AVERROR_PATCHWELCOME;
 }
 
-if (!(vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)) {
+if (!(vps->scalability_mask_flag &
+  (HEVC_SCALABILITY_MULTIVIEW | HEVC_SCALABILITY_AUXILIARY))) {
 av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n",
15 - ff_ctz(vps->scalability_mask_flag));
 return AVERROR_PATCHWELCOME;
 }
+// x265 specify MULTIVIEW when the stream really is alpha video only.
+if (num_scalability_types > 1)
+av_log(avctx, AV_LOG_WARNING, "Multiple scalability types 
presented\n");
 
-if (!splitting_flag)
-dimension_id_len = get_bits(gb, 3) + 1;
+n = 0;
+for (int i = 0; i < num_scalability_types - splitting_flag; i++) {
+dimension_id_len[i] = get_bits(gb, 3) + 1;
+n += dimension_id_len[i];
+}
+if (splitting_flag)
+dimension_id_len[num_scalability_types - 1] = 5 - n;
 
 if (get_bits1(gb)) { /* vps_nuh_layer_id_present_flag */
 int layer_id_in_nuh = get_bits(gb, 6);
@@ -559,28 +568,57 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 }
 
 if (!splitting_flag) {
-int view_idx = get_bits(gb, dimension_id_len);
-if (view_idx != 1) {
-av_log(avctx, AV_LOG_ERROR, "Unexpected ViewOrderIdx: %d\n", 
view_idx);
+int index = 0;
+
+for (int i = 0; i < num_scalability_types; i++)
+dimension_id[i] = get_bits(gb, dimension_id_len[i]);
+
+if (vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)
+index++;
+
+/* AuxId 1 is alpha, 2 is depth. Only support alpha */
+if (vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY &&
+dimension_id[index] != HEVC_AUX_ALPHA) {
+av_log(avctx, AV_LOG_WARNING,
+   "Unsupported dimension_id %d for 
HEVC_SCALABILITY_AUXILIARY\n",
+   dimension_id[index]);
 return AVERROR_PATCHWELCOME;
 }
 }
 
 view_id_len = get_bits(gb, 4);
-if (view_id_len)
-for (int i = 0; i < 2 /* NumViews */; i++)
+if (view_id_len) {
+n = (vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW) ? 2 : 1;
+for (int i = 0; i < n; i++)
 vps->view_id[i] = get_bits(gb, view_id_len);
+}
 
-if (!get_bits1(gb) /* direct_dependency_flag */) {
-  

[FFmpeg-devel] [PATCH v3 3/3] avcodec/hevc: Add alpha layer support

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

Signed-off-by: Zhao Zhili 
---
 libavcodec/hevc/hevcdec.c | 72 ++-
 libavcodec/hevc/hevcdec.h |  2 ++
 libavcodec/hevc/refs.c| 11 +-
 3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e9c045f7a1..1cdc28de50 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -466,6 +466,24 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 return 0;
 }
 
+int ff_hevc_is_alpha_video(const HEVCContext *s) {
+const HEVCVPS *vps = s->vps;
+int ret = 0;
+
+if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
+return 0;
+
+/* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other
+ * than alpha cannot reach here.
+ */
+ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY);
+
+av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
+   ret ? "is" : "not");
+
+return ret;
+}
+
 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
 {
 unsigned layers_active_output = 0, highest_layer;
@@ -473,6 +491,18 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 s->layers_active_output = 1;
 s->layers_active_decode = 1;
 
+if (ff_hevc_is_alpha_video(s)) {
+const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(s->avctx->pix_fmt);
+
+if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
+return 0;
+
+s->layers_active_decode = (1 << vps->nb_layers) - 1;
+s->layers_active_output = 1;
+
+return 0;
+}
+
 // nothing requested - decode base layer only
 if (!s->nb_view_ids)
 return 0;
@@ -530,6 +560,34 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 return 0;
 }
 
+static enum AVPixelFormat map_to_alpha_format(HEVCContext *s,
+  enum AVPixelFormat pix_fmt)
+{
+switch (pix_fmt) {
+case AV_PIX_FMT_YUV420P:
+case AV_PIX_FMT_YUVJ420P:
+return AV_PIX_FMT_YUVA420P;
+case AV_PIX_FMT_YUV420P10:
+return AV_PIX_FMT_YUVA420P10;
+case AV_PIX_FMT_YUV444P:
+return AV_PIX_FMT_YUVA444P;
+case AV_PIX_FMT_YUV422P:
+return AV_PIX_FMT_YUVA422P;
+case AV_PIX_FMT_YUV422P10LE:
+return AV_PIX_FMT_YUVA422P10LE;
+case AV_PIX_FMT_YUV444P10:
+return AV_PIX_FMT_YUVA444P10;
+case AV_PIX_FMT_YUV444P12:
+return AV_PIX_FMT_YUVA444P12;
+case AV_PIX_FMT_YUV422P12:
+return AV_PIX_FMT_YUVA422P12;
+default:
+av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
+   av_get_pix_fmt_name(pix_fmt));
+return AV_PIX_FMT_NONE;
+}
+}
+
 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 {
 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
@@ -540,9 +598,13 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
  CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
  CONFIG_HEVC_VDPAU_HWACCEL + \
  CONFIG_HEVC_VULKAN_HWACCEL)
-enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
+enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
+enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
 int ret;
 
+if (ff_hevc_is_alpha_video(s))
+alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
+
 switch (sps->pix_fmt) {
 case AV_PIX_FMT_YUV420P:
 case AV_PIX_FMT_YUVJ420P:
@@ -664,6 +726,8 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
 break;
 }
 
+if (alpha_fmt != AV_PIX_FMT_NONE)
+*fmt++ = alpha_fmt;
 *fmt++ = sps->pix_fmt;
 *fmt = AV_PIX_FMT_NONE;
 
@@ -3194,6 +3258,12 @@ static int hevc_frame_start(HEVCContext *s, 
HEVCLayerContext *l,
 !sps->vui.common.video_signal_type_present_flag)
 pix_fmt = sps_base->pix_fmt;
 
+// Ignore range mismatch between base layer and alpha layer
+if (ff_hevc_is_alpha_video(s) &&
+sps_base->pix_fmt == AV_PIX_FMT_YUV420P &&
+pix_fmt == AV_PIX_FMT_YUVJ420P)
+pix_fmt = sps_base->pix_fmt;
+
 if (pix_fmt != sps_base->pix_fmt ||
 sps->width  != sps_base->width   ||
 sps->height != sps_base->height) {
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 4e95035688..b2b725b5cd 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -714,6 +714,8 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, 
const HEVCPPS *pps,
 
 void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int 
log2_cb_size);
 
+int ff_hevc_is_alpha_video(const HEVCContext *s);
+
 extern const uint8_t ff_hevc_qpel_extra_before[4];
 extern const uint8_t ff_hevc_qpel_extra_after[4];
 extern const uint8_t ff_hevc_qpel

[FFmpeg-devel] [PATCH v2 2/3] avcodec/libx264: Set FFCodec.pix_fmts field

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

We can fix deprecation warning by not set p.pix_fmts, and copy
FFCodec.pix_fmts to FFCodec.p.pix_fmts in av_codec_init_static().
However, that method requires non-const FFCodec. So I decided to
set pix_fmts and p.pix_fmts both for now.
---
 libavcodec/libx264.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 409f45fc7d..ef3c8eb98b 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1633,6 +1633,7 @@ const FFCodec ff_libx264_encoder = {
 .flush= X264_flush,
 .close= X264_close,
 .defaults = x264_defaults,
+.pix_fmts = pix_fmts_all,
 .p.pix_fmts   = pix_fmts_all,
 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
 .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
@@ -1659,6 +1660,7 @@ const FFCodec ff_libx264rgb_encoder = {
 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
   AV_CODEC_CAP_OTHER_THREADS |
   AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+.pix_fmts   = pix_fmts_8bit_rgb,
 .p.pix_fmts = pix_fmts_8bit_rgb,
 .p.priv_class   = &rgbclass,
 .p.wrapper_name = "libx264",
@@ -1691,6 +1693,7 @@ const FFCodec ff_libx262_encoder = {
 .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
 AV_CODEC_CAP_OTHER_THREADS |
 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+.pix_fmts = pix_fmts_8bit,
 .p.pix_fmts   = pix_fmts_8bit,
 .color_ranges = AVCOL_RANGE_MPEG,
 .p.priv_class = &X262_class,
-- 
2.46.0

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

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


[FFmpeg-devel] [PATCH v2 3/3] avcodec/mpeg12enc: Set pix_fmts and supported_framerates fields

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/mpeg12enc.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index e56571da03..1dc8c2181f 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -1238,6 +1238,9 @@ const FFCodec ff_mpeg1video_encoder = {
 .init = encode_init,
 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
 .close= ff_mpv_encode_end,
+.supported_framerates = ff_mpeg12_frame_rate_tab + 1,
+.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
+   AV_PIX_FMT_NONE },
 .p.supported_framerates = ff_mpeg12_frame_rate_tab + 1,
 .p.pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },
@@ -1257,6 +1260,10 @@ const FFCodec ff_mpeg2video_encoder = {
 .init = encode_init,
 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
 .close= ff_mpv_encode_end,
+.supported_framerates = ff_mpeg2_frame_rate_tab,
+.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
+   AV_PIX_FMT_YUV422P,
+   AV_PIX_FMT_NONE },
 .p.supported_framerates = ff_mpeg2_frame_rate_tab,
 .p.pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_YUV422P,
-- 
2.46.0

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

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


Re: [FFmpeg-devel] [PATCH 2/3] avcodec/libx264: Set FFCodec.pix_fmts field and fix deprecation warning

2025-02-05 Thread Zhao Zhili



> On Feb 6, 2025, at 01:42, Andreas Rheinhardt  
> wrote:
> 
> Zhao Zhili:
>> From: Zhao Zhili 
>> 
>> We can fix deprecation warning by not set p.pix_fmts, and copy
>> FFCodec.pix_fmts to FFCodec.p.pix_fmts in av_codec_init_static().
>> However, that method requires non-const FFCodec. So I decided to
>> set pix_fmts and p.pix_fmts both, and disable deprecation warning
>> explicitly.
>> ---
>> libavcodec/libx264.c | 9 +
>> 1 file changed, 9 insertions(+)
>> 
>> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
>> index 409f45fc7d..9b8b32ef4e 100644
>> --- a/libavcodec/libx264.c
>> +++ b/libavcodec/libx264.c
>> @@ -1633,7 +1633,10 @@ const FFCodec ff_libx264_encoder = {
>> .flush= X264_flush,
>> .close= X264_close,
>> .defaults = x264_defaults,
>> +.pix_fmts = pix_fmts_all,
>> +FF_DISABLE_DEPRECATION_WARNINGS
>> .p.pix_fmts   = pix_fmts_all,
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
>> .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
>> #if X264_BUILD < 158
>> @@ -1659,7 +1662,10 @@ const FFCodec ff_libx264rgb_encoder = {
>> .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>>   AV_CODEC_CAP_OTHER_THREADS |
>>   AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
>> +.pix_fmts   = pix_fmts_8bit_rgb,
>> +FF_DISABLE_DEPRECATION_WARNINGS
>> .p.pix_fmts = pix_fmts_8bit_rgb,
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> .p.priv_class   = &rgbclass,
>> .p.wrapper_name = "libx264",
>> .priv_data_size = sizeof(X264Context),
>> @@ -1691,7 +1697,10 @@ const FFCodec ff_libx262_encoder = {
>> .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>> AV_CODEC_CAP_OTHER_THREADS |
>> AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
>> +.pix_fmts = pix_fmts_8bit,
>> +FF_DISABLE_DEPRECATION_WARNINGS
>> .p.pix_fmts   = pix_fmts_8bit,
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> .color_ranges = AVCOL_RANGE_MPEG,
>> .p.priv_class = &X262_class,
>> .p.wrapper_name   = "libx264",
> 
> Only Clang emits these deprecation warnings; and IIRC GCC does not
> support disabling deprecation warnings inside a definition like this
> (compilation failure). The deprecation warnings can instead be fixed
> like in fdff1b9cbfd8cf5a9810c29efa4baf13a4786742.

OK. I decided just set -Wno-deprecated-declarations in my build environment
and not continue addressing the depression warning.

> 
> - Andreas
> 
> ___
> 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 1/1] fftools/ffmpeg_opt: Exit with non-zero status when destination exists

2025-02-05 Thread Marth64
> On 2024-07-16 09:40 am, Marth64 wrote:
> > Gyan:
> >> The former is not an error. The user was asked and the application
> >> behaved as per their reply.
> > Could it make sense to only return the AVERROR(EEXIST) if -nostdin is
> > passed (otherwise current behavior)?
>
> Agreed.

Planning to send a patch for this in the next few days. Thank you.
___
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 v3 1/3] avcodec/hevc: Rewrite scalability_mask_flag parse in decode_vps_ext

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

Remove a for loop and make it easy to extend to support other types
of scalability. Move ScalabilityMask to hevc header file so it can
be used in hevc decoder.

Signed-off-by: Zhao Zhili 
---
 libavcodec/hevc/hevc.h |  7 +++
 libavcodec/hevc/ps.c   | 33 +++--
 libavcodec/hevc/ps.h   |  2 ++
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/libavcodec/hevc/hevc.h b/libavcodec/hevc/hevc.h
index 8bd59142db..b2229fda40 100644
--- a/libavcodec/hevc/hevc.h
+++ b/libavcodec/hevc/hevc.h
@@ -162,5 +162,12 @@ enum {
 HEVC_MAX_PALETTE_PREDICTOR_SIZE = 128,
 };
 
+enum HEVCScalabilityMask {
+HEVC_SCALABILITY_DEPTH  = 1 << (15 - 0),
+HEVC_SCALABILITY_MULTIVIEW  = 1 << (15 - 1),
+HEVC_SCALABILITY_SPATIAL= 1 << (15 - 2),
+HEVC_SCALABILITY_AUXILIARY  = 1 << (15 - 3),
+HEVC_SCALABILITY_MASK_MAX   = 0x,
+};
 
 #endif /* AVCODEC_HEVC_HEVC_H */
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 285084685b..861a6bb0a2 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -450,14 +450,6 @@ static void hevc_vps_free(AVRefStructOpaque opaque, void 
*obj)
 av_freep(&vps->data);
 }
 
-enum ScalabilityMask {
-HEVC_SCALABILITY_DEPTH  = 0,
-HEVC_SCALABILITY_MULTIVIEW  = 1,
-HEVC_SCALABILITY_SPATIAL= 2,
-HEVC_SCALABILITY_AUXILIARY  = 3,
-HEVC_SCALABILITY_MASK_MAX   = 15,
-};
-
 enum DependencyType {
 HEVC_DEP_TYPE_SAMPLE = 0,
 HEVC_DEP_TYPE_MV = 1,
@@ -532,17 +524,22 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 return AVERROR_INVALIDDATA;
 
 splitting_flag = get_bits1(gb);
-num_scalability_types = 0;
-for (int i = 0; i <= HEVC_SCALABILITY_MASK_MAX; i++) {
-int scalability_mask_flag = get_bits1(gb);
-if (scalability_mask_flag && (i != HEVC_SCALABILITY_MULTIVIEW)) {
-av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n", 
i);
-return AVERROR_PATCHWELCOME;
-}
-num_scalability_types += scalability_mask_flag;
-}
-if (num_scalability_types != 1)
+vps->scalability_mask_flag = get_bits(gb, 16);
+num_scalability_types = av_popcount(vps->scalability_mask_flag);
+if (!num_scalability_types) {
+av_log(avctx, AV_LOG_ERROR, "Missing scalability mask\n");
 return AVERROR_INVALIDDATA;
+} else if (num_scalability_types > 1) {
+av_log(avctx, AV_LOG_ERROR, "Scalability number %d not supported\n",
+   num_scalability_types);
+return AVERROR_PATCHWELCOME;
+}
+
+if (!(vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)) {
+av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n",
+   15 - ff_ctz(vps->scalability_mask_flag));
+return AVERROR_PATCHWELCOME;
+}
 
 if (!splitting_flag)
 dimension_id_len = get_bits(gb, 3) + 1;
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index 6f5b1f8755..d3465e3d27 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -205,6 +205,8 @@ typedef struct HEVCVPS {
  */
 int nb_layers;
 
+uint16_t scalability_mask_flag;
+
 // LayerIdxInVps[nuh_layer_id], i.e. a mapping of nuh_layer_id to VPS layer
 // indices. Valid values are between 0 and HEVC_VPS_MAX_LAYERS. Entries for
 // unmapped values of nuh_layer_id are set to -1.
-- 
2.46.0

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

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


Re: [FFmpeg-devel] [PATCH v3 3/3] avcodec/hevc: Add alpha layer support

2025-02-05 Thread James Almer

On 2/5/2025 2:22 PM, Zhao Zhili wrote:




On Feb 5, 2025, at 23:33, James Almer  wrote:

On 2/5/2025 12:10 PM, Zhao Zhili wrote:

From: Zhao Zhili 
Signed-off-by: Zhao Zhili 
---
  libavcodec/hevc/hevcdec.c | 72 ++-
  libavcodec/hevc/hevcdec.h |  2 ++
  libavcodec/hevc/refs.c| 11 +-
  3 files changed, 83 insertions(+), 2 deletions(-)


I tried with https://0x0.st/X7Vx.mov and https://0x0.st/8KCA.mp4, and neither 
seem to output the alpha plane.


The first sample is a early release from apple, with error in vps extension.

I don’t know where the second sample comes from, it’s blank when playback with 
QuickTime Player. The bitstream has a lot of error.

Here is a sample encoded with videotoolbox

./ffmpeg -i bunny.mp4 -i basketball.mp4 \
-filter_complex '[1:v][0:v]alphamerge,format=bgra[vout]’ -\
c:v hevc_videotoolbox -pix_fmt bgra -alpha_quality 0.5 \
-t 10 -map '[vout]' -tag:v hvc1 alpha.mp4

https://drive.google.com/file/d/1SK6gnMNlWODeTySpetNAKgNeqt69DQDz/view?usp=drive_link


That link asks to request access.



OpenPGP_signature.asc
Description: OpenPGP digital 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".


[FFmpeg-devel] [PATCH 3/3] avcodec/mpeg12enc: Set pix_fmts and supported_framerates fields

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/mpeg12enc.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index e56571da03..7c8ba0b25a 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -1238,9 +1238,14 @@ const FFCodec ff_mpeg1video_encoder = {
 .init = encode_init,
 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
 .close= ff_mpv_encode_end,
+.supported_framerates = ff_mpeg12_frame_rate_tab + 1,
+.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
+   AV_PIX_FMT_NONE },
+FF_DISABLE_DEPRECATION_WARNINGS
 .p.supported_framerates = ff_mpeg12_frame_rate_tab + 1,
 .p.pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },
+FF_ENABLE_DEPRECATION_WARNINGS
 .color_ranges = AVCOL_RANGE_MPEG,
 .p.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
@@ -1257,10 +1262,16 @@ const FFCodec ff_mpeg2video_encoder = {
 .init = encode_init,
 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
 .close= ff_mpv_encode_end,
+.supported_framerates = ff_mpeg2_frame_rate_tab,
+.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
+   AV_PIX_FMT_YUV422P,
+   AV_PIX_FMT_NONE },
+FF_DISABLE_DEPRECATION_WARNINGS
 .p.supported_framerates = ff_mpeg2_frame_rate_tab,
 .p.pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_YUV422P,
AV_PIX_FMT_NONE },
+FF_ENABLE_DEPRECATION_WARNINGS
 .color_ranges = AVCOL_RANGE_MPEG,
 .p.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
-- 
2.46.0

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

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


[FFmpeg-devel] [PATCH 2/3] avcodec/libx264: Set FFCodec.pix_fmts field and fix deprecation warning

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

We can fix deprecation warning by not set p.pix_fmts, and copy
FFCodec.pix_fmts to FFCodec.p.pix_fmts in av_codec_init_static().
However, that method requires non-const FFCodec. So I decided to
set pix_fmts and p.pix_fmts both, and disable deprecation warning
explicitly.
---
 libavcodec/libx264.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 409f45fc7d..9b8b32ef4e 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1633,7 +1633,10 @@ const FFCodec ff_libx264_encoder = {
 .flush= X264_flush,
 .close= X264_close,
 .defaults = x264_defaults,
+.pix_fmts = pix_fmts_all,
+FF_DISABLE_DEPRECATION_WARNINGS
 .p.pix_fmts   = pix_fmts_all,
+FF_ENABLE_DEPRECATION_WARNINGS
 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
 .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
 #if X264_BUILD < 158
@@ -1659,7 +1662,10 @@ const FFCodec ff_libx264rgb_encoder = {
 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
   AV_CODEC_CAP_OTHER_THREADS |
   AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+.pix_fmts   = pix_fmts_8bit_rgb,
+FF_DISABLE_DEPRECATION_WARNINGS
 .p.pix_fmts = pix_fmts_8bit_rgb,
+FF_ENABLE_DEPRECATION_WARNINGS
 .p.priv_class   = &rgbclass,
 .p.wrapper_name = "libx264",
 .priv_data_size = sizeof(X264Context),
@@ -1691,7 +1697,10 @@ const FFCodec ff_libx262_encoder = {
 .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
 AV_CODEC_CAP_OTHER_THREADS |
 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+.pix_fmts = pix_fmts_8bit,
+FF_DISABLE_DEPRECATION_WARNINGS
 .p.pix_fmts   = pix_fmts_8bit,
+FF_ENABLE_DEPRECATION_WARNINGS
 .color_ranges = AVCOL_RANGE_MPEG,
 .p.priv_class = &X262_class,
 .p.wrapper_name   = "libx264",
-- 
2.46.0

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/libx264: Fix deprecation warnings on pix_fmts

2025-02-05 Thread Zhao Zhili
I prefer another version which doesn't drop const modifier.

https://ffmpeg.org/pipermail/ffmpeg-devel/2025-February/339331.html

> On Feb 6, 2025, at 00:07, Zhao Zhili  
> wrote:
> 
> From: Zhao Zhili 
> 
> ---
> libavcodec/allcodecs.c |  6 ++---
> libavcodec/libx264.c   | 53 +-
> 2 files changed, 50 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 4e1b1c9b45..d2ec4c3045 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -811,9 +811,9 @@ extern const FFCodec ff_libvvenc_encoder;
> /* preferred over libwebp */
> extern const FFCodec ff_libwebp_anim_encoder;
> extern const FFCodec ff_libwebp_encoder;
> -extern const FFCodec ff_libx262_encoder;
> -extern const FFCodec ff_libx264_encoder;
> -extern const FFCodec ff_libx264rgb_encoder;
> +extern FFCodec ff_libx262_encoder;
> +extern FFCodec ff_libx264_encoder;
> +extern FFCodec ff_libx264rgb_encoder;
> extern FFCodec ff_libx265_encoder;
> extern const FFCodec ff_libxeve_encoder;
> extern const FFCodec ff_libxevd_decoder;
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 409f45fc7d..c4bc7c48f5 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -1607,6 +1607,12 @@ static const FFCodecDefault x264_defaults[] = {
> { NULL },
> };
> 
> +static int X264_get_supported_config(const AVCodecContext *avctx,
> + const AVCodec *codec,
> + enum AVCodecConfig config,
> + unsigned flags, const void **out,
> + int *out_num);
> +
> #if CONFIG_LIBX264_ENCODER
> static const AVClass x264_class = {
> .class_name = "libx264",
> @@ -1615,7 +1621,7 @@ static const AVClass x264_class = {
> .version= LIBAVUTIL_VERSION_INT,
> };
> 
> -const FFCodec ff_libx264_encoder = {
> +FFCodec ff_libx264_encoder = {
> .p.name   = "libx264",
> CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
> .p.type   = AVMEDIA_TYPE_VIDEO,
> @@ -1633,13 +1639,13 @@ const FFCodec ff_libx264_encoder = {
> .flush= X264_flush,
> .close= X264_close,
> .defaults = x264_defaults,
> -.p.pix_fmts   = pix_fmts_all,
> .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
> .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
> #if X264_BUILD < 158
>   | FF_CODEC_CAP_NOT_INIT_THREADSAFE
> #endif
>   ,
> +.get_supported_config = X264_get_supported_config,
> };
> #endif
> 
> @@ -1651,7 +1657,7 @@ static const AVClass rgbclass = {
> .version= LIBAVUTIL_VERSION_INT,
> };
> 
> -const FFCodec ff_libx264rgb_encoder = {
> +FFCodec ff_libx264rgb_encoder = {
> .p.name = "libx264rgb",
> CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
> .p.type = AVMEDIA_TYPE_VIDEO,
> @@ -1659,7 +1665,6 @@ const FFCodec ff_libx264rgb_encoder = {
> .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>   AV_CODEC_CAP_OTHER_THREADS |
>   AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> -.p.pix_fmts = pix_fmts_8bit_rgb,
> .p.priv_class   = &rgbclass,
> .p.wrapper_name = "libx264",
> .priv_data_size = sizeof(X264Context),
> @@ -1672,6 +1677,7 @@ const FFCodec ff_libx264rgb_encoder = {
>   | FF_CODEC_CAP_NOT_INIT_THREADSAFE
> #endif
>   ,
> +.get_supported_config = X264_get_supported_config,
> };
> #endif
> 
> @@ -1683,7 +1689,7 @@ static const AVClass X262_class = {
> .version= LIBAVUTIL_VERSION_INT,
> };
> 
> -const FFCodec ff_libx262_encoder = {
> +FFCodec ff_libx262_encoder = {
> .p.name   = "libx262",
> CODEC_LONG_NAME("libx262 MPEG2VIDEO"),
> .p.type   = AVMEDIA_TYPE_VIDEO,
> @@ -1691,7 +1697,6 @@ const FFCodec ff_libx262_encoder = {
> .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
> AV_CODEC_CAP_OTHER_THREADS |
> AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> -.p.pix_fmts   = pix_fmts_8bit,
> .color_ranges = AVCOL_RANGE_MPEG,
> .p.priv_class = &X262_class,
> .p.wrapper_name   = "libx264",
> @@ -1702,5 +1707,41 @@ const FFCodec ff_libx262_encoder = {
> .defaults = x264_defaults,
> .caps_internal= FF_CODEC_CAP_NOT_INIT_THREADSAFE |
> FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
> +.get_supported_config = X264_get_supported_config,
> };
> #endif
> +
> +static int X264_get_supported_config(const AVCodecContext *avctx,
> + const AVCodec *codec,
> + enum AVCodecConfig config,
> + unsigned flags, const void **out,
> +   

Re: [FFmpeg-devel] [PATCH 2/2] avformat/hls: .ts is always ok even if its a mov/mp4

2025-02-05 Thread Michael Niedermayer
Hi Kacper

On Tue, Feb 04, 2025 at 12:45:14PM +0100, Kacper Michajlow wrote:
[...]
> security benefits. I get it. Someone needed to hit their KPI by
> submitting CVEs, and they found a marginally applicable case of a
> highly unrealistic attack scenario.

I think you mis judge the (un)realism of this attack

prior to the patches, i can give you a m3u8 file and it will store
any local file in the output video

This is not even just a matter of video streaming services,
With a bit of social engeneering you can likely get people to
do that.
"Hey i found this odd file that encodes to different gibberish
 on each machien, iam an artist, doing an art project, can you
 just quickly reencode this and send me the mkv it generates ?"

Who would think that above will effectively give the attacker full
access to your machiene. unless you run this in a sandbox that has
no access to sensitve files



> 
> But FFmpeg should be cautious about adopting questionable security
> measures, such as:
> 
> > DASH playlists should restrict URIs to data:// and file:// unless otherwise 
> > specified with protocol_whitelist.
> 
> I mean, cool, but isn't DASH a Dynamic Adaptive Streaming over HTTP?
> 
> In summary, I believe the ability of FFmpeg to open or parse certain
> formats is highly dependent on the deployment environment. If you
> provide a service that allows foreign playlists to be opened on your
> server, it is your responsibility to restrict access appropriately,
> whether through sandboxing, firewalls, or by disabling unnecessary
> demuxers and features in your FFmpeg binaries to minimize the attack
> surface. There's even a useful configuration option to disable
> networking if that suits your needs. For example, I fully expect my
> libavformat to open DASH streams using the HTTP protocol, and I don’t
> consider that a CVE issue simply because it has that capability.

A local file by default should not open a network connection.
(otherwise one can count who, when and where a file is played)
The user can set the protocol_whitelist if she wants local files
to open network connections

if a m3u8 / dash / whatever file is remote on http then said file
is not local and can open other remote files but cannot open local
files by default
again the user can override that as she prefers

This is just a basic "same origin" policy

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator


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 v2 2/2] random_seed: Improve behaviour with small timer increments with high precision timers

2025-02-05 Thread Michael Niedermayer
Hi Martin

On Thu, Feb 06, 2025 at 12:18:09AM +0200, Martin Storsjö wrote:
> On a Zen 5, on Ubuntu 24.04 (with CLOCKS_PER_SEC 100), the
> value of clock() in this loop increments by 0 most of the time,
> and when it does increment, it usually increments by 1 compared
> to the previous round.
> 
> Due to the "last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t"
> expression, we only manage to take one step forward in this loop
> (incrementing i) if clock() increments by 2, while it incremented
> by 0 in the previous iteration (last_td).
> 
> This is similar to the change done in
> c4152fc42e480c41efb7f761b1bbe5f0bc43d5bc, to speed it up on
> systems with very small CLOCKS_PER_SEC. However in this case,
> CLOCKS_PER_SEC is still very large, but the machine is fast enough
> to hit every clock increment repeatedly.
> 
> For this case, use the number of repetitions of each timer value
> as entropy source; require a change in the number of repetitions
> in order to proceed to the next buffer index.
> 
> This helps the fate-random-seed test to actually terminate within
> a reasonable time on such a system (where it previously could hang,
> running for many minutes).
> ---
>  libavutil/random_seed.c | 20 
>  1 file changed, 20 insertions(+)
> 
> diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
> index ca084b40da..adb7b1f717 100644
> --- a/libavutil/random_seed.c
> +++ b/libavutil/random_seed.c
> @@ -83,6 +83,7 @@ static uint32_t get_generic_seed(void)
>  static uint32_t buffer[512] = { 0 };
>  unsigned char digest[20];
>  uint64_t last_i = i;
> +int last_repeat = 0, cur_repeat = 0;
>  
>  av_assert0(sizeof(tmp) >= av_sha_size);
>  
> @@ -101,8 +102,21 @@ static uint32_t get_generic_seed(void)
>  int incremented_i = 0;
>  int cur_td = t - last_t;
>  if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) < t) {
> +// If the timer incremented by more than 2*last_td at once,
> +// we may e.g. have had a context switch. If the timer resolution
> +// is high (CLOCKS_PER_SEC > 1000), require that the timer
> +// incremented by more than 1. If the timer resolution is low,
> +// it is enough that the timer incremented at all.
>  buffer[++i & 511] += cur_td % 3294638521U;
>  incremented_i = 1;
> +} else if (t != last_t && cur_repeat > 0 && last_repeat > 0 &&
> +   cur_repeat != last_repeat) {
> +// If the timer resolution is high, and we get the same timer
> +// value multiple times, use variances in the number of repeats
> +// of each timer value as entropy. If the number of repeats 
> changed,
> +// proceed to the next index.

Does it still work if you check against the last 2 ?
or does this become too slow ?
What iam thinking of is this

7,8,7,8,8,7,8,7,8,8,7,8,7,8,8,7,8,7,8,8,... and a 9 or 6 or further distant 
would trigger it

I assume both the CPU clock and the wall time are quite precisse so if we
just compare them the entropy could be low even with 2 alternating values

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Nations do behave wisely once they have exhausted all other alternatives. 
-- Abba Eban


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


[FFmpeg-devel] [PATCHv2] avcodec/g728dec: G.728 decoder

2025-02-05 Thread Peter Ross
---
suggestions incorporated.

 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/codec_desc.c |   7 ++
 libavcodec/codec_id.h   |   1 +
 libavcodec/g728data.h   |  70 +
 libavcodec/g728dec.c| 220 
 libavcodec/utils.c  |   1 +
 7 files changed, 301 insertions(+)
 create mode 100644 libavcodec/g728data.h
 create mode 100644 libavcodec/g728dec.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 95bd5488b6..1028046e89 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -395,6 +395,7 @@ OBJS-$(CONFIG_G723_1_DECODER)  += g723_1dec.o 
g723_1.o \
   acelp_vectors.o celp_filters.o 
celp_math.o
 OBJS-$(CONFIG_G723_1_ENCODER)  += g723_1enc.o g723_1.o \
   acelp_vectors.o celp_filters.o 
celp_math.o
+OBJS-$(CONFIG_G728_DECODER)+= g728dec.o
 OBJS-$(CONFIG_G729_DECODER)+= g729dec.o lsp.o celp_math.o 
celp_filters.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o 
g729postfilter.o
 OBJS-$(CONFIG_GDV_DECODER) += gdv.o
 OBJS-$(CONFIG_GEM_DECODER) += gemdec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4e1b1c9b45..111eadf7ce 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -475,6 +475,7 @@ extern const FFCodec ff_flac_decoder;
 extern const FFCodec ff_ftr_decoder;
 extern const FFCodec ff_g723_1_encoder;
 extern const FFCodec ff_g723_1_decoder;
+extern const FFCodec ff_g728_decoder;
 extern const FFCodec ff_g729_decoder;
 extern const FFCodec ff_gsm_decoder;
 extern const FFCodec ff_gsm_ms_decoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index b734d07ded..d8bd30d0e1 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3466,6 +3466,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("LC3 (Low Complexity Communication 
Codec)"),
 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_G728,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "g728",
+.long_name = NULL_IF_CONFIG_SMALL("G.728"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 97b70c5bf5..ee02fe4261 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -552,6 +552,7 @@ enum AVCodecID {
 AV_CODEC_ID_OSQ,
 AV_CODEC_ID_QOA,
 AV_CODEC_ID_LC3,
+AV_CODEC_ID_G728,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/g728data.h b/libavcodec/g728data.h
new file mode 100644
index 00..a2ddf5682d
--- /dev/null
+++ b/libavcodec/g728data.h
@@ -0,0 +1,70 @@
+/*
+ * G.728 decoder
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_G728DATA_H
+#define AVCODEC_G728DATA_H
+
+#include 
+#include "libavutil/macros.h"
+
+#define IDIM 5 /* Vector dimension (excitation block size) */
+#define LPC 50 /* Synthesis filter order */
+#define LPCLG 10 /* Log-gain predictor order */
+#define NFRSZ 20 /* Frame size (adaptation cycle size in samples */
+#define NONR 35 /* Number of non-recursive window samples for synthesis filter 
*/
+#define NONRLG 20 /* Number of non-recursive window samples for log-gain 
predictor */
+#define NUPDATE 4 /* Predictor update period (in terms of vectors) */
+
+#define NSBSZ (LPC + NONR + NFRSZ)
+#define NSBGSZ (LPCLG + NONRLG + NUPDATE)
+
+// Hybrid window for the synthesis filter
+static const uint16_t g728_wnr[NSBSZ] = {
+ 1565,  3127,  4681,  6225,  7755,  9266, 10757, 12223, 13661, 15068,
+16441, 17776, 19071, 20322, 21526, 22682, 23786, 24835, 25828, 26761,
+27634, 28444, 29188, 29866, 30476, 31016, 31486, 31884, 32208, 32460,
+32637, 32739, 32767, 32721, 32599, 32403, 32171, 31940, 31711, 31484,
+31259, 31034, 30812, 30591, 30372, 30154, 29938, 29724, 29511, 29299,
+29089, 28881, 28674, 28468, 28264, 28062, 27861, 27661, 27463, 27266,
+27071, 26877, 26684, 

[FFmpeg-devel] [PATCH v4 2/3] avcodec/hevc/ps: Add basic HEVC_SCALABILITY_AUXILIARY support

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

Only implementing what's needed for HEVC with alpha.

Signed-off-by: Zhao Zhili 
---
 libavcodec/hevc/hevc.h |   5 ++
 libavcodec/hevc/ps.c   | 126 +
 libavcodec/hevc/ps.h   |   4 ++
 3 files changed, 98 insertions(+), 37 deletions(-)

diff --git a/libavcodec/hevc/hevc.h b/libavcodec/hevc/hevc.h
index b2229fda40..710786a89d 100644
--- a/libavcodec/hevc/hevc.h
+++ b/libavcodec/hevc/hevc.h
@@ -170,4 +170,9 @@ enum HEVCScalabilityMask {
 HEVC_SCALABILITY_MASK_MAX   = 0x,
 };
 
+enum HEVCAuxId {
+HEVC_AUX_ALPHA = 1,
+HEVC_AUX_DEPTH = 2,
+};
+
 #endif /* AVCODEC_HEVC_HEVC_H */
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 861a6bb0a2..4f18cd72e4 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -460,14 +460,17 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
   uint64_t layer1_id_included)
 {
 PTL ptl_dummy;
-uint8_t max_sub_layers[HEVC_MAX_LAYERS];
+uint8_t max_sub_layers[HEVC_MAX_LAYERS] = {1, 1};
+uint8_t dimension_id_len[16] = {0};
+uint8_t dimension_id[16] = {0};
+unsigned n;
 
-int splitting_flag, dimension_id_len, view_id_len, num_add_olss, 
num_scalability_types,
+int splitting_flag, view_id_len, num_add_olss, num_scalability_types,
 default_output_layer_idc, direct_dep_type_len, direct_dep_type,
 sub_layers_max_present, sub_layer_flag_info_present_flag, nb_ptl;
 unsigned non_vui_extension_length;
 
-if (vps->vps_max_layers == 1 || vps->vps_num_layer_sets == 1) {
+if (vps->vps_max_layers == 1) {
 av_log(avctx, AV_LOG_VERBOSE, "Ignoring VPS extensions with a single 
layer\n");
 return 0;
 }
@@ -520,7 +523,8 @@ static int decode_vps_ext(GetBitContext *gb, AVCodecContext 
*avctx, HEVCVPS *vps
  */
 vps->nb_layers = 2;
 
-if (parse_ptl(gb, avctx, 0, &ptl_dummy, vps->vps_max_sub_layers) < 0)
+if (vps->vps_base_layer_internal_flag &&
+parse_ptl(gb, avctx, 0, &ptl_dummy, vps->vps_max_sub_layers) < 0)
 return AVERROR_INVALIDDATA;
 
 splitting_flag = get_bits1(gb);
@@ -529,20 +533,25 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 if (!num_scalability_types) {
 av_log(avctx, AV_LOG_ERROR, "Missing scalability mask\n");
 return AVERROR_INVALIDDATA;
-} else if (num_scalability_types > 1) {
-av_log(avctx, AV_LOG_ERROR, "Scalability number %d not supported\n",
-   num_scalability_types);
-return AVERROR_PATCHWELCOME;
 }
 
-if (!(vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)) {
+if (!(vps->scalability_mask_flag &
+  (HEVC_SCALABILITY_MULTIVIEW | HEVC_SCALABILITY_AUXILIARY))) {
 av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n",
15 - ff_ctz(vps->scalability_mask_flag));
 return AVERROR_PATCHWELCOME;
 }
+// x265 specify MULTIVIEW when the stream really is alpha video only.
+if (num_scalability_types > 1)
+av_log(avctx, AV_LOG_WARNING, "Multiple scalability types 
presented\n");
 
-if (!splitting_flag)
-dimension_id_len = get_bits(gb, 3) + 1;
+n = 0;
+for (int i = 0; i < num_scalability_types - splitting_flag; i++) {
+dimension_id_len[i] = get_bits(gb, 3) + 1;
+n += dimension_id_len[i];
+}
+if (splitting_flag)
+dimension_id_len[num_scalability_types - 1] = 5 - n;
 
 if (get_bits1(gb)) { /* vps_nuh_layer_id_present_flag */
 int layer_id_in_nuh = get_bits(gb, 6);
@@ -559,28 +568,57 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 }
 
 if (!splitting_flag) {
-int view_idx = get_bits(gb, dimension_id_len);
-if (view_idx != 1) {
-av_log(avctx, AV_LOG_ERROR, "Unexpected ViewOrderIdx: %d\n", 
view_idx);
+int index = 0;
+
+for (int i = 0; i < num_scalability_types; i++)
+dimension_id[i] = get_bits(gb, dimension_id_len[i]);
+
+if (vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)
+index++;
+
+/* AuxId 1 is alpha, 2 is depth. Only support alpha */
+if (vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY &&
+dimension_id[index] != HEVC_AUX_ALPHA) {
+av_log(avctx, AV_LOG_WARNING,
+   "Unsupported dimension_id %d for 
HEVC_SCALABILITY_AUXILIARY\n",
+   dimension_id[index]);
 return AVERROR_PATCHWELCOME;
 }
 }
 
 view_id_len = get_bits(gb, 4);
-if (view_id_len)
-for (int i = 0; i < 2 /* NumViews */; i++)
+if (view_id_len) {
+n = (vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW) ? 2 : 1;
+for (int i = 0; i < n; i++)
 vps->view_id[i] = get_bits(gb, view_id_len);
+}
 
-if (!get_bits1(gb) /* direct_dependency_flag */) {
-  

[FFmpeg-devel] [PATCH v4 3/3] avcodec/hevc: Add alpha layer support

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

Signed-off-by: Zhao Zhili 
---
 libavcodec/hevc/hevcdec.c | 72 ++-
 libavcodec/hevc/hevcdec.h |  2 ++
 libavcodec/hevc/refs.c| 11 +-
 3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e9c045f7a1..1cdc28de50 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -466,6 +466,24 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 return 0;
 }
 
+int ff_hevc_is_alpha_video(const HEVCContext *s) {
+const HEVCVPS *vps = s->vps;
+int ret = 0;
+
+if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
+return 0;
+
+/* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other
+ * than alpha cannot reach here.
+ */
+ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY);
+
+av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
+   ret ? "is" : "not");
+
+return ret;
+}
+
 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
 {
 unsigned layers_active_output = 0, highest_layer;
@@ -473,6 +491,18 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 s->layers_active_output = 1;
 s->layers_active_decode = 1;
 
+if (ff_hevc_is_alpha_video(s)) {
+const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(s->avctx->pix_fmt);
+
+if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
+return 0;
+
+s->layers_active_decode = (1 << vps->nb_layers) - 1;
+s->layers_active_output = 1;
+
+return 0;
+}
+
 // nothing requested - decode base layer only
 if (!s->nb_view_ids)
 return 0;
@@ -530,6 +560,34 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 return 0;
 }
 
+static enum AVPixelFormat map_to_alpha_format(HEVCContext *s,
+  enum AVPixelFormat pix_fmt)
+{
+switch (pix_fmt) {
+case AV_PIX_FMT_YUV420P:
+case AV_PIX_FMT_YUVJ420P:
+return AV_PIX_FMT_YUVA420P;
+case AV_PIX_FMT_YUV420P10:
+return AV_PIX_FMT_YUVA420P10;
+case AV_PIX_FMT_YUV444P:
+return AV_PIX_FMT_YUVA444P;
+case AV_PIX_FMT_YUV422P:
+return AV_PIX_FMT_YUVA422P;
+case AV_PIX_FMT_YUV422P10LE:
+return AV_PIX_FMT_YUVA422P10LE;
+case AV_PIX_FMT_YUV444P10:
+return AV_PIX_FMT_YUVA444P10;
+case AV_PIX_FMT_YUV444P12:
+return AV_PIX_FMT_YUVA444P12;
+case AV_PIX_FMT_YUV422P12:
+return AV_PIX_FMT_YUVA422P12;
+default:
+av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
+   av_get_pix_fmt_name(pix_fmt));
+return AV_PIX_FMT_NONE;
+}
+}
+
 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 {
 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
@@ -540,9 +598,13 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
  CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
  CONFIG_HEVC_VDPAU_HWACCEL + \
  CONFIG_HEVC_VULKAN_HWACCEL)
-enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
+enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
+enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
 int ret;
 
+if (ff_hevc_is_alpha_video(s))
+alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
+
 switch (sps->pix_fmt) {
 case AV_PIX_FMT_YUV420P:
 case AV_PIX_FMT_YUVJ420P:
@@ -664,6 +726,8 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
 break;
 }
 
+if (alpha_fmt != AV_PIX_FMT_NONE)
+*fmt++ = alpha_fmt;
 *fmt++ = sps->pix_fmt;
 *fmt = AV_PIX_FMT_NONE;
 
@@ -3194,6 +3258,12 @@ static int hevc_frame_start(HEVCContext *s, 
HEVCLayerContext *l,
 !sps->vui.common.video_signal_type_present_flag)
 pix_fmt = sps_base->pix_fmt;
 
+// Ignore range mismatch between base layer and alpha layer
+if (ff_hevc_is_alpha_video(s) &&
+sps_base->pix_fmt == AV_PIX_FMT_YUV420P &&
+pix_fmt == AV_PIX_FMT_YUVJ420P)
+pix_fmt = sps_base->pix_fmt;
+
 if (pix_fmt != sps_base->pix_fmt ||
 sps->width  != sps_base->width   ||
 sps->height != sps_base->height) {
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 4e95035688..b2b725b5cd 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -714,6 +714,8 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, 
const HEVCPPS *pps,
 
 void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int 
log2_cb_size);
 
+int ff_hevc_is_alpha_video(const HEVCContext *s);
+
 extern const uint8_t ff_hevc_qpel_extra_before[4];
 extern const uint8_t ff_hevc_qpel_extra_after[4];
 extern const uint8_t ff_hevc_qpel

[FFmpeg-devel] [PATCH v4 1/3] avcodec/hevc: Rewrite scalability_mask_flag parse in decode_vps_ext

2025-02-05 Thread Zhao Zhili
From: Zhao Zhili 

Remove a for loop and make it easy to extend to support other types
of scalability. Move ScalabilityMask to hevc header file so it can
be used in hevc decoder.

Signed-off-by: Zhao Zhili 
---
 libavcodec/hevc/hevc.h |  7 +++
 libavcodec/hevc/ps.c   | 33 +++--
 libavcodec/hevc/ps.h   |  2 ++
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/libavcodec/hevc/hevc.h b/libavcodec/hevc/hevc.h
index 8bd59142db..b2229fda40 100644
--- a/libavcodec/hevc/hevc.h
+++ b/libavcodec/hevc/hevc.h
@@ -162,5 +162,12 @@ enum {
 HEVC_MAX_PALETTE_PREDICTOR_SIZE = 128,
 };
 
+enum HEVCScalabilityMask {
+HEVC_SCALABILITY_DEPTH  = 1 << (15 - 0),
+HEVC_SCALABILITY_MULTIVIEW  = 1 << (15 - 1),
+HEVC_SCALABILITY_SPATIAL= 1 << (15 - 2),
+HEVC_SCALABILITY_AUXILIARY  = 1 << (15 - 3),
+HEVC_SCALABILITY_MASK_MAX   = 0x,
+};
 
 #endif /* AVCODEC_HEVC_HEVC_H */
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 285084685b..861a6bb0a2 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -450,14 +450,6 @@ static void hevc_vps_free(AVRefStructOpaque opaque, void 
*obj)
 av_freep(&vps->data);
 }
 
-enum ScalabilityMask {
-HEVC_SCALABILITY_DEPTH  = 0,
-HEVC_SCALABILITY_MULTIVIEW  = 1,
-HEVC_SCALABILITY_SPATIAL= 2,
-HEVC_SCALABILITY_AUXILIARY  = 3,
-HEVC_SCALABILITY_MASK_MAX   = 15,
-};
-
 enum DependencyType {
 HEVC_DEP_TYPE_SAMPLE = 0,
 HEVC_DEP_TYPE_MV = 1,
@@ -532,17 +524,22 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 return AVERROR_INVALIDDATA;
 
 splitting_flag = get_bits1(gb);
-num_scalability_types = 0;
-for (int i = 0; i <= HEVC_SCALABILITY_MASK_MAX; i++) {
-int scalability_mask_flag = get_bits1(gb);
-if (scalability_mask_flag && (i != HEVC_SCALABILITY_MULTIVIEW)) {
-av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n", 
i);
-return AVERROR_PATCHWELCOME;
-}
-num_scalability_types += scalability_mask_flag;
-}
-if (num_scalability_types != 1)
+vps->scalability_mask_flag = get_bits(gb, 16);
+num_scalability_types = av_popcount(vps->scalability_mask_flag);
+if (!num_scalability_types) {
+av_log(avctx, AV_LOG_ERROR, "Missing scalability mask\n");
 return AVERROR_INVALIDDATA;
+} else if (num_scalability_types > 1) {
+av_log(avctx, AV_LOG_ERROR, "Scalability number %d not supported\n",
+   num_scalability_types);
+return AVERROR_PATCHWELCOME;
+}
+
+if (!(vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)) {
+av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n",
+   15 - ff_ctz(vps->scalability_mask_flag));
+return AVERROR_PATCHWELCOME;
+}
 
 if (!splitting_flag)
 dimension_id_len = get_bits(gb, 3) + 1;
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index 6f5b1f8755..d3465e3d27 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -205,6 +205,8 @@ typedef struct HEVCVPS {
  */
 int nb_layers;
 
+uint16_t scalability_mask_flag;
+
 // LayerIdxInVps[nuh_layer_id], i.e. a mapping of nuh_layer_id to VPS layer
 // indices. Valid values are between 0 and HEVC_VPS_MAX_LAYERS. Entries for
 // unmapped values of nuh_layer_id are set to -1.
-- 
2.46.0

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

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


Re: [FFmpeg-devel] [PATCH v3 2/3] avcodec/hevc/ps: Add basic HEVC_SCALABILITY_AUXILIARY support

2025-02-05 Thread Zhao Zhili



> On Feb 6, 2025, at 05:20, James Almer  wrote:
> 
> On 2/5/2025 12:10 PM, Zhao Zhili wrote:
>> -skip_bits1(gb); /* direct_depenency_all_layers_flag */
>> -direct_dep_type = get_bits_long(gb, direct_dep_type_len);
>> -if (direct_dep_type > HEVC_DEP_TYPE_BOTH) {
>> -av_log(avctx, AV_LOG_WARNING, "Unsupported direct_dep_type: %d\n",
>> -   direct_dep_type);
>> -return AVERROR_PATCHWELCOME;
>> +/* direct_depenency_all_layers_flag */
>> +if (get_bits1(gb)) {
>> +direct_dep_type = get_bits_long(gb, direct_dep_type_len);
>> +if (direct_dep_type > HEVC_DEP_TYPE_BOTH) {
>> +av_log(avctx, AV_LOG_WARNING, "Unsupported direct_dep_type: 
>> %d\n",
>> +   direct_dep_type);
>> +return AVERROR_PATCHWELCOME;
>> +}
>>  }
> 
> direct_dep_type is also coded if direct_depenency_all_layers_flag is false 
> when (if I'm reading the spec right) vps->num_direct_ref_layers[1] is not 0.

Fixed in v4.

https://ffmpeg.org/pipermail/ffmpeg-devel/2025-February/339364.html

> 
> ___
> 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 1/1] fftools/ffmpeg_opt: Exit with non-zero status when destination exists

2025-02-05 Thread Leo Izen

On 2/5/25 11:14 AM, Marth64 wrote:

behaved as per their reply.

Could it make sense to only return the AVERROR(EEXIST) if -nostdin is


If you do, you should consider not just -nostdin but also if reading 
from stdin like a pipe, e.g. ffmpeg -i -  foo.mkv
this will exit with success if foo.mkv exists without asking on stdin 
(as you'd expect it to not, cause it's reading from stdin)


- Leo Izen (Traneptora)


___
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 1/2] random_seed: Reorder if clauses for gathering entropy

2025-02-05 Thread Michael Niedermayer
Hi

On Thu, Feb 06, 2025 at 12:18:08AM +0200, Martin Storsjö wrote:
> Make it easier to add more cases.
> 
> This should be a pure refactoring, with no functional changes.
> ---
>  libavutil/random_seed.c | 19 +++
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
> index 8a4e4f1fc0..ca084b40da 100644
> --- a/libavutil/random_seed.c
> +++ b/libavutil/random_seed.c
> @@ -98,17 +98,20 @@ static uint32_t get_generic_seed(void)
>  
>  for (;;) {
>  clock_t t = clock();
> -if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t) {
> -last_td = t - last_t;
> -buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + 
> (last_td % 3294638521U);
> +int incremented_i = 0;
> +int cur_td = t - last_t;
> +if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) < t) {
> +buffer[++i & 511] += cur_td % 3294638521U;
> +incremented_i = 1;
>  } else {
> -last_td = t - last_t;
> -buffer[++i & 511] += last_td % 3294638521U;
> -if ((t - init_t) >= CLOCKS_PER_SEC>>5)
> -if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i 
> - last_i > 8)
> -break;
> +buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (cur_td 
> % 3294638521U);
> +}
> +if (incremented_i && (t - init_t) >= CLOCKS_PER_SEC>>5) {
> +if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - 
> last_i > 8)
> +break;
>  }
>  last_t = t;
> +last_td = cur_td;
>  if (!init_t)
>  init_t = t;
>  }

sure, if you prefer / if it makes chanegs easier

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates


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 5/6] avcodec/hevc/sei: dynamically allocate 3D Reference Displays Information SEI messages

2025-02-05 Thread Michael Niedermayer
On Mon, Feb 03, 2025 at 07:35:45PM -0300, James Almer wrote:
> Considerably reduces the size of HEVCSEI and eliminates data copy between 
> threads.
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/hevc/hevcdec.c | 4 ++--
>  libavcodec/hevc/refs.c| 4 ++--
>  libavcodec/hevc/sei.c | 6 +-
>  libavcodec/hevc/sei.h | 6 +-
>  4 files changed, 14 insertions(+), 6 deletions(-)

this segfaults here, will probably retest tomorrow without other patches
but i removed the ones you pointed to

[vist#0:0/hevc @ 0x12015580] [dec:hevc @ 0x1201b240] View with index 1 
requested, but only 1 views available in current video sequence (more views may 
or may not be available in later sequences).
==307141== Thread 6 dec0:0:hevc:
==307141== Invalid read of size 1
==307141==at 0x93F313: export_multilayer (in ffmpeg/ffmpeg_g)
==307141==by 0x94B51F: hevc_receive_frame (in ffmpeg/ffmpeg_g)
==307141==by 0x8798AA: ff_decode_receive_frame_internal (in ffmpeg/ffmpeg_g)
==307141==by 0x879F54: decode_receive_frame_internal (in ffmpeg/ffmpeg_g)
==307141==by 0x87A229: avcodec_send_packet (in ffmpeg/ffmpeg_g)
==307141==by 0x2FBE13: decoder_thread (in ffmpeg/ffmpeg_g)
==307141==by 0x31D6AE: task_wrapper (in ffmpeg/ffmpeg_g)
==307141==by 0x4A06608: start_thread (pthread_create.c:477)
==307141==by 0x772A352: clone (clone.S:95)
==307141==  Address 0x3 is not stack'd, malloc'd or (recently) free'd



[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Any man who breaks a law that conscience tells him is unjust and willingly 
accepts the penalty by staying in jail in order to arouse the conscience of 
the community on the injustice of the law is at that moment expressing the 
very highest respect for law. - Martin Luther King Jr


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


[FFmpeg-devel] [PATCH v2 5/6] avcodec/hevc/sei: dynamically allocate 3D Reference Displays Information SEI messages

2025-02-05 Thread James Almer
Considerably reduces the size of HEVCSEI.

Signed-off-by: James Almer 
---
Fixed segfaults.

 libavcodec/hevc/hevcdec.c | 10 +-
 libavcodec/hevc/refs.c|  4 ++--
 libavcodec/hevc/sei.c |  6 +-
 libavcodec/hevc/sei.h |  6 +-
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e9c045f7a1..881538fb91 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -429,7 +429,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
 {
-const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
+const HEVCSEITDRDI *tdrdi = s->sei.tdrdi;
 
 av_freep(&s->view_ids_available);
 s->nb_view_ids_available = 0;
@@ -444,7 +444,7 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 if (!s->view_ids_available)
 return AVERROR(ENOMEM);
 
-if (tdrdi->num_ref_displays) {
+if (tdrdi && tdrdi->num_ref_displays) {
 s->view_pos_available = av_calloc(vps->nb_layers, 
sizeof(*s->view_pos_available));
 if (!s->view_pos_available)
 return AVERROR(ENOMEM);
@@ -454,9 +454,9 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 s->view_ids_available[i] = vps->view_id[i];
 
 if (s->view_pos_available) {
-s->view_pos_available[i] = vps->view_id[i] == 
tdrdi->left_view_id[0]  ?
+s->view_pos_available[i] = tdrdi && (vps->view_id[i] == 
tdrdi->left_view_id[0])  ?
AV_STEREO3D_VIEW_LEFT   
   :
-   vps->view_id[i] == 
tdrdi->right_view_id[0] ?
+   tdrdi && (vps->view_id[i] == 
tdrdi->right_view_id[0]) ?
AV_STEREO3D_VIEW_RIGHT : 
AV_STEREO3D_VIEW_UNSPEC;
 }
 }
@@ -4015,7 +4015,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 s->sei.common.frame_packing= s0->sei.common.frame_packing;
 s->sei.common.display_orientation  = s0->sei.common.display_orientation;
 s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
-s->sei.tdrdi   = s0->sei.tdrdi;
+av_refstruct_replace(&s->sei.tdrdi, s0->sei.tdrdi);
 
 return 0;
 }
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index dd7f7f95a8..d1d2f27a9b 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -104,7 +104,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, 
HEVCLayerContext *l)
 
 // add view ID side data if it's nontrivial
 if (vps->nb_layers > 1 || view_id) {
-HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
+HEVCSEITDRDI *tdrdi = s->sei.tdrdi;
 AVFrameSideData *sd = av_frame_side_data_new(&frame->f->side_data,
  
&frame->f->nb_side_data,
  AV_FRAME_DATA_VIEW_ID,
@@ -113,7 +113,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, 
HEVCLayerContext *l)
 goto fail;
 *(int*)sd->data = view_id;
 
-if (tdrdi->num_ref_displays) {
+if (tdrdi && tdrdi->num_ref_displays) {
 AVStereo3D *stereo_3d;
 
 stereo_3d = av_stereo3d_create_side_data(frame->f);
diff --git a/libavcodec/hevc/sei.c b/libavcodec/hevc/sei.c
index 8793d86fdc..588516043b 100644
--- a/libavcodec/hevc/sei.c
+++ b/libavcodec/hevc/sei.c
@@ -220,7 +220,11 @@ static int decode_nal_sei_prefix(GetBitContext *gb, 
GetByteContext *gbyte,
 case SEI_TYPE_TIME_CODE:
 return decode_nal_sei_timecode(&s->timecode, gb);
 case SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO:
-return decode_nal_sei_3d_reference_displays_info(&s->tdrdi, gb);
+av_refstruct_unref(&s->tdrdi);
+s->tdrdi = av_refstruct_allocz(sizeof(*s->tdrdi));
+if (!s->tdrdi)
+return AVERROR(ENOMEM);
+return decode_nal_sei_3d_reference_displays_info(s->tdrdi, gb);
 default: {
 int ret = ff_h2645_sei_message_decode(&s->common, type, 
AV_CODEC_ID_HEVC,
   gb, gbyte, logctx);
diff --git a/libavcodec/hevc/sei.h b/libavcodec/hevc/sei.h
index ee640003bc..42ee6a20b7 100644
--- a/libavcodec/hevc/sei.h
+++ b/libavcodec/hevc/sei.h
@@ -24,6 +24,7 @@
 #include 
 
 #include "libavutil/buffer.h"
+#include "libavutil/refstruct.h"
 
 #include "libavcodec/get_bits.h"
 #include "libavcodec/h2645_sei.h"
@@ -101,7 +102,9 @@ typedef struct HEVCSEI {
 HEVCSEIPictureTiming picture_timing;
 int active_seq_parameter_set_id;
 HEVCSEITimeCode timecode;
-HEVCSEITDRDI tdrdi;
+
+// Dynamic allocations due to large size.
+HEVCSEITDRDI *tdrdi;
 } HEVCSEI;
 
 struct HEVCParamSets;
@@ -118,6 +121,7 @@ int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, 
HEVCSEI *s,
  */
 static inlin

Re: [FFmpeg-devel] [PATCH v3 2/2] Add stream dump test with test for ogg/flac.

2025-02-05 Thread Michael Niedermayer
On Tue, Feb 04, 2025 at 07:31:45AM -0500, Romain Beauxis wrote:
> This is the new FATE test.
> 
> Test samples are available here: 
> https://www.dropbox.com/scl/fo/fxt2edwkyj2mjc9qubku5/AICHxJyxMMAK8MIJqWLcvk4?rlkey=mlt12lsu741ejukz0p5qtn9rq&dl=0
> 
> Output prior to the changes is:
> Stream ID: 0, codec name: flac, metadata: encoder=Lavc61.19.100 
> flac:title=First Stream
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, frame PTS: 0, metadata:
> Stream ID: 0, packet PTS: 4608, packet DTS: 4608
> Stream ID: 0, frame PTS: 4608, metadata:
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, frame PTS: 0, metadata:
> Stream ID: 0, packet PTS: 4608, packet DTS: 4608
> Stream ID: 0, frame PTS: 4608, metadata:
> 
> Output after the changes:
> Stream ID: 0, codec name: flac, metadata: encoder=Lavc61.19.100 
> flac:title=First Stream
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, frame PTS: 0, metadata:
> Stream ID: 0, packet PTS: 4608, packet DTS: 4608
> Stream ID: 0, frame PTS: 4608, metadata:
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, packet PTS: 0, packet DTS: 0
> Stream ID: 0, frame PTS: 0, metadata: encoder=Lavc61.19.100 flac:title=Second 
> Stream
> Stream ID: 0, packet PTS: 4608, packet DTS: 4608
> Stream ID: 0, frame PTS: 4608, metadata:
> 
> ---
>  tests/Makefile|   2 +
>  tests/api/Makefile|   2 +-
>  tests/api/api-dump-stream-meta-test.c | 169 ++
>  tests/fate/api.mak|   5 +
>  tests/fate/ogg-flac.mak   |  11 ++

This is missing:
./tests/ref/fate/api-dump-stream-meta

also make fate fails like this:
TESTapi-dump-stream-meta
reference file './tests/ref/fate/api-dump-stream-meta' not found
./tests/fate-run.sh: 705: cannot open 
tests/data/fate/api-dump-stream-meta.diff: No such file
Test api-dump-stream-meta failed. Look at 
tests/data/fate/api-dump-stream-meta.err for details.
make: *** [tests/Makefile:313: api-dump-stream-meta] Error 1

but the failed part cant be run

make api-dump-stream-meta
make: *** No rule to make target 'api-dump-stream-meta'.  Stop.

also if i add a empty reference file
make fate passes

so it seems there is some bug in this

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle


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


[FFmpeg-devel] [PATCH] avformat/unix: Set is_streamed to true

2025-02-05 Thread Efrain Torres
Currently when a Unix Domain Socket is used as input there is a loss of 
data when data is consumed from the stream. Setting is_streamed to true 
fixes this, since the unix domain socket is now treated like a 
consumable stream.


Fixes: #9346

Signed-off-by: dank074 
---
 libavformat/unix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/unix.c b/libavformat/unix.c
index 5704155cf0..2de4023835 100644
--- a/libavformat/unix.c
+++ b/libavformat/unix.c
@@ -89,7 +89,7 @@ static int unix_open(URLContext *h, const char 
*filename, int flags)

 }
  s->fd = fd;
-
+h->is_streamed = 1;
 return 0;
  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] [PATCH] avutil/hwcontext_amf: fix crash on uninit after init failed

2025-02-05 Thread Kacper Michajłow
amf_device_create() calls amf_device_uninit() on errors, but if things
were not initialized it will null deref amf_ctx->factory.

Fixes: https://github.com/mpv-player/mpv/issues/15814

Signed-off-by: Kacper Michajłow 
---
 libavutil/hwcontext_amf.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c
index 8e0ce1927e..5ba2ec5b07 100644
--- a/libavutil/hwcontext_amf.c
+++ b/libavutil/hwcontext_amf.c
@@ -339,7 +339,7 @@ static int amf_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 static void amf_device_uninit(AVHWDeviceContext *device_ctx)
 {
 AVAMFDeviceContext  *amf_ctx = device_ctx->hwctx;
-AMF_RESULT  res;
+AMF_RESULT  res = AMF_NOT_INITIALIZED;
 AMFTrace   *trace;
 
 if (amf_ctx->context) {
@@ -348,7 +348,9 @@ static void amf_device_uninit(AVHWDeviceContext *device_ctx)
 amf_ctx->context = NULL;
 }
 
-res = amf_ctx->factory->pVtbl->GetTrace(amf_ctx->factory, &trace);
+if (amf_ctx->factory)
+res = amf_ctx->factory->pVtbl->GetTrace(amf_ctx->factory, &trace);
+
 if (res == AMF_OK) {
 trace->pVtbl->UnregisterWriter(trace, FFMPEG_AMF_WRITER_ID);
 }
-- 
2.45.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 v2 3/3] avcodec/hevc: Add alpha layer support

2025-02-05 Thread James Almer

On 12/15/2024 3:39 AM, Zhao Zhili wrote:

From: Zhao Zhili 

---
  libavcodec/hevc/hevcdec.c | 72 ++-
  libavcodec/hevc/hevcdec.h |  2 ++
  libavcodec/hevc/refs.c| 10 +-
  3 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index be35a9de82..3675ac1e2b 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -458,6 +458,24 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
  return 0;
  }
  
+int ff_hevc_is_alpha_video(const HEVCContext *s) {

+const HEVCVPS *vps = s->vps;
+int ret = 0;
+
+if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
+return 0;
+
+/* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other
+ * than alpha cannot reach here.
+ */
+ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY);
+
+av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
+   ret ? "is" : "not");
+
+return ret;
+}
+
  static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
  {
  unsigned layers_active_output = 0, highest_layer;
@@ -465,6 +483,18 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
  s->layers_active_output = 1;
  s->layers_active_decode = 1;
  
+if (ff_hevc_is_alpha_video(s)) {

+const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(s->avctx->pix_fmt);
+
+if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
+return 0;
+
+s->layers_active_decode = (1 << vps->nb_layers) - 1;
+s->layers_active_output = 1;
+
+return 0;
+}
+
  // nothing requested - decode base layer only
  if (!s->nb_view_ids)
  return 0;
@@ -522,6 +552,34 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
  return 0;
  }
  
+static enum AVPixelFormat map_to_alpha_format(HEVCContext *s,

+  enum AVPixelFormat pix_fmt)
+{
+switch (pix_fmt) {
+case AV_PIX_FMT_YUV420P:
+case AV_PIX_FMT_YUVJ420P:
+return AV_PIX_FMT_YUVA420P;
+case AV_PIX_FMT_YUV420P10:
+return AV_PIX_FMT_YUVA420P10;
+case AV_PIX_FMT_YUV444P:
+return AV_PIX_FMT_YUVA444P;
+case AV_PIX_FMT_YUV422P:
+return AV_PIX_FMT_YUVA422P;
+case AV_PIX_FMT_YUV422P10LE:
+return AV_PIX_FMT_YUVA422P10LE;
+case AV_PIX_FMT_YUV444P10:
+return AV_PIX_FMT_YUVA444P10;
+case AV_PIX_FMT_YUV444P12:
+return AV_PIX_FMT_YUVA444P12;
+case AV_PIX_FMT_YUV422P12:
+return AV_PIX_FMT_YUVA422P12;
+default:
+av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
+   av_get_pix_fmt_name(pix_fmt));
+return AV_PIX_FMT_NONE;
+}
+}
+
  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
  {
  #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
@@ -532,9 +590,13 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
   CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
   CONFIG_HEVC_VDPAU_HWACCEL + \
   CONFIG_HEVC_VULKAN_HWACCEL)
-enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
+enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
+enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
  int ret;
  
+if (ff_hevc_is_alpha_video(s))

+alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
+
  switch (sps->pix_fmt) {
  case AV_PIX_FMT_YUV420P:
  case AV_PIX_FMT_YUVJ420P:
@@ -650,6 +712,8 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
  break;
  }
  
+if (alpha_fmt != AV_PIX_FMT_NONE)

+*fmt++ = alpha_fmt;
  *fmt++ = sps->pix_fmt;
  *fmt = AV_PIX_FMT_NONE;
  
@@ -3182,6 +3246,12 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l,

  !sps->vui.common.video_signal_type_present_flag)
  pix_fmt = sps_base->pix_fmt;
  
+// Ignore range mismatch between base layer and alpha layer

+if (ff_hevc_is_alpha_video(s) &&
+sps_base->pix_fmt == AV_PIX_FMT_YUV420P &&
+pix_fmt == AV_PIX_FMT_YUVJ420P)
+pix_fmt = sps_base->pix_fmt;
+
  if (pix_fmt != sps_base->pix_fmt ||
  sps->width  != sps_base->width   ||
  sps->height != sps_base->height) {
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 473709b4e8..f8ed156a1c 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -714,6 +714,8 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, 
const HEVCPPS *pps,
  
  void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size);
  
+int ff_hevc_is_alpha_video(const HEVCContext *s);

+
  extern const uint8_t ff_hevc_qpel_extra_before[4];
  extern const ui