[FFmpeg-devel] [PATCH] hwcontext_vulkan: add support for mapping multiplane images into CUDA

2025-03-15 Thread Lynne
This patch refactors the CUDA import code to allow for Vulkan images
with multiple planes to be mapped.
---
 libavutil/hwcontext_vulkan.c | 262 +--
 1 file changed, 160 insertions(+), 102 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 10521ce685..fcff34b5e2 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -3409,6 +3409,130 @@ fail:
 #endif
 
 #if CONFIG_CUDA
+static int export_mem_to_cuda(AVHWDeviceContext *ctx,
+  AVHWDeviceContext *cuda_cu, CudaFunctions *cu,
+  AVVkFrameInternal *dst_int, int idx,
+  VkDeviceMemory mem, size_t size)
+{
+VkResult ret;
+VulkanDevicePriv *p = ctx->hwctx;
+AVVulkanDeviceContext *hwctx = &p->p;
+FFVulkanFunctions *vk = &p->vkctx.vkfn;
+
+#ifdef _WIN32
+CUDA_EXTERNAL_MEMORY_HANDLE_DESC ext_desc = {
+.type = IsWindows8OrGreater()
+? CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32
+: CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT,
+.size = size,
+};
+VkMemoryGetWin32HandleInfoKHR export_info = {
+.sType  = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR,
+.memory = mem,
+.handleType = IsWindows8OrGreater()
+? VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT
+: VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT,
+};
+
+ret = vk->GetMemoryWin32HandleKHR(hwctx->act_dev, &export_info,
+  &ext_desc.handle.win32.handle);
+if (ret != VK_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Unable to export the image as a Win32 
Handle: %s!\n",
+   ff_vk_ret2str(ret));
+return AVERROR_EXTERNAL;
+}
+dst_int->ext_mem_handle[idx] = ext_desc.handle.win32.handle;
+#else
+CUDA_EXTERNAL_MEMORY_HANDLE_DESC ext_desc = {
+.type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD,
+.size = size,
+};
+VkMemoryGetFdInfoKHR export_info = {
+.sType  = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
+.memory = mem,
+.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
+};
+
+ret = vk->GetMemoryFdKHR(hwctx->act_dev, &export_info,
+ &ext_desc.handle.fd);
+if (ret != VK_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Unable to export the image as a FD: %s!\n",
+   ff_vk_ret2str(ret));
+return AVERROR_EXTERNAL;
+}
+#endif
+
+ret = CHECK_CU(cu->cuImportExternalMemory(&dst_int->ext_mem[idx], 
&ext_desc));
+if (ret < 0) {
+#ifndef _WIN32
+close(ext_desc.handle.fd);
+#endif
+return AVERROR_EXTERNAL;
+}
+
+return 0;
+}
+
+static int export_sem_to_cuda(AVHWDeviceContext *ctx,
+  AVHWDeviceContext *cuda_cu, CudaFunctions *cu,
+  AVVkFrameInternal *dst_int, int idx,
+  VkSemaphore sem)
+{
+VkResult ret;
+VulkanDevicePriv *p = ctx->hwctx;
+AVVulkanDeviceContext *hwctx = &p->p;
+FFVulkanFunctions *vk = &p->vkctx.vkfn;
+
+#ifdef _WIN32
+VkSemaphoreGetWin32HandleInfoKHR sem_export = {
+.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_WIN32_HANDLE_INFO_KHR,
+.semaphore = sem,
+.handleType = IsWindows8OrGreater()
+  ? VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT
+  : VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT,
+};
+CUDA_EXTERNAL_SEMAPHORE_HANDLE_DESC ext_sem_desc = {
+.type = 10 /* TODO: 
CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_WIN32 */,
+};
+#else
+VkSemaphoreGetFdInfoKHR sem_export = {
+.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR,
+.semaphore = sem,
+.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
+};
+CUDA_EXTERNAL_SEMAPHORE_HANDLE_DESC ext_sem_desc = {
+.type = 9 /* TODO: 
CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_FD */,
+};
+#endif
+
+#ifdef _WIN32
+ret = vk->GetSemaphoreWin32HandleKHR(hwctx->act_dev, &sem_export,
+ &ext_sem_desc.handle.win32.handle);
+#else
+ret = vk->GetSemaphoreFdKHR(hwctx->act_dev, &sem_export,
+&ext_sem_desc.handle.fd);
+#endif
+if (ret != VK_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Failed to export semaphore: %s\n",
+   ff_vk_ret2str(ret));
+return AVERROR_EXTERNAL;
+}
+#ifdef _WIN32
+dst_int->ext_sem_handle[idx] = ext_sem_desc.handle.win32.handle;
+#endif
+
+ret = CHECK_CU(cu->cuImportExternalSemaphore(&dst_int->cu_sem[idx],
+ &ext_sem_desc));
+if (ret < 0) {
+#ifndef _WIN32
+close(ext_sem_desc.handle.fd);
+#endif
+return AVERROR_EXTERNAL;
+}
+
+return 0;
+}
+
 static i

[FFmpeg-devel] [PATCH 4/6] avformat/flvdec: Remove one level of indentation

2025-03-15 Thread Zhao Zhili
From: Zhao Zhili 

Also remove the condition of AMF_DATA_TYPE_BOOL when parse color
info. There is no AMF_DATA_TYPE_BOOL type in color info.
---
 libavformat/flvdec.c | 66 +---
 1 file changed, 31 insertions(+), 35 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index fcc8403db7..b5c468a1d1 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -754,42 +754,38 @@ static int amf_parse_object(AVFormatContext *s, AVStream 
*astream,
 }
 }
 
-if (flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_PARSING) {
+if (amf_type == AMF_DATA_TYPE_NUMBER && flv->meta_color_info_flag == 
FLV_COLOR_INFO_FLAG_PARSING) {
 FLVMetaVideoColor *meta_video_color = &flv->meta_color_info;
-
-if (amf_type == AMF_DATA_TYPE_NUMBER ||
-amf_type == AMF_DATA_TYPE_BOOL) {
-if (!strcmp(key, "colorPrimaries")) {
-meta_video_color->primaries = num_val;
-} else if (!strcmp(key, "transferCharacteristics")) {
-meta_video_color->transfer_characteristics = num_val;
-} else if (!strcmp(key, "matrixCoefficients")) {
-meta_video_color->matrix_coefficients = num_val;
-} else if (!strcmp(key, "maxFall")) {
-meta_video_color->max_fall = num_val;
-} else if (!strcmp(key, "maxCLL")) {
-meta_video_color->max_cll = num_val;
-} else if (!strcmp(key, "redX")) {
-meta_video_color->mastering_meta.r_x = num_val;
-} else if (!strcmp(key, "redY")) {
-meta_video_color->mastering_meta.r_y = num_val;
-} else if (!strcmp(key, "greenX")) {
-meta_video_color->mastering_meta.g_x = num_val;
-} else if (!strcmp(key, "greenY")) {
-meta_video_color->mastering_meta.g_y = num_val;
-} else if (!strcmp(key, "blueX")) {
-meta_video_color->mastering_meta.b_x = num_val;
-} else if (!strcmp(key, "blueY")) {
-meta_video_color->mastering_meta.b_y = num_val;
-} else if (!strcmp(key, "whitePointX")) {
-meta_video_color->mastering_meta.white_x = num_val;
-} else if (!strcmp(key, "whitePointY")) {
-meta_video_color->mastering_meta.white_y = num_val;
-} else if (!strcmp(key, "maxLuminance")) {
-meta_video_color->mastering_meta.max_luminance = num_val;
-} else if (!strcmp(key, "minLuminance")) {
-meta_video_color->mastering_meta.min_luminance = num_val;
-}
+if (!strcmp(key, "colorPrimaries")) {
+meta_video_color->primaries = num_val;
+} else if (!strcmp(key, "transferCharacteristics")) {
+meta_video_color->transfer_characteristics = num_val;
+} else if (!strcmp(key, "matrixCoefficients")) {
+meta_video_color->matrix_coefficients = num_val;
+} else if (!strcmp(key, "maxFall")) {
+meta_video_color->max_fall = num_val;
+} else if (!strcmp(key, "maxCLL")) {
+meta_video_color->max_cll = num_val;
+} else if (!strcmp(key, "redX")) {
+meta_video_color->mastering_meta.r_x = num_val;
+} else if (!strcmp(key, "redY")) {
+meta_video_color->mastering_meta.r_y = num_val;
+} else if (!strcmp(key, "greenX")) {
+meta_video_color->mastering_meta.g_x = num_val;
+} else if (!strcmp(key, "greenY")) {
+meta_video_color->mastering_meta.g_y = num_val;
+} else if (!strcmp(key, "blueX")) {
+meta_video_color->mastering_meta.b_x = num_val;
+} else if (!strcmp(key, "blueY")) {
+meta_video_color->mastering_meta.b_y = num_val;
+} else if (!strcmp(key, "whitePointX")) {
+meta_video_color->mastering_meta.white_x = num_val;
+} else if (!strcmp(key, "whitePointY")) {
+meta_video_color->mastering_meta.white_y = num_val;
+} else if (!strcmp(key, "maxLuminance")) {
+meta_video_color->mastering_meta.max_luminance = num_val;
+} else if (!strcmp(key, "minLuminance")) {
+meta_video_color->mastering_meta.min_luminance = num_val;
 }
 }
 
-- 
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] avfilter: POC: enable out-of-tree filters

2025-03-15 Thread Leandro Santiago
This is a POC/prototype that aims to enable out of tree filters on
FFmpeg.

Here I name them "extra filters".

It introduces the program `jq` as a new build dependency.

To test it, create a directory, for instance, /tmp/my-shiny-filter/ and
inside it, create the following files:

`filter.json`, with the content:

```
{
  "check": "require_pkg_config json json-c json-c/json.h json_c_version_num",
  "symbols": ["ff_vf_foo", "ff_vf_bar"]
}
```

`filter.mak`, with the content:

```
OBJS += vf_shiny.o
LIBOBJS += vf_shiny.o

libavfilter/vf_shiny.o:
$(CC) $(EXTRA_FILTER_FLAGS) -c -o $@ 
$(EXTRA_FILTER_FOO_LOCATION)/vf_shiny.c
```

`vf_shiny.c` file, with the content:


```
#include "libavutil/internal.h" 
  
#include "avfilter.h"   
  #include 
"filters.h" 
 
#include "video.h" 

const FFFilter ff_vf_bar = {
.p.name= "bar",
.p.description = NULL_IF_CONFIG_SMALL("Example filter Baz"),
.p.flags   = AVFILTER_FLAG_METADATA_ONLY,
FILTER_INPUTS(ff_video_default_filterpad),
FILTER_OUTPUTS(ff_video_default_filterpad),
};

const FFFilter ff_vf_foo = {
.p.name= "foo",
.p.description = NULL_IF_CONFIG_SMALL("Another foo filter"),
.p.flags   = AVFILTER_FLAG_METADATA_ONLY,
FILTER_INPUTS(ff_video_default_filterpad),
FILTER_OUTPUTS(ff_video_default_filterpad),
};
```

Then, from the ffmpeg source tree, run configure specifying where the
extra filter is located:

```
./configure --extra-filter=/tmp/my-shiny-filter
make ffplay
```

Now you can use the filters:

```
./ffplay /path/to/file.webm -vf 'foo,baz'
```

What works:

- Building C based filters with no extra dependencies.
- Multiple filters in the same object file.

What does not work:

- The extra filters will not use the same CC flags used to build the
  built-in filters as I could get it to work yet.
- Due to the above limitation, you cannot include headers of extra
  dependencies, for instance, `json.h` in the example.
- You can pass arbitrary CFLAGS or LDFLAGS in the filter.json file,
  but they should be passed only then building/linking `libavfilter`,
  instead of other libraries.

What was not implemented:

- I believe it would be useful to check if the license of the filter is
  compatible with the license used to build FFmpeg.
- Only extra filters written in C (maybe C++?) are supported for now.
  One of my goals is to enable Rust as well.

Signed-off-by: Leandro Santiago 
---
 .gitignore   |  3 ++
 configure| 61 
 libavfilter/Makefile |  4 +++
 libavfilter/allfilters.c |  1 +
 4 files changed, 69 insertions(+)

diff --git a/.gitignore b/.gitignore
index 9cfc78b414..4963e90191 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,6 @@
 /tools/python/__pycache__/
 /libavcodec/vulkan/*.c
 /libavfilter/vulkan/*.c
+/ffbuild/extra-filters.txt
+/ffbuild/extra-filters.mak
+/libavfilter/extra_filters_extern.h
diff --git a/configure b/configure
index 750c99e3b9..6a2adc6c05 100755
--- a/configure
+++ b/configure
@@ -179,6 +179,7 @@ Individual component options:
   --enable-filter=NAME enable filter NAME
   --disable-filter=NAMEdisable filter NAME
   --disable-filtersdisable all filters
+  --extra-filter=/foo/bar  add extra filter from directory. This option can be 
used multiple times
 
 External library support:
 
@@ -1798,6 +1799,7 @@ AVDEVICE_COMPONENTS="
 
 AVFILTER_COMPONENTS="
 filters
+extra_filters
 "
 
 AVFORMAT_COMPONENTS="
@@ -4382,6 +4384,8 @@ do_random(){
 $action $(rand_list "$@" | awk "BEGIN { srand($random_seed) } \$1 == 
\"prob\" { prob = \$2; next } rand() < prob { print }")
 }
 
+rm -f ffbuild/extra-filters.txt
+
 # deprecated components (disabled by default)
 disable sonic_encoder sonic_ls_encoder
 
@@ -4457,6 +4461,10 @@ for opt do
 die_unknown $opt
 fi
 ;;
+--extra-filter=*)
+filter_path="${opt#--extra-filter=}"
+echo "$filter_path" >> ffbuild/extra-filters.txt
+;;
 --list-*)
 NAME="${opt#--list-}"
 is_in $NAME $COMPONENT_LIST || die_unknown $opt
@@ -4487,6 +4495,36 @@ for opt do
 esac
 done
 
+find_extra_filters_extern() {
+  # TODO: handle invalid filter
+  while read f; do
+jq -r '.symbols[]' < "$f/filter.json" | sed 
's/^ff_[avfsinkrc]\{2,5\}_\([[:alnum:]_]\{1,\}\)/\1_filter/'
+  done < ffbuild/extra-filters.txt
+}
+
+EXTRA_FILTER_LIST=$(find_extra_filters_extern)
+
+for n in extra_filters; do
+v=$(toupper ${n%s})_LIST
+eval enable \$$v
+eval ${n}_if_any="\$$v"
+done
+
+FILTER_LIST="
+$FIL

Re: [FFmpeg-devel] [PATCH 1/7] avcodec/pcm: Remove always-false check

2025-03-15 Thread Ramiro Polla



On 3/13/25 06:49, Andreas Rheinhardt wrote:

Patches attached.



[PATCH 2/7] avcodec/pcm: Cache sample_size value


diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 5d8dcb8ff0..620acf0f46 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -328,17 +335,14 @@ static int pcm_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 int buf_size   = avpkt->size;
 PCMDecode *s   = avctx->priv_data;
 int channels   = avctx->ch_layout.nb_channels;
-int sample_size, c, n, ret, samples_per_block;
+int sample_size = s->sample_size, c, n, ret, samples_per_block;
 uint8_t *samples;
 int32_t *dst_int32_t;


Could you put sample_size on its own line? It gets a little confusing 
with the first variable being initialized, but the subsequent variables 
being uninitialized.



[PATCH 3/7] avcodec/pcm: Remove duplication from FFCodec define macros


diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 620acf0f46..6c1feecca3 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c

[...]

+//   AV_CODEC_ID_*   pcm_* name
+// AV_SAMPLE_FMT_*   long name
+PCM_CODEC  (ALAW, S16, alaw, "PCM A-law / G.711 A-law");
+PCM_DECODER(F16LE,FLT, f16le,"PCM 16.8 floating point 
little-endian");


The labels don't align with the fields.

And in the next patch ([PATCH 4/7] avcodec/pcm: Don't allocate LUT when 
unused), with the introduction of PCM_CODEC_EXT(), the alignment of 
PCM_CODEC/PCM_DECODER/PCM_CODEC_EXT is lost.


Ramiro

___
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 v4 15/16] FFHWAccel: add buffer_ref argument to start_frame

2025-03-15 Thread Lynne




On 13/03/2025 23:08, Andreas Rheinhardt wrote:

Lynne:

This commit adds a reference to the buffer as an argument to
start_frame, and adapts all existing code.

This allows for asynchronous hardware accelerators to skip
copying packet data by referencing it.
---
  
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c

index da8fdc5935..20ef821819 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3401,7 +3401,10 @@ static int hevc_frame_start(HEVCContext *s, 
HEVCLayerContext *l,
  goto fail;
  
  if (s->avctx->hwaccel) {

-ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
+AVCodecInternal *avci = s->avctx->internal;
+AVPacket *avpkt = avci->in_pkt;
+ret = FF_HW_CALL(s->avctx, start_frame,
+ avpkt->buf, NULL, 0);
  if (ret < 0)
  goto fail;
  }
diff --git a/libavcodec/hwaccel_internal.h b/libavcodec/hwaccel_internal.h
index 77df4e0904..4eb74f0b34 100644
--- a/libavcodec/hwaccel_internal.h
+++ b/libavcodec/hwaccel_internal.h
@@ -52,11 +52,13 @@ typedef struct FFHWAccel {
   * Otherwise, this means the whole frame is available at this point.
   *
   * @param avctx the codec context
+ * @param buf_ref the frame data buffer reference (optional)
   * @param buf the frame data buffer base
   * @param buf_size the size of the frame in bytes
   * @return zero if successful, a negative value otherwise
   */
-int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t 
buf_size);
+int (*start_frame)(AVCodecContext *avctx, AVBufferRef *buf_ref,


const AVBufferRef*, we are not passing ownership


Done locally.


Why did you not make this the last parameter (given that only very few
hwaccels will access it)?


It made more sense to have it upfront as it backs up the data given.
I can change it, but I'd rather not, unless you have a strong opinion.


+   const uint8_t *buf, uint32_t buf_size);
  
  /**

   * Callback for parameter data (SPS/PPS/VPS etc).
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index bd1b502e50..f3d940671e 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -808,7 +808,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
  if (!s->hwaccel_picture_private)
  return AVERROR(ENOMEM);
  
-ret = hwaccel->start_frame(s->avctx, s->raw_image_buffer,

+ret = hwaccel->start_frame(s->avctx, NULL, s->raw_image_buffer,
 s->raw_image_buffer_size);
  if (ret < 0)
  return ret;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index ffe0710470..c21f220680 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1361,7 +1361,7 @@ static int mpeg_field_start(Mpeg1Context *s1, const 
uint8_t *buf, int buf_size)
  }
  
  if (avctx->hwaccel) {

-if ((ret = FF_HW_CALL(avctx, start_frame, buf, buf_size)) < 0)
+if ((ret = FF_HW_CALL(avctx, start_frame, NULL, buf, buf_size)) < 0)
  return ret;
  } else if (s->codec_tag == MKTAG('V', 'C', 'R', '2')) {
  // Exchange UV
diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c
index 6b408edb87..9b9be702d5 100644
--- a/libavcodec/nvdec_vp9.c
+++ b/libavcodec/nvdec_vp9.c
@@ -29,7 +29,8 @@
  #include "internal.h"
  #include "vp9shared.h"
  
-static int nvdec_vp9_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)

+static int nvdec_vp9_start_frame(AVCodecContext *avctx, AVBufferRef 
*buffer_ref,
+ const uint8_t *buffer, uint32_t size)
  {
  VP9SharedContext *h = avctx->priv_data;
  const AVPixFmtDescriptor *pixdesc = 
av_pix_fmt_desc_get(avctx->sw_pix_fmt);
diff --git a/libavcodec/proresdec.c b/libavcodec/proresdec.c
index 01caa611a0..edc46e1442 100644
--- a/libavcodec/proresdec.c
+++ b/libavcodec/proresdec.c
@@ -793,7 +793,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
  
  if (HWACCEL_MAX && avctx->hwaccel) {

  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
-ret = hwaccel->start_frame(avctx, NULL, 0);
+ret = hwaccel->start_frame(avctx, avpkt->buf, NULL, 0);


Passing an AVBufferRef for NULL data seems fishy.


I misinterpreted what NULL means.
Changed this to be NULL.
___
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/3] avcodec/{h263, ituh263, msmpeg4, snow}dec: Use proper, logcontext

2025-03-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Patches attached
> 
> - Andreas
> 
Will apply this patchset tomorrow unless there are objections.

- 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] ffbuild: read library linker objects from a file

2025-03-15 Thread Gyan Doshi



On 2025-03-12 03:12 pm, Martin Storsjö wrote:

On Wed, 12 Mar 2025, Gyan Doshi wrote:


On 2025-03-12 01:29 pm, Martin Storsjö wrote:

On Wed, 12 Mar 2025, Gyan Doshi wrote:


The linker command can exceed the maximum argument limit on MinGW,
especially for libavcodec.

The objects list is now stored in a file and passed to the linker.
---
ffbuild/library.mak | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ffbuild/library.mak b/ffbuild/library.mak
index 793e9d41fa..781b018e00 100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@ -66,8 +66,10 @@ $(SUBDIR)$(SLIBNAME): 
$(SUBDIR)$(SLIBNAME_WITH_MAJOR)


$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SHLIBOBJS) $(SLIBOBJS) 
$(SUBDIR)lib$(NAME).ver

$(SLIB_CREATE_DEF_CMD)
-    $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) $$(filter 
%.o,$$^) $(FFEXTRALIBS)

+    $(Q)echo $$(filter %.o,$$^) > $$@.objs
+    $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) @$$@.objs 
$(FFEXTRALIBS)

$(SLIB_EXTRA_CMD)
+    -$(RM) $$@.objs


Don't we need do the same for static libraries too?

On first glance, this looks quite reasonable... However, the limit 
that is an issue is the length of a command line. The .objs file is 
written with an "echo" command - doesn't that fundamentally also hit 
the same limit (just a little bit later, as there are fewer command 
line flags in this command)?


Or do we assume that make executes it with a shell, where the shell 
handles "echo" as a shell builtin so that it doesn't actually spawn 
a subprocess for this? Can you test it, if you could extend the list 
of object files to the point where the .objs file is clearly over 32 
KB, and verify that it did include all the files you intended?


The specific error I got when building a shared build of 7.1.1 (with 
~90 external libs) was


/bin/sh: line 1: /mingw64/bin/ccache: Argument list too long

Got same error without ccache.

The static build of the same config succeeded without any patching.
The .objs file generated for libavcodec shared build is 29KB.

How do I inflate the size to above 32K? I've enabled pretty much 
everything I can.


The simplest would probably be to add a bunch of empty .c files (with 
long file names) in libavcodec and hook them up in the makefile. We 
won't notice if they are missed when linking of course, but if we pass 
the command line length limit, we should still notice it in one way or 
another.


I did something simpler. I just duplicated the arg on the echo line. The 
build was successful. Each objs file was twice as big, same for the 
generated DLL.

Does that answer your queries?

Regards,
Gyan

___
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] [RFC] FFV1 float support

2025-03-15 Thread Jerome Martinez

Le 06/03/2025 à 17:37, Michael Niedermayer a écrit :

On Thu, Mar 06, 2025 at 03:14:49AM +0100, Lynne wrote:

On 06/03/2025 01:15, Michael Niedermayer wrote:

Hi everyone

Current FFv1 code with my patchset supports 16bit floats. The implementation
is quite simple. Which is good

I have tried improving compression, the gains are incremental, but its not
large overall. For example 44% space gain on the remapping table is just
0.1% overall.

I have few float samples. Its mainly one high quality slideshow of unrelated
16bit float images. These excercise a wide range fo things including negative
color values.
I think I have only one single (non slideshow) video of float 16 samples,

It turns out the most efficient way to store floats that i found, is to remap
them to integers. Not to store tham as sign, exponent, mantisse, i tried that
for many hours.


I also tried some stuff but IMO the remap to integer is what is 
currently the best for keeping the spec simple & with a good 
compression, and a more complex way is not needed until we find 
something which really makes a difference in term of compression ratio.
So let's keep it simple, just a remap to int, and we already get all the 
advantage of e.g. the incoming GPU implementation.




[...]
What about the mapping itself, it uses a rather simple rle coder. ive spend
most of the day today tuning that and failing to really beat that.
Using context from the previous image didnt work with the slideshow material
i have nor that one video i have. I tried using sign and exponent as context,
tried previous run, relations of runs, low bits and many more, but no or
insignificant improvments of yesterdays implementation was achieved.

I did mention this once before, but you should look into the Daala/Opus way
of storing rawbits into a separate chunk at the end of the bitstream. It
avoids polluting the range context with equiprobable bits.

This may fit into my LSB work but that is not float specific and its not
needed for float support.

I originally thought we would do floats through RAW storing LSB, and special
handling the "always" 0 and 1 bits. It makes sense but just remapping only
the used values to a compact list eliminates all the constant bits for free
and we never have more than 16bits per sample

We still can implement storing LSB raw, i have written 2 implementations
the first without range coder was this:
https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2024-October/334718.html

I didnt like it, but it seems more popular


I am still in favor of this simple and independent way to store the LSB 
bits, the other tentatives seem to only add complexity and performance 
issues while not providing enough gain.





Also given the raw bits are a known and constant length. It could make
sense to put them first if they are stored non interleaved.


Putting them last is better IMO, we can compute the byte offset with the 
constant length while storing some config in the slice header.

Actually, there are many possibilities, I suggest:
- permitting both MSB & LSB, because we may have MSB 0 and we would no 
store them (see below)
- after the count of bits not compressed, we add a flag indicating if we 
store them or not (meaning they are 0)
- permitting a configuration per stream (Configuration Record) or per 
slice (Slice Header); if a decision is to keep only one place for 
keeping it simple, it would be in the slice header.


The rational is that we may have:
- 0 padding for the LSB is when we compress integer from DCP, we have 
input with 16-bit TIFF but only 12 relevant bits, and we need to keep 
the bit depth of 16-bit if we want to say that we do it lossless and 
that we can reverse, especially because 99.999% of frames are with 4 
bits of padding but you may have a frame for whatever reason (often a 
bug, but if we do lossless we need to store buggy frames) which is not 
0, so a performant storage of 0-filled LSB while permitting to store the 
actual bits if not 0.
- 0 padding for the MSB is when we compress float mapped to integer and 
float range is from 0.0 to 1.0 only, sign & most of mantissa are always 
0 so we can store them as a flag, but we prepare the stream to have 
values out of range (<0 or > 1).

- and we don't know that before we start to compress each frame/slice

Would you accept something like:
- start of the Range Coder
- current slice header
- flag indicating the usage of bits not compressed
- if this flag is 1,
  - count of MSB not compressed
  - flag indicating if the MSB bitfield is not stored i.e. 0-padding
  - count of LSB not compressed
  - flag indicating if the LSB bitfield is not stored i.e. 0-padding
- current slice content
- current slice footer
- end of the Range Coder
- MSB bitfield if relevant
- LSB bitfield if relevant



[...]
That said the LSB patch still isnt needed for float support, it could
improve speed at the expense of compression for 16 and 32bit samples (float or 
other)


Advantage of remap of float to integer is 

Re: [FFmpeg-devel] [PATCH FFmpeg 1/15] libavutil: add detectionbbox util functions

2025-03-15 Thread Lynne

On 08/03/2025 15:58, m.kaindl0...@gmail.com wrote:

Those functions will be used by classify in the upcoming patches.

Try the new filters using my Github Repo 
https://github.com/MaximilianKaindl/DeepFFMPEGVideoClassification.

Any Feedback is appreciated!

Signed-off-by: MaximilianKaindl 
---
  libavutil/detection_bbox.c | 54 ++
  libavutil/detection_bbox.h | 31 ++
  2 files changed, 85 insertions(+)

diff --git a/libavutil/detection_bbox.c b/libavutil/detection_bbox.c index 
cb157b355b..378233121d 100644
--- a/libavutil/detection_bbox.c
+++ b/libavutil/detection_bbox.c
@@ -18,6 +18,7 @@
  
  #include "detection_bbox.h"

  #include "mem.h"
+#include "libavutil/avstring.h"
  
  AVDetectionBBoxHeader *av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size)  { @@ -71,3 +72,56 @@ AVDetectionBBoxHeader *av_detection_bbox_create_side_data(AVFrame *frame, uint32
  
  return header;

  }
+
+int av_detection_bbox_fill_with_best_labels(char **labels, float
+*probabilities, int num_labels, AVDetectionBBox *bbox, int 
max_classes_per_box, float confidence_threshold) {
+int i, j, minpos, ret;
+float min;
+
+if (!labels || !probabilities || !bbox) {
+return AVERROR(EINVAL);
+}
+
+for (i = 0; i < num_labels; i++) {
+if (probabilities[i] >= confidence_threshold) {
+if (bbox->classify_count >= max_classes_per_box) {
+// Find lowest probability classification
+min = av_q2d(bbox->classify_confidences[0]);
+minpos = 0;
+for (j = 1; j < bbox->classify_count; j++) {
+float prob = av_q2d(bbox->classify_confidences[j]);
+if (prob < min) {
+min = prob;
+minpos = j;
+}
+}
+
+if (probabilities[i] > min) {
+ret = av_detection_bbox_set_content(bbox, labels[i], 
minpos, probabilities[i]);
+if (ret < 0)
+return ret;
+}
+} else {
+ret = av_detection_bbox_set_content(bbox, labels[i], 
bbox->classify_count, probabilities[i]);
+if (ret < 0)
+return ret;
+bbox->classify_count++;
+}
+}
+}
+return 0;
+}
+
+int av_detection_bbox_set_content(AVDetectionBBox *bbox, char *label,
+int index, float probability) {
+// Set probability
+bbox->classify_confidences[index] = av_make_q((int)(probability *
+1), 1);
+
+// Copy label with size checking
+if (av_strlcpy(bbox->classify_labels[index], label, 
AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE) >=
+AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE) {
+av_log(NULL, AV_LOG_WARNING, "Label truncated in 
set_prob_and_label_of_bbox\n");
+}
+
+return 0;
+}
diff --git a/libavutil/detection_bbox.h b/libavutil/detection_bbox.h index 
011988052c..27d749ad59 100644
--- a/libavutil/detection_bbox.h
+++ b/libavutil/detection_bbox.h
@@ -105,4 +105,35 @@ AVDetectionBBoxHeader *av_detection_bbox_alloc(uint32_t 
nb_bboxes, size_t *out_s
   * AV_FRAME_DATA_DETECTION_BBOXES and initializes the variables.
   */
  AVDetectionBBoxHeader *av_detection_bbox_create_side_data(AVFrame *frame, 
uint32_t nb_bboxes);
+
+/**
+ * Fills an AVDetectionBBox structure with the best labels based on 
probabilities.
+ *
+ * This function selects up to max_classes_per_box labels with the
+highest probabilities
+ * that exceed the given confidence threshold, and assigns them to the 
bounding box.
+ *
+ * @param labels Array of label strings
+ * @param probabilities Array of probability values corresponding to
+each label
+ * @param num_labels Number of elements in the labels and probabilities
+arrays
+ * @param bbox Pointer to the AVDetectionBBox structure to be filled
+ * @param max_classes_per_box Maximum number of classes to assign to
+the bounding box
+ * @param confidence_threshold Minimum probability value required for a
+label to be considered
+ * @return 0 on success, negative error code on failure  */ int
+av_detection_bbox_fill_with_best_labels(char **labels, float
+*probabilities, int num_labels, AVDetectionBBox *bbox, int
+max_classes_per_box, float confidence_threshold);
+
+/**
+ * Sets the content of an AVDetectionBBox at the specified index.
+ *
+ * This function assigns a label and its associated probability to the
+specified index
+ * in the bounding box's internal storage.
+ *
+ * @param bbox Pointer to the AVDetectionBBox structure to modify
+ * @param label The class label to assign (will be copied internally)
+ * @param index The index at which to store the label and probability
+ * @param probability The confidence score/probability for this label
+ * @return 0 on success
+ */
+int av_detection_bbox_set_content(AVDetectionBBox *bbox, char *label,
+int index, float probability);


This is outsid

Re: [FFmpeg-devel] [PATCH v6 4/8] fftools/ffmpeg_filter: Move some declaration to new header file

2025-03-15 Thread Stefano Sabatini
On date Saturday 2025-03-08 20:16:30 +, softworkz wrote:
> From: softworkz 
> 
> to allow print_graph to access the information.
> 
> Signed-off-by: softworkz 
> ---
>  fftools/ffmpeg_filter.c | 188 +---
>  fftools/ffmpeg_filter.h | 232 
>  2 files changed, 233 insertions(+), 187 deletions(-)
>  create mode 100644 fftools/ffmpeg_filter.h

Looks good to me.
___
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/6] avformat/flvdec: Put FLVMetaVideoColor inside FLVContext directly

2025-03-15 Thread Zhao Zhili
From: Zhao Zhili 

1. Rename metaVideoColor to meta_color_info
2. Allocated FLVMetaVideoColor together with FLVContext
3. Improve the use of meta_color_info_flag. Do a sequence of strcmp
only if meta_color_info_flag is FLV_COLOR_INFO_FLAG_PARSING.
4. Check return value of amf_parse_object().
---
 libavformat/flvdec.c | 37 -
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 7ea4275784..fcc8403db7 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -68,6 +68,12 @@ typedef struct FLVMetaVideoColor {
 FLVMasteringMeta mastering_meta;
 } FLVMetaVideoColor;
 
+enum FLVMetaColorInfoFlag {
+FLV_COLOR_INFO_FLAG_NONE = 0,
+FLV_COLOR_INFO_FLAG_GOT = 1,
+FLV_COLOR_INFO_FLAG_PARSING = 2,
+};
+
 typedef struct FLVContext {
 const AVClass *class; ///< Class for private options.
 int trust_metadata;   ///< configure streams according onMetaData
@@ -102,8 +108,8 @@ typedef struct FLVContext {
 int64_t time_offset;
 int64_t time_pos;
 
-FLVMetaVideoColor *metaVideoColor;
-int meta_color_info_flag;
+FLVMetaVideoColor meta_color_info;
+enum FLVMetaColorInfoFlag meta_color_info_flag;
 
 uint8_t **mt_extradata;
 int *mt_extradata_sz;
@@ -600,7 +606,6 @@ static int amf_parse_object(AVFormatContext *s, AVStream 
*astream,
 FLVContext *flv = s->priv_data;
 AVIOContext *ioc;
 AMFDataType amf_type;
-FLVMetaVideoColor *meta_video_color = flv->metaVideoColor;
 char str_val[1024];
 double num_val;
 amf_date date;
@@ -749,7 +754,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream 
*astream,
 }
 }
 
-if (meta_video_color) {
+if (flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_PARSING) {
+FLVMetaVideoColor *meta_video_color = &flv->meta_color_info;
+
 if (amf_type == AMF_DATA_TYPE_NUMBER ||
 amf_type == AMF_DATA_TYPE_BOOL) {
 if (!strcmp(key, "colorPrimaries")) {
@@ -943,7 +950,6 @@ static int flv_read_close(AVFormatContext *s)
 av_freep(&flv->mt_extradata_sz);
 av_freep(&flv->keyframe_times);
 av_freep(&flv->keyframe_filepositions);
-av_freep(&flv->metaVideoColor);
 return 0;
 }
 
@@ -1183,6 +1189,7 @@ static int resync(AVFormatContext *s)
 
 static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, 
int64_t next_pos)
 {
+int ret;
 FLVContext *flv = s->priv_data;
 AMFDataType type;
 AVIOContext *ioc;
@@ -1200,19 +1207,22 @@ static int flv_parse_video_color_info(AVFormatContext 
*s, AVStream *st, int64_t
 return TYPE_UNKNOWN;
 }
 
-av_free(flv->metaVideoColor);
-if (!(flv->metaVideoColor = av_mallocz(sizeof(FLVMetaVideoColor {
-return AVERROR(ENOMEM);
+flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_PARSING;
+ret = amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse 
metadata
+if (ret < 0) {
+flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
+return ret;
 }
-flv->meta_color_info_flag = 1;
-amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
+
+flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_GOT;
+
 return 0;
 }
 
 static int flv_update_video_color_info(AVFormatContext *s, AVStream *st)
 {
 FLVContext *flv = s->priv_data;
-const FLVMetaVideoColor* meta_video_color = flv->metaVideoColor;
+const FLVMetaVideoColor* meta_video_color = &flv->meta_color_info;
 const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta;
 
 int has_mastering_primaries, has_mastering_luminance;
@@ -1735,9 +1745,10 @@ retry_duration:
 goto leave;
 }
 
-if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO && 
flv->meta_color_info_flag) {
+if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO &&
+flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_GOT) {
 flv_update_video_color_info(s, st); // update av packet side 
data
-flv->meta_color_info_flag = 0;
+flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
 }
 
 if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
-- 
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] FFmpeg 4.4.6 and 4.2.11

2025-03-15 Thread Michael Niedermayer
On Wed, Mar 12, 2025 at 02:17:32PM +0100, Michael Niedermayer wrote:
> On Mon, Mar 03, 2025 at 02:10:49AM +0100, Michael Niedermayer wrote:
> > Hi all
> > 
> > As ive already backported and somewhat tested release/4.3 i intend to
> > make the next point release from that and after that next is
> > 3.4 (because its the supported branch that is longest without a release)
> > 
> > like always, please backport things if you want something backported
> > please test, if you want something tested
> > and tell me if theres anything i need to know (like waiting for something)
> 
> 4.3.9 released, 3.4.14 is next

3.4.14 released a few days ago too

next is 4.4.6 and 4.2.11

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


Re: [FFmpeg-devel] [PATCH 00/12] avcodec/sanm: various improvements

2025-03-15 Thread Michael Niedermayer
On Fri, Mar 14, 2025 at 08:07:08AM +0100, Manuel Lauss wrote:
> Hi Michael,
> 
> On Fri, Mar 14, 2025 at 1:06 AM Michael Niedermayer
>  wrote:
> >
> > Hi Manuel
> >
> > please add yourself to the MAINTAINER file for sanm with a patch
> > you are already maintaining sanm, its just not written in the file
> 
> Fine, I'll add a patch for this in a v2 patchset.

thanks

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

Many things microsoft did are stupid, but not doing something just because
microsoft did it is even more stupid. If everything ms did were stupid they
would be bankrupt already.


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 4/4] avcodec/ffv1enc_template: Be a bit more verbose on error

2025-03-15 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ffv1enc_template.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index d8160282b2e..8b2d938770f 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -39,12 +39,12 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc,
 
 if (ac != AC_GOLOMB_RICE) {
 if (c->bytestream_end - c->bytestream < w * 35) {
-av_log(logctx, AV_LOG_ERROR, "encoded frame too large\n");
+av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too 
large\n");
 return AVERROR_INVALIDDATA;
 }
 } else {
 if (put_bytes_left(&sc->pb, 0) < w * 4) {
-av_log(logctx, AV_LOG_ERROR, "encoded frame too large\n");
+av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too 
large\n");
 return AVERROR_INVALIDDATA;
 }
 }
-- 
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] avfilter: POC: enable out-of-tree filters

2025-03-15 Thread Michael Niedermayer
Hi

On Thu, Mar 13, 2025 at 01:18:49PM +0100, Leandro Santiago wrote:
> This is a POC/prototype that aims to enable out of tree filters on
> FFmpeg.
> 
> Here I name them "extra filters".
> 

> It introduces the program `jq` as a new build dependency.

I dont think this dependency is needed to achieve linking to filters
in another directory
i think its worth the few hours extra time to find a clean/nice way to do it
with no new depeandancies

also there is the quite intriguing option of using "git merge" to include
external filters
What i mean here is that there could be a script lets call it ffmerge

"ffmerge available" would check some online repository and list whats
compatible with the current checkout

"ffmerge merge shiny_filter" would then merge the shiny filter repository/branch

Advanatge would be that this is more powerfull than just linking external
filters.
Disadvantage is that for this to work care needs to be taken that conflicts
do not occur

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire


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 v3 3/4] fftools: Provide a log formatting callback for context prefixes

2025-03-15 Thread softworkz
From: softworkz 

This allows to print logical ids instead of memory addresses.
The benefits are:

- Smaller log file sizes
- The disambiguation is much easier to recognize and to follow
- It eventually allows comparing and viewing log file diffs
  without almost every line being different due to those addresses
---
 fftools/cmdutils.c | 69 ++
 fftools/cmdutils.h |  5 
 fftools/ffmpeg.c   |  1 +
 fftools/ffplay.c   |  1 +
 fftools/ffprobe.c  |  1 +
 5 files changed, 77 insertions(+)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 8ac20bf049..9f93eb6523 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -59,6 +59,56 @@ AVDictionary *format_opts, *codec_opts;
 
 int hide_banner = 0;
 
+static int nb_class_ids;
+
+#define NB_CLASS_IDS 1000
+static struct class_ids {
+void *avcl;
+uint64_t class_hash;
+unsigned id;
+} class_ids[NB_CLASS_IDS];
+
+static uint64_t fnv_hash(const char *str)
+{
+// FNV-1a 64-bit hash algorithm
+uint64_t hash = 0xcbf29ce484222325ULL;
+while (*str) {
+hash ^= (unsigned char)*str++;
+hash *= 0x10001b3ULL;
+}
+return hash;
+}
+
+static unsigned get_class_id(void* avcl)
+{
+AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
+const char* class_name = avc->item_name(avcl);
+unsigned i, nb_ids = 0;
+uint64_t class_hash;
+
+for (i = 0; i < NB_CLASS_IDS && class_ids[i].avcl; i++) {
+if (class_ids[i].avcl == avcl)
+return class_ids[i].id;
+}
+
+class_hash = fnv_hash(avc->class_name);
+
+for (i = 0; i < NB_CLASS_IDS; i++) {
+if (class_ids[i].class_hash == class_hash)
+nb_ids++;
+
+if (!class_ids[i].avcl) {
+class_ids[i].avcl = avcl;
+class_ids[i].class_hash = class_hash;
+class_ids[i].id = nb_ids;
+return class_ids[i].id;
+}
+}
+
+// exceeded NB_CLASS_IDS entries in class_ids[]
+return 0;
+}
+
 void uninit_opts(void)
 {
 av_dict_free(&swr_opts);
@@ -550,6 +600,25 @@ static void check_options(const OptionDef *po)
 }
 }
 
+static const char *item_name(void *obj, const AVClass *cls)
+{
+return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
+}
+
+static void log_formatprefix_callback(AVBPrint* buffer, AVClass** avcl, int 
log_flags)
+{
+const int print_mem = log_flags & AV_LOG_PRINT_MEMADDRESSES;
+if (print_mem)
+av_bprintf(buffer+0, "[%s @ %p] ", item_name(avcl, *avcl), avcl);
+else
+av_bprintf(buffer+0, "[%s #%u] ", item_name(avcl, *avcl), 
get_class_id(avcl));
+}
+
+void init_logformatting(void)
+{
+av_log_set_formatprefix_callback(&log_formatprefix_callback);
+}
+
 void parse_loglevel(int argc, char **argv, const OptionDef *options)
 {
 int idx;
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 316b6a8c64..182d894ff9 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -401,6 +401,11 @@ int split_commandline(OptionParseContext *octx, int argc, 
char *argv[],
  */
 void uninit_parse_context(OptionParseContext *octx);
 
+/**
+ * Sets up formatting callbacks for logging
+ */
+void init_logformatting(void);
+
 /**
  * Find the '-loglevel' option in the command line args and apply it.
  */
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index dc321fb4a2..f84a7024be 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -955,6 +955,7 @@ int main(int argc, char **argv)
 setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
 
 av_log_set_flags(AV_LOG_SKIP_REPEATED);
+init_logformatting();
 parse_loglevel(argc, argv, options);
 
 #if CONFIG_AVDEVICE
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 2a572fc3aa..2e093c0069 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3762,6 +3762,7 @@ int main(int argc, char **argv)
 init_dynload();
 
 av_log_set_flags(AV_LOG_SKIP_REPEATED);
+init_logformatting();
 parse_loglevel(argc, argv, options);
 
 /* register all codecs, demux and protocols */
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 7341731d2f..3a9f2128fd 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -4652,6 +4652,7 @@ int main(int argc, char **argv)
 init_dynload();
 
 av_log_set_flags(AV_LOG_SKIP_REPEATED);
+init_logformatting();
 
 options = real_options;
 parse_loglevel(argc, argv, options);
-- 
ffmpeg-codebot

___
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 00/31] Major library soname bump

2025-03-15 Thread Andreas Rheinhardt
James Almer:
> It's been a year since the last bump, so lets get rid of old deprecated API
> in time for ffmpeg 8.0
> 
Two more patches.

- Andreas
From 1c0532d20ce6f56902c94913dc6d8b5d7a714de9 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt 
Date: Sat, 15 Mar 2025 22:10:44 +0100
Subject: [PATCH 1/2] avutil/dict: Unavpriv avpriv_dict_set_timestamp()

And move it to lavf, its only user.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/flvdec.c  |  3 +--
 libavformat/ifv.c |  3 +--
 libavformat/internal.h| 11 +++
 libavformat/matroskadec.c |  3 +--
 libavformat/mov.c |  3 +--
 libavformat/mux_utils.c   |  3 +--
 libavformat/mxfdec.c  |  3 +--
 libavformat/utils.c   | 19 +++
 libavutil/dict.c  | 18 --
 libavutil/dict_internal.h | 37 -
 10 files changed, 36 insertions(+), 67 deletions(-)
 delete mode 100644 libavutil/dict_internal.h

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index c51f64a588..b90ed34b1c 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -28,7 +28,6 @@
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/dict.h"
-#include "libavutil/dict_internal.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include "libavutil/internal.h"
@@ -826,7 +825,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
   ) {
 // timezone is ignored, since there is no easy way to offset the UTC
 // timestamp into the specified timezone
-avpriv_dict_set_timestamp(&s->metadata, key, 1000 * (int64_t)date.milliseconds);
+ff_dict_set_timestamp(&s->metadata, key, 1000 * (int64_t)date.milliseconds);
 }
 }
 
diff --git a/libavformat/ifv.c b/libavformat/ifv.c
index 0cfd2763a9..f0263ed3b4 100644
--- a/libavformat/ifv.c
+++ b/libavformat/ifv.c
@@ -21,7 +21,6 @@
  */
 
 #include "libavutil/channel_layout.h"
-#include "libavutil/dict_internal.h"
 #include "avformat.h"
 #include "demux.h"
 #include "internal.h"
@@ -96,7 +95,7 @@ static int parse_header(AVFormatContext *s)
 uint32_t vid_magic;
 
 avio_skip(s->pb, 0x34);
-avpriv_dict_set_timestamp(&s->metadata, "creation_time", avio_rl32(s->pb) * 100LL);
+ff_dict_set_timestamp(&s->metadata, "creation_time", avio_rl32(s->pb) * 100LL);
 avio_skip(s->pb, 0x24);
 
 ifv->width = avio_rl16(s->pb);
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b909adf209..1cf162c2bd 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -651,4 +651,15 @@ int ff_match_url_ext(const char *url, const char *extensions);
 int ff_get_frame_filename(char *buf, int buf_size, const char *path,
   int64_t number, int flags);
 
+/**
+ * Set a dictionary value to an ISO-8601 compliant timestamp string.
+ *
+ * @param dict pointer to a pointer to a dictionary struct. If *dict is NULL
+ * a dictionary struct is allocated and put in *dict.
+ * @param key metadata key
+ * @param timestamp unix timestamp in microseconds
+ * @return <0 on error
+ */
+int ff_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index efa3e44c85..d4b7ae112c 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -38,7 +38,6 @@
 #include "libavutil/base64.h"
 #include "libavutil/bprint.h"
 #include "libavutil/dict.h"
-#include "libavutil/dict_internal.h"
 #include "libavutil/display.h"
 #include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/intfloat.h"
@@ -2137,7 +2136,7 @@ static int matroska_aac_sri(int samplerate)
 static void matroska_metadata_creation_time(AVDictionary **metadata, int64_t date_utc)
 {
 /* Convert to seconds and adjust by number of seconds between 2001-01-01 and Epoch */
-avpriv_dict_set_timestamp(metadata, "creation_time", date_utc / 1000 + 9783072LL);
+ff_dict_set_timestamp(metadata, "creation_time", date_utc / 1000 + 9783072LL);
 }
 
 static int matroska_parse_flac(AVFormatContext *s,
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 57d9364ea2..cb96521e81 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -32,7 +32,6 @@
 #include "libavutil/attributes.h"
 #include "libavutil/bprint.h"
 #include "libavutil/channel_layout.h"
-#include "libavutil/dict_internal.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
@@ -1858,7 +1857,7 @@ static void mov_metadata_creation_time(MOVContext *c, AVIOContext *pb, AVDiction
 return;
 }
 
-avpriv_dict_set_timestamp(metadata, "creation_time", time * 100);
+ff_dict_set_timestamp(metadata, "creation_time", time * 100);
 }
 }
 
diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c
index ed1242a6a2..86

Re: [FFmpeg-devel] [PATCH v4 00/16] Add a Vulkan compute based FFv1 hwaccel

2025-03-15 Thread Lynne

On 13/03/2025 18:03, Lynne wrote:

This series of commits adds a fully compliant version 3 and 4 hardware
accelerator code for FFv1 written in Vulkan.

Changes from the previous version:
  - Use the exported host_map code in hwcontext_vulkan.c
  - Add a buffer_ref argument to FFHWAccel.start_frame
  - Various optimizations in the shader code

Lynne (16):
   pixfmt: add AV_PIX_FMT_GBRAP32
   vulkan: rename ff_vk_set_descriptor_image to ff_vk_shader_update_img
   vulkan: add ff_vk_create_imageview
   vulkan: copy host-mapping buffer code from hwcontext
   hwcontext_vulkan: use the common host map function to map frame data
   vulkan: workaround BGR storage image undefined behaviour
   vulkan_decode: support software-defined decoders
   vulkan_decode: support multiple image views
   vulkan_decode: adjust number of async contexts created
   ffv1enc_vulkan: refactor shaders slightly to support sharing
   vulkan: unify handling of BGR and simplify ffv1_rct
   vulkan: add ff_vk_exec_add_dep_wait_sem()
   vulkan: add support for AV_PIX_FMT_GBRAP32
   ffv1dec: add support for hwaccels
   FFHWAccel: add buffer_ref argument to start_frame
   ffv1: add a Vulkan-based decoder

  configure |2 +
  libavcodec/Makefile   |3 +-
  libavcodec/av1dec.c   |3 +-
  libavcodec/d3d12va_av1.c  |5 +-
  libavcodec/d3d12va_h264.c |5 +-
  libavcodec/d3d12va_hevc.c |5 +-
  libavcodec/d3d12va_mpeg2.c|5 +-
  libavcodec/d3d12va_vc1.c  |5 +-
  libavcodec/d3d12va_vp9.c  |5 +-
  libavcodec/dxva2_av1.c|1 +
  libavcodec/dxva2_h264.c   |1 +
  libavcodec/dxva2_hevc.c   |1 +
  libavcodec/dxva2_mpeg2.c  |1 +
  libavcodec/dxva2_vc1.c|1 +
  libavcodec/dxva2_vp9.c|1 +
  libavcodec/ffv1.h |2 +
  libavcodec/ffv1_vulkan.c  |  123 +++
  libavcodec/ffv1_vulkan.h  |   61 ++
  libavcodec/ffv1dec.c  |   87 +-
  libavcodec/ffv1enc_vulkan.c   |  236 ++---
  libavcodec/h263dec.c  |2 +-
  libavcodec/h264dec.c  |8 +-
  libavcodec/hevc/hevcdec.c |5 +-
  libavcodec/hwaccel_internal.h |4 +-
  libavcodec/hwaccels.h |1 +
  libavcodec/mjpegdec.c |2 +-
  libavcodec/mpeg12dec.c|2 +-
  libavcodec/nvdec_av1.c|4 +-
  libavcodec/nvdec_h264.c   |1 +
  libavcodec/nvdec_hevc.c   |1 +
  libavcodec/nvdec_mjpeg.c  |4 +-
  libavcodec/nvdec_mpeg12.c |3 +-
  libavcodec/nvdec_mpeg4.c  |3 +-
  libavcodec/nvdec_vc1.c|3 +-
  libavcodec/nvdec_vp8.c|3 +-
  libavcodec/nvdec_vp9.c|3 +-
  libavcodec/proresdec.c|2 +-
  libavcodec/vaapi_av1.c|1 +
  libavcodec/vaapi_h264.c   |1 +
  libavcodec/vaapi_hevc.c   |1 +
  libavcodec/vaapi_mjpeg.c  |1 +
  libavcodec/vaapi_mpeg2.c  |5 +-
  libavcodec/vaapi_mpeg4.c  |5 +-
  libavcodec/vaapi_vc1.c|5 +-
  libavcodec/vaapi_vp8.c|1 +
  libavcodec/vaapi_vp9.c|1 +
  libavcodec/vaapi_vvc.c|1 +
  libavcodec/vc1dec.c   |6 +-
  libavcodec/vdpau_av1.c|3 +-
  libavcodec/vdpau_h264.c   |1 +
  libavcodec/vdpau_hevc.c   |1 +
  libavcodec/vdpau_mpeg12.c |1 +
  libavcodec/vdpau_mpeg4.c  |1 +
  libavcodec/vdpau_vc1.c|1 +
  libavcodec/vdpau_vp9.c|3 +-
  libavcodec/videotoolbox.c |8 +-
  libavcodec/videotoolbox_av1.c |1 +
  libavcodec/videotoolbox_vp9.c |1 +
  libavcodec/vp8.c  |2 +-
  libavcodec/vp9.c  |2 +-
  libavcodec/vt_internal.h  |1 +
  libavcodec/vulkan/Makefile|6 +
  libavcodec/vulkan/common.comp |   95 ++
  libavcodec/vulkan/ffv1_common.comp|   25 +-
  libavcodec/vulkan/ffv1_dec.comp   |  290 ++
  libavcodec/vulkan/ffv1_dec_rct.comp   |   88 ++
  libavcodec/vulkan/ffv1_dec_setup.comp |  138 +++
  libavcodec/vulkan/ffv1_enc_rct.comp   |   17 +-
  libavcodec/vulkan/ffv1_enc_setup.comp |   18 +-
  libavcodec/vulkan/ffv1_rct.comp   |   90 ++
  libavcodec/vulkan/ffv1_reset.comp |3 +-
  libavcodec/vulkan/ffv1_vlc.comp   |   37 +
  libavcodec/vulkan/rangecoder.comp |  101 +-
  libavcodec/vulkan_av1.c   |5 +-
  libavcodec/vulkan_decode.c|  257 +++--
  libavcodec/vulkan_decode.h|   23 +-
  libavcodec/vulkan_ffv1.c 

Re: [FFmpeg-devel] [PATCH 1/9] avcodec/msmpeg4enc: Inline constant

2025-03-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Patches attached.
> 
> - Andreas
> 
Will apply this patchset tomorrow unless there are objections.

- 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] avformat/avio: Add max_pkt_size option

2025-03-15 Thread Marton Balint



On Fri, 14 Mar 2025, Zhao Zhili wrote:





On Mar 14, 2025, at 04:03, Marton Balint  wrote:


On Thu, 13 Mar 2025, Zhao Zhili wrote:


From: Zhao Zhili 

Optimizing memory footprint in memory-constrained systems.

Signed-off-by: Zhao Zhili 
---
libavformat/avio.c| 2 ++
libavformat/version.h | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index d109f3adff..e1b959ed73 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -61,6 +61,8 @@ static const AVOption options[] = {
   {"protocol_whitelist", "List of protocols that are allowed to be used", 
OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, D },
   {"protocol_blacklist", "List of protocols that are not allowed to be used", 
OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, D },
   {"rw_timeout", "Timeout for IO operations (in microseconds)", 
offsetof(URLContext, rw_timeout), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, 
AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
+{"max_pkt_size", "Default maximum packet size in bytes, could be overwritten by 
particular protocol",
+offsetof(URLContext, max_packet_size), AV_OPT_TYPE_INT, { .i64 = 
IO_BUFFER_SIZE }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM | 
AV_OPT_FLAG_DECODING_PARAM },
   { NULL }
};



This feels super confusing. A *max_packet_size* option which might not do anything 
at all depending on the protocol the user is using, and which the user might 
override with the protocol specific *pkt_size* option if it exists. So I'd rather 
not expose ->max_pkt_size like that.


rw_timeout has the same issue, it’s still useful for users.


And it is confusing for the users when the -timeout option can/should be 
used and when -rw_timeout. Not to mention which one is in miliseconds, 
nanoseconds or seconds.


In general it is not nice from the users point of view that some options 
are allowed to be set when they are not actually supported, and the user 
have no feedback about it, that is why I'd rather go for the protocol 
specific options. And also since protocols are controlling this right now 
anyway.




The patch is for 


https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/341114.html


Yeah, I saw that, and to be honest, it is a bit suprising to me that 32k 
for IO buffer is too big for something that actually runs ffmpeg/avformat 
(which allocates a lot more RAM than that). So probably it would be nice 
to hear a bit more about the use case.




We can add pkt_size for more protocols, but it sounds weird for tcp
with pkt_size option.


You are right, pkt_size (or max_pkt_size) is not the right name for this. 
For example max_pkt_size conflicts with mpegts "max_pkt_size" option.




Use can change AVIOContext::max_packet_size directly. I’m not sure
if it’s better or valid.


AVIOContext struct unfortunately does not sepearte public and private 
fields, so there is no clear boundary...


Regards,
Marton





Regards,
Marton




diff --git a/libavformat/version.h b/libavformat/version.h
index 6ffdf61b43..e1ab967f5b 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
#include "version_major.h"

#define LIBAVFORMAT_VERSION_MINOR   9
-#define LIBAVFORMAT_VERSION_MICRO 107
+#define LIBAVFORMAT_VERSION_MICRO 108

#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
  LIBAVFORMAT_VERSION_MINOR, \
--
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 mailing list
ffmpeg-devel@ffmpeg.org 
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


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

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

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

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


Re: [FFmpeg-devel] [PATCH] swscale/swscale_unscaled: account for semi planar formats with data in the msb

2025-03-15 Thread James Almer

On 3/14/2025 11:52 AM, James Almer wrote:

Fixes fate failures introduced by recent tests that exercise the faulty code.

Signed-off-by: James Almer 
---
  libswscale/swscale_unscaled.c | 74 ++-
  tests/ref/pixfmt/p410-nv24|  2 +-
  tests/ref/pixfmt/p410-p412be  |  2 +-
  tests/ref/pixfmt/p410-p412le  |  2 +-
  tests/ref/pixfmt/p410-p416be  |  2 +-
  tests/ref/pixfmt/p410-p416le  |  2 +-
  tests/ref/pixfmt/p412-nv24|  2 +-
  tests/ref/pixfmt/p412-p410be  |  2 +-
  tests/ref/pixfmt/p412-p410le  |  2 +-
  tests/ref/pixfmt/p412-p416be  |  2 +-
  tests/ref/pixfmt/p412-p416le  |  2 +-
  11 files changed, 48 insertions(+), 46 deletions(-)


Will apply soon because FATE is too yellow without this.



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] avcodec/ffv1dec: set the FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM capability

2025-03-15 Thread James Almer
Will prevent decoding frame data during probing.

Signed-off-by: James Almer 
---
 libavcodec/ffv1dec.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index b731f11297..998b981a33 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -697,6 +697,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 if (ret < 0)
 return ret;
 
+if (avctx->skip_frame >= AVDISCARD_ALL)
+return avpkt->size;
+
 ret = ff_progress_frame_get_buffer(avctx, &f->picture,
AV_GET_BUFFER_FLAG_REF);
 if (ret < 0)
@@ -821,5 +824,6 @@ const FFCodec ff_ffv1_decoder = {
 .p.capabilities = AV_CODEC_CAP_DR1 |
   AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
 .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP |
+  FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
   FF_CODEC_CAP_USES_PROGRESSFRAMES,
 };
-- 
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] avcodec/ffv1dec: set the FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM capability

2025-03-15 Thread Lynne

On 15/03/2025 20:10, James Almer wrote:

Will prevent decoding frame data during probing.

Signed-off-by: James Almer 
---
  libavcodec/ffv1dec.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index b731f11297..998b981a33 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -697,6 +697,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
  if (ret < 0)
  return ret;
  
+if (avctx->skip_frame >= AVDISCARD_ALL)

+return avpkt->size;
+
  ret = ff_progress_frame_get_buffer(avctx, &f->picture,
 AV_GET_BUFFER_FLAG_REF);
  if (ret < 0)
@@ -821,5 +824,6 @@ const FFCodec ff_ffv1_decoder = {
  .p.capabilities = AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
  .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP |
+  FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
FF_CODEC_CAP_USES_PROGRESSFRAMES,
  };


LGTM, been running this locally for days now. Speeds up opening high 
resolution files by seconds.

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 2/5] avcodec/ffv1: Add YAF16 support

2025-03-15 Thread Michael Niedermayer
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ffv1_parse.c |  6 --
 libavcodec/ffv1dec.c|  4 ++--
 libavcodec/ffv1enc.c| 33 +
 3 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/libavcodec/ffv1_parse.c b/libavcodec/ffv1_parse.c
index a85b563e98b..a49f1eb6cef 100644
--- a/libavcodec/ffv1_parse.c
+++ b/libavcodec/ffv1_parse.c
@@ -294,9 +294,11 @@ int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, 
uint8_t *state)
 } else
 return AVERROR(ENOSYS);
 } else if (f->transparency && !f->chroma_planes) {
-if (f->avctx->bits_per_raw_sample <= 8)
+if (f->avctx->bits_per_raw_sample <= 8 && !f->flt) {
 f->pix_fmt = AV_PIX_FMT_YA8;
-else
+} else if (f->avctx->bits_per_raw_sample == 16 && f->flt) {
+f->pix_fmt = AV_PIX_FMT_YAF16;
+} else
 return AVERROR(ENOSYS);
 } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) {
 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index d702e36625a..e24c6b8d3a2 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -362,8 +362,8 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->transparency)
 decode_plane(f, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], 
width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 
2, 1, ac);
 } else if (f->colorspace == 0) {
- decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], 
width, height, p->linesize[0], 0, 0, 2, ac);
- decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, 
width, height, p->linesize[0], 1, 1, 2, ac);
+ decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] 
 , width, height, p->linesize[0], 0, 0, 2, ac);
+ decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 
(ps>>1), width, height, p->linesize[0], 1, 1, 2, ac);
 } else if (f->use32bit) {
 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
p->data[1] + ps * x + y * p->linesize[1],
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index b8ccda469ec..9fb98c37584 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -301,11 +301,11 @@ static int encode_plane(FFV1Context *f, FFV1SliceContext 
*sc,
 } else {
 if (f->packed_at_lsb) {
 for (x = 0; x < w; x++) {
-sample[0][x] = ((uint16_t*)(src + stride*y))[x];
+sample[0][x] = ((uint16_t*)(src + stride*y))[x * 
pixel_stride];
 }
 } else {
 for (x = 0; x < w; x++) {
-sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - 
f->bits_per_raw_sample);
+sample[0][x] = ((uint16_t*)(src + stride*y))[x * 
pixel_stride] >> (16 - f->bits_per_raw_sample);
 }
 }
 if (sc->remap)
@@ -334,10 +334,10 @@ static void load_plane(FFV1Context *f, FFV1SliceContext 
*sc,
 } else {
 if (f->packed_at_lsb) {
 for (x = 0; x < w; x++)
-sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x] 
] = 1;
+sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x * 
pixel_stride] ] = 1;
 } else {
 for (x = 0; x < w; x++)
-sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x] 
>> (16 - f->bits_per_raw_sample) ] = 1;
+sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x * 
pixel_stride] >> (16 - f->bits_per_raw_sample) ] = 1;
 }
 }
 }
@@ -842,6 +842,7 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext 
*avctx,
 case AV_PIX_FMT_YUVA444P16:
 case AV_PIX_FMT_YUVA422P16:
 case AV_PIX_FMT_YUVA420P16:
+case AV_PIX_FMT_YAF16:
 if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) {
 s->bits_per_raw_sample = 16;
 } else if (!s->bits_per_raw_sample) {
@@ -926,17 +927,16 @@ av_cold int 
ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
 if (s->bits_per_raw_sample >= 16) {
 s->use32bit = 1;
 }
-s->flt = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT);
 s->version = FFMAX(s->version, 1);
-
-if (s->flt)
-s->version = FFMAX(s->version, 4);
 break;
 default:
 av_log(avctx, AV_LOG_ERROR, "format %s not supported\n",
av_get_pix_fmt_name(pix_fmt));
 return AVERROR(ENOSYS);
 }
+s->flt = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT);
+if (s->flt)
+s->version = FFMAX(s->version, 4);
 av_assert0(s->bits_per_raw_sample >= 8);
 
 if (s->remap_mode < 0)
@@ -1225,7 +1225,7 @@ retry:
 

[FFmpeg-devel] [PATCH v2 01/13] avcodec/sanm: disable left/top for fullscreen codecs

2025-03-15 Thread Manuel Lauss
The block-based codecs 37/47/48 work on the full frame, and there's no
existing LucasArts game video that uses left/top offsets for these,
as it doesn't make sense. Ignore the left/top parameters for these codecs.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 32 +++-
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index a4f0a28c7c..49ac9bebfe 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -621,8 +621,7 @@ static inline void codec37_mv(uint8_t *dst, const uint8_t 
*src,
 }
 }
 
-static int old_codec37(SANMVideoContext *ctx, int top,
-   int left, int width, int height)
+static int old_codec37(SANMVideoContext *ctx, int width, int height)
 {
 int i, j, k, l, t, run, len, code, skip, mx, my;
 ptrdiff_t stride = ctx->pitch;
@@ -638,8 +637,8 @@ static int old_codec37(SANMVideoContext *ctx, int top,
 flags = bytestream2_get_byte(&ctx->gb);
 bytestream2_skip(&ctx->gb, 3);
 
-if (decoded_size > ctx->height * stride - left - top * stride) {
-decoded_size = ctx->height * stride - left - top * stride;
+if (decoded_size > ctx->height * stride) {
+decoded_size = ctx->height * stride;
 av_log(ctx->avctx, AV_LOG_WARNING, "Decoded size is too large.\n");
 }
 
@@ -649,8 +648,8 @@ static int old_codec37(SANMVideoContext *ctx, int top,
 FFSWAP(uint16_t*, ctx->frm1, ctx->frm2);
 }
 
-dst  = ((uint8_t*)ctx->frm1) + left + top * stride;
-prev = ((uint8_t*)ctx->frm2) + left + top * stride;
+dst  = ((uint8_t*)ctx->frm1);
+prev = ((uint8_t*)ctx->frm2);
 
 if (mvoff > 2) {
 av_log(ctx->avctx, AV_LOG_ERROR, "Invalid motion base value %d.\n", 
mvoff);
@@ -925,15 +924,14 @@ static void codec47_comp1(SANMVideoContext *ctx, uint8_t 
*dst_in, int width,
 }
 }
 
-static int old_codec47(SANMVideoContext *ctx, int top,
-   int left, int width, int height)
+static int old_codec47(SANMVideoContext *ctx, int width, int height)
 {
 uint32_t decoded_size;
 int i, j;
 ptrdiff_t stride = ctx->pitch;
-uint8_t *dst   = (uint8_t *)ctx->frm0 + left + top * stride;
-uint8_t *prev1 = (uint8_t *)ctx->frm1 + left + top * stride;
-uint8_t *prev2 = (uint8_t *)ctx->frm2 + left + top * stride;
+uint8_t *dst   = (uint8_t *)ctx->frm0;
+uint8_t *prev1 = (uint8_t *)ctx->frm1;
+uint8_t *prev2 = (uint8_t *)ctx->frm2;
 uint8_t auxcol[2];
 int tbl_pos = bytestream2_tell(&ctx->gb);
 int seq = bytestream2_get_le16(&ctx->gb);
@@ -947,8 +945,8 @@ static int old_codec47(SANMVideoContext *ctx, int top,
 decoded_size = bytestream2_get_le32(&ctx->gb);
 bytestream2_skip(&ctx->gb, 8);
 
-if (decoded_size > ctx->height * stride - left - top * stride) {
-decoded_size = ctx->height * stride - left - top * stride;
+if (decoded_size > ctx->height * stride) {
+decoded_size = ctx->height * stride;
 av_log(ctx->avctx, AV_LOG_WARNING, "Decoded size is too large.\n");
 }
 
@@ -959,8 +957,8 @@ static int old_codec47(SANMVideoContext *ctx, int top,
 }
 if (!seq) {
 ctx->prev_seq = -1;
-memset(prev1, auxcol[0], (ctx->height - top) * stride);
-memset(prev2, auxcol[1], (ctx->height - top) * stride);
+memset(prev1, auxcol[0], ctx->height * stride);
+memset(prev2, auxcol[1], ctx->height * stride);
 }
 
 switch (compr) {
@@ -1267,9 +1265,9 @@ static int process_frame_obj(SANMVideoContext *ctx)
 case 3:
 return old_codec1(ctx, top, left, w, h);
 case 37:
-return old_codec37(ctx, top, left, w, h);
+return old_codec37(ctx, w, h);
 case 47:
-return old_codec47(ctx, top, left, w, h);
+return old_codec47(ctx, w, h);
 case 48:
 return old_codec48(ctx, w, h);
 default:
-- 
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 v2 04/13] avcodec/sanm: better ANIMv1 engine support

2025-03-15 Thread Manuel Lauss
- clear the front buffer with color 0 on the first FOBJ.
  Fixes a lot of Rebel Assault 1 videos and Rebel Assault 2 space
  scenes (e.g. 08PLAY.SAN which consists only of codec1/2/21 objects
  which only ever touch parts of the buffer).
- for ANIMv1 (Rebel Assault 1): set palette index 0 to all zeroes.
  This fixes a lot of stray colors in e.g L1HANGAR.ANM, L2INTRO.ANM,
  space scenes.
- Esp in RA1, there are a lot of FRME objects which don't contain
  any video data (prebuffering some audio only). Account for that.
- In RA1 L2PLAY.ANM there are a few unaligned FOBJs, handle this
  in a generic way.

Signed-off-by: Manuel Lauss 
---
v2: added handling of unaligned objects

 libavcodec/sanm.c | 49 ++-
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 38cdb533eb..069bc0400a 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -264,7 +264,7 @@ typedef struct SANMVideoContext {
 AVCodecContext *avctx;
 GetByteContext gb;
 
-int version, subversion, have_dimensions;
+int version, subversion, have_dimensions, first_fob;
 uint32_t pal[PALETTE_SIZE];
 int16_t delta_pal[PALETTE_DELTA];
 
@@ -515,6 +515,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 ctx->subversion = AV_RL16(avctx->extradata);
 for (i = 0; i < PALETTE_SIZE; i++)
 ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4);
+if (ctx->subversion < 2)
+ctx->pal[0] = 0xFFU << 24;
 }
 
 return 0;
@@ -1298,6 +1300,15 @@ static int process_frame_obj(SANMVideoContext *ctx)
 }
 bytestream2_skip(&ctx->gb, 4);
 
+/* on first FOBJ, when the codec is not one of the
+ * full-buffer codecs (37/47/48), frm0 needs to be cleared.
+ */
+if (ctx->first_fob) {
+ctx->first_fob = 0;
+if (codec < 37)
+memset(ctx->frm0, 0, ctx->frm0_size);
+}
+
 switch (codec) {
 case 1:
 case 3:
@@ -1349,6 +1360,8 @@ static int process_xpal(SANMVideoContext *ctx, int size)
 if (size >= PALETTE_DELTA * 2 + 4 + PALETTE_SIZE * 3) {
 for (i = 0; i < PALETTE_SIZE; i++)
 ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
+if (ctx->subversion < 2)
+ctx->pal[0] = 0xFFU << 24;
 }
 }
 return 0;
@@ -1762,7 +1775,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 bytestream2_init(&ctx->gb, pkt->data, pkt->size);
 
 if (!ctx->version) {
-int to_store = 0;
+int to_store = 0, have_img = 0;
+
+ctx->first_fob = 1;
 
 while (bytestream2_get_bytes_left(&ctx->gb) >= 8) {
 uint32_t sig, size;
@@ -1785,12 +1800,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 }
 for (i = 0; i < PALETTE_SIZE; i++)
 ctx->pal[i] = 0xFFU << 24 | 
bytestream2_get_be24u(&ctx->gb);
+if (ctx->subversion < 2)
+ctx->pal[0] = 0xFFU << 24;
 break;
 case MKBETAG('F', 'O', 'B', 'J'):
 if (size < 16)
 return AVERROR_INVALIDDATA;
 if (ret = process_frame_obj(ctx))
 return ret;
+have_img = 1;
 break;
 case MKBETAG('X', 'P', 'A', 'L'):
 if (ret = process_xpal(ctx, size))
@@ -1801,6 +1819,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 break;
 case MKBETAG('F', 'T', 'C', 'H'):
 memcpy(ctx->frm0, ctx->stored_frame, ctx->buf_size);
+have_img = 1;
 break;
 default:
 bytestream2_skip(&ctx->gb, size);
@@ -1809,15 +1828,26 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 break;
 }
 
+/* the sizes of chunks are usually a multiple of 2. However
+ * there are a few unaligned FOBJs in RA1 L2PLAY.ANM only (looks
+ * like a game bug) and IACT audio chunks which have odd sizes
+ * but are padded with a zero byte.
+ */
 bytestream2_seek(&ctx->gb, pos + size, SEEK_SET);
-if (size & 1)
-bytestream2_skip(&ctx->gb, 1);
+if ((pos + size) & 1) {
+if (0 != bytestream2_get_byteu(&ctx->gb))
+bytestream2_seek(&ctx->gb, pos + size, SEEK_SET);
+}
 }
 if (to_store)
 memcpy(ctx->stored_frame, ctx->frm0, ctx->buf_size);
-if ((ret = copy_output(ctx, NULL)))
-return ret;
-memcpy(ctx->frame->data[1], ctx->pal, 1024);
+
+if (have_img && ctx->have_dimensions) {
+if ((ret = copy_output(ctx, NULL)))
+return ret;
+memcpy(ctx->frame->data[1], ctx->pal, 1024);
+  

[FFmpeg-devel] [PATCH 4/5] avcodec/ffv1enc: Fix signed type handling with remap

2025-03-15 Thread Michael Niedermayer
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ffv1enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 3879d1b19a1..b3fb6560e5a 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -310,7 +310,7 @@ static int encode_plane(FFV1Context *f, FFV1SliceContext 
*sc,
 }
 if (sc->remap)
 for (x = 0; x < w; x++)
-sample[0][x] = sc->fltmap[remap_index][ sample[0][x] ];
+sample[0][x] = sc->fltmap[remap_index][ 
(uint16_t)sample[0][x] ];
 
 if((ret = encode_line(f, sc, f->avctx, w, sample, plane_index, 
f->bits_per_raw_sample, ac, pass1)) < 0)
 return ret;
-- 
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 v2 08/13] avcodec/sanm: codec21 decoder

2025-03-15 Thread Manuel Lauss
similar to codec23, this one alternatingly skips and writes bytes.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index aca5bf49ec..6080144235 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -614,6 +614,49 @@ static int old_codec23(SANMVideoContext *ctx, int top, int 
left, int width,
 return 0;
 }
 
+static int old_codec21(SANMVideoContext *ctx, int top, int left, int width,
+   int height)
+{
+const uint32_t maxpxo = ctx->height * ctx->pitch;
+uint8_t *dst = (uint8_t *)ctx->frm0, c;
+int i, j, k, pc, sk, pxoff;
+
+dst = (uint8_t *)ctx->frm0;
+for (i = 0; i < height; i++) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+return 0;
+pxoff = left + ((top + i) * ctx->pitch);
+k = bytestream2_get_le16u(&ctx->gb);
+sk = 1;
+pc = 0;
+while (k > 0 && pc <= width) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+return AVERROR_INVALIDDATA;
+j = bytestream2_get_le16u(&ctx->gb);
+k -= 2;
+if (sk) {
+pxoff += j;
+pc += j;
+} else {
+if (bytestream2_get_bytes_left(&ctx->gb) < (j + 1))
+return AVERROR_INVALIDDATA;
+do {
+c = bytestream2_get_byteu(&ctx->gb);
+if (pxoff >=0 && pxoff < maxpxo) {
+*(dst + pxoff) = c;
+}
+pxoff++;
+pc++;
+j--;
+k--;
+} while (j > -1);
+}
+sk ^= 1;
+}
+}
+return 0;
+}
+
 static int old_codec1(SANMVideoContext *ctx, int top,
   int left, int width, int height, int opaque)
 {
@@ -1393,6 +1436,8 @@ static int process_frame_obj(SANMVideoContext *ctx)
 return old_codec1(ctx, top, left, w, h, codec == 3);
 case 2:
 return old_codec2(ctx, top, left, w, h);
+case 21:
+return old_codec21(ctx, top, left, w, h);
 case 23:
 return old_codec23(ctx, top, left, w, h, param, parm2);
 case 37:
-- 
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] ffmpeg: add per-stream input option drop_changed

2025-03-15 Thread Gyan Doshi
This is a replacement in ffmpeg for the deprecated avcodec flag 
AV_CODEC_FLAG_DROPCHANGED.

This option is meant to be used when the filtergraph should not be
reinited upon input parameter changes as that leads to loss of state
in the filtergraph potentially leading to broken or aborted output,
e.g. inserting of silence with first_pts specified in aresample.

Generally useful to avoid corrupted yet decodable packets in live
streaming inputs.

This option when enabled takes precedence over reinit_filters
---
 doc/ffmpeg.texi |  6 ++
 fftools/ffmpeg.h|  2 ++
 fftools/ffmpeg_demux.c  | 13 -
 fftools/ffmpeg_filter.c | 10 ++
 fftools/ffmpeg_opt.c|  3 +++
 5 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index fca220a334..a73db79f94 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1373,6 +1373,12 @@ The properties where a change triggers reinitialization 
are,
 for video, frame resolution or pixel format;
 for audio, sample format, sample rate, channel count or channel layout.
 
+@item -drop_changed[:@var{stream_specifier}] @var{integer} 
(@emph{input,per-stream})
+This boolean option determines whether a frame with differing frame parameters 
mid-stream
+gets dropped instead of leading to filtergraph reinitialization, as that would 
lead to loss
+of filter state. Generally useful to avoid corrupted yet decodable packets in 
live streaming
+inputs. Default is false.
+
 @item -filter_threads @var{nb_threads} (@emph{global})
 Defines how many threads are used to process a filter pipeline. Each pipeline
 will produce a thread pool with this many threads available for parallel 
processing.
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 86a3e10c6b..5869979214 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -232,6 +232,7 @@ typedef struct OptionsContext {
 SpecifierOptList filter_scripts;
 #endif
 SpecifierOptList reinit_filters;
+SpecifierOptList drop_changed;
 SpecifierOptList fix_sub_duration;
 SpecifierOptList fix_sub_duration_heartbeat;
 SpecifierOptList canvas_sizes;
@@ -262,6 +263,7 @@ enum IFilterFlags {
 IFILTER_FLAG_REINIT = (1 << 1),
 IFILTER_FLAG_CFR= (1 << 2),
 IFILTER_FLAG_CROP   = (1 << 3),
+IFILTER_FLAG_DROPCHANGED= (1 << 4),
 };
 
 typedef struct InputFilterOptions {
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index b8171e336e..292b718f14 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -67,6 +67,7 @@ typedef struct DemuxStream {
 int  reinit_filters;
 int  autorotate;
 int  apply_cropping;
+int  drop_changed;
 
 
 int  wrap_correction_done;
@@ -1099,7 +1100,8 @@ int ist_filter_add(InputStream *ist, InputFilter 
*ifilter, int is_simple,
 return AVERROR(ENOMEM);
 
 opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
-   IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
+   IFILTER_FLAG_REINIT * !!(ds->reinit_filters) |
+   IFILTER_FLAG_DROPCHANGED* !!(ds->drop_changed);
 
 return 0;
 }
@@ -1410,6 +1412,15 @@ static int ist_add(const OptionsContext *o, Demuxer *d, 
AVStream *st, AVDictiona
 ds->reinit_filters = -1;
 opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, 
&ds->reinit_filters);
 
+ds->drop_changed = 0;
+opt_match_per_stream_int(ist, &o->drop_changed, ic, st, &ds->drop_changed);
+
+if (ds->drop_changed && ds->reinit_filters) {
+if (ds->reinit_filters > 0)
+av_log(ist, AV_LOG_ERROR, "drop_changed and reinit_filters both 
set, which is contradictory; ignoring reinit_filters.\n");
+ds->reinit_filters = 0;
+}
+
 ist->user_set_discard = AVDISCARD_NONE;
 
 if ((o->video_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO) ||
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ef35c3988f..fddfbceec1 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -126,6 +126,7 @@ typedef struct InputFilterPriv {
 
 int eof;
 int bound;
+uint64_tnb_dropped;
 
 // parameters configured for this input
 int format;
@@ -2898,6 +2899,13 @@ static int send_frame(FilterGraph *fg, FilterGraphThread 
*fgt,
 } else if (ifp->downmixinfo_present)
 need_reinit |= DOWNMIX_CHANGED;
 
+if (need_reinit && (ifp->opts.flags & IFILTER_FLAG_DROPCHANGED)) {
+ifp->nb_dropped++;
+av_log(fg, AV_LOG_DEBUG, "Avoiding reinit; dropping frame pts: %s 
bound for %s\n", av_ts2str(frame->pts), ifilter->name);
+av_frame_unref(frame);
+return 0;
+}
+
 if (!(ifp->opts.flags & IFILTER_FLAG_REINIT) && fgt->graph)
 need_reinit = 0;
 
@@ -3140,6 +3148,8 @@ read_frames:
  

Re: [FFmpeg-devel] [PATCH] avutil/vulkan: Remove unused ff_vk_create_avbuf()

2025-03-15 Thread Lynne

On 09/03/2025 17:53, Andreas Rheinhardt wrote:

Patch attached.

- Andreas


LGTM.
Buffer pools should be used instead of making individual buffers. And 
for buffers we import, I've added a new function which takes care of 
this in my FFv1 patchset.

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

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


[FFmpeg-devel] [PATCH 2/2] avcodec/ffv1dec_template: wrap around in fltmap table

2025-03-15 Thread Michael Niedermayer
Avoids out of array access
Another solution may be choosen later if something else turns out to fit
naturally into the decoder. But for now dont crash

Signed-off-by: Michael Niedermayer 
---
 libavcodec/ffv1dec_template.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index 37caacb758d..818f12f865d 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -225,11 +225,11 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, 
FFV1SliceContext *sc,
 r += g;
 }
 if (sc->remap) {
-r = sc->fltmap[0][r];
-g = sc->fltmap[1][g];
-b = sc->fltmap[2][b];
+r = sc->fltmap[0][r & 0x];
+g = sc->fltmap[1][g & 0x];
+b = sc->fltmap[2][b & 0x];
 if (transparency)
-a = sc->fltmap[3][a];
+a = sc->fltmap[3][a & 0x];
 }
 
 if (lbd)
-- 
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] Include field_mode information in NUT stream info

2025-03-15 Thread Anders Rein
Hi! Thanks for the feedback.I have no problem adding the "X-" prefix
to the field order key, however I was just following the way
"r_frame_rate" was passed. As far as I can see this field is not
mentioned in nut.txt either and should also be using the X- prefix. Or
am I missing something?

On Mon, 10 Mar 2025 at 21:19, Michael Niedermayer
 wrote:
>
> Hi
>
> On Mon, Mar 10, 2025 at 05:44:22PM +0100, Anders Rein wrote:
> > This will make it possible to transmit raw video over NUT without losing
> > the field order information.
>
> [...]
>
> > diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
> > index 55efb114c3..abe4e3fb98 100644
> > --- a/libavformat/nutenc.c
> > +++ b/libavformat/nutenc.c
> > @@ -21,6 +21,7 @@
> >
> >  #include 
> >
> > +#include "libavcodec/defs.h"
> >  #include "libavutil/intreadwrite.h"
> >  #include "libavutil/mathematics.h"
> >  #include "libavutil/mem.h"
> > @@ -560,12 +561,22 @@ static int write_streaminfo(NUTContext *nut, 
> > AVIOContext *bc, int stream_id) {
> >  count += add_info(dyn_bc, "Disposition", 
> > ff_nut_dispositions[i].str);
> >  }
> >  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
> > +const char* field_order;
> >  uint8_t buf[256];
> >  if (st->r_frame_rate.num>0 && st->r_frame_rate.den>0)
> >  snprintf(buf, sizeof(buf), "%d/%d", st->r_frame_rate.num, 
> > st->r_frame_rate.den);
> >  else
> >  snprintf(buf, sizeof(buf), "%d/%d", st->avg_frame_rate.num, 
> > st->avg_frame_rate.den);
> >  count += add_info(dyn_bc, "r_frame_rate", buf);
> > +
> > +// Since the NUT specifications (nut.txt) do not support field 
> > order information,
> > +// the stream_info side channel is used as a means to transfer 
> > this information.
> > +// This is strictly not a part of the NUT specifications and 
> > should not be required.
> > +field_order = 
> > ff_nut_serialized_field_order_value_or_null(st->codecpar->field_order);
> > +if (field_order != NULL) {
> > +count += add_info(dyn_bc, "field_order", field_order);
> > +}
>
> either send a patch to nut.txt or it should be "X-field_order" for non
> standard fields
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Freedom in capitalist society always remains about the same as it was in
> ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
> ___
> 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".

-- 
Disclaimer: This email and any files transmitted with it are confidential 
and intended solely for the use of the individual or entity to whom they 
are addressed. If you have received this email in error or are not the 
named addressee, you should not disseminate, distribute or copy this email. 
Please notify the author by replying to this e-mail and destroy this email 
and any attachments.
___
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 v4 2/3] avcodec/sanm: fobj left/top are signed

2025-03-15 Thread Michael Niedermayer
Hi

On Sun, Mar 09, 2025 at 04:52:25PM +0100, Manuel Lauss wrote:
> Hi Michael,
> 
> On Sat, Mar 8, 2025 at 8:11 PM Michael Niedermayer
>  wrote:
> >
> > Hi Manuel
> >
> > On Tue, Mar 04, 2025 at 06:07:18PM +0100, Manuel Lauss wrote:
> > > The left and top parameters of an FOBJ are signed values.
> > >
> > > Signed-off-by: Manuel Lauss 
> > > ---
> > > v4: revert v3, it arose due to a misunderstanding
> > > v3: change the bytestream accessor to signed too
> > > v2: no changes
> > >  libavcodec/sanm.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
> > > index a4f0a28c7c..71dbac4320 100644
> > > --- a/libavcodec/sanm.c
> > > +++ b/libavcodec/sanm.c
> > > @@ -1238,8 +1238,8 @@ static int old_codec48(SANMVideoContext *ctx, int 
> > > width, int height)
> > >  static int process_frame_obj(SANMVideoContext *ctx)
> > >  {
> > >  uint16_t codec = bytestream2_get_le16u(&ctx->gb);
> > > -uint16_t left  = bytestream2_get_le16u(&ctx->gb);
> > > -uint16_t top   = bytestream2_get_le16u(&ctx->gb);
> > > +int16_t  left  = bytestream2_get_le16u(&ctx->gb);
> > > +int16_t  top   = bytestream2_get_le16u(&ctx->gb);
> > >  uint16_t w = bytestream2_get_le16u(&ctx->gb);
> > >  uint16_t h = bytestream2_get_le16u(&ctx->gb);
> >
> > Does the following code also handle all error conditions that
> > negative left/top could now trigger ?
> 
> For the LucasArts titles that sanm.c currently supports well,
> no negative values are ever encountered.
> I let ffplay run through maybe 1/3 of the Rebel Assault 1 videos,
> which are the only ones that make use of negative values, but
> didn't encounter any crashes; mostly because the codecs it
> uses aren't supported by ffmpeg/sanm (yet).

My concern is not that it crashes my concern is that manually craftet
files could result in arbitrary code execution if theres any out of
array accesses.
Did you check that negative values are safe in that respect ?

thx

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

If the United States is serious about tackling the national security threats 
related to an insecure 5G network, it needs to rethink the extent to which it
values corporate profits and government espionage over security.-Bruce Schneier


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] avcodec/aom_film_grain: Cast const away to suppress compiler, warning

2025-03-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Patch attached.
> 
> - Andreas
> 
Will apply.

- 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 1/7] avcodec/pcm: Remove always-false check

2025-03-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Patches attached.
> 
> - Andreas
> 
Will apply this patchset tomorrow unless there are objections.

- 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] [PATCH] avcodec/exrdec: restore applying color transfer characteristics for float16 samples

2025-03-15 Thread James Almer
Regression since 0e917389fe73c932049635d947bba076f1709589.
This change also reverts commit 431805c096738da7661a0baee2b12fe9724dcc95.

Signed-off-by: James Almer 
---
 libavcodec/exr.c | 38 --
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 4482f104d0..107281e115 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -42,6 +42,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
+#include "libavutil/float2half.h"
 #include "libavutil/half2float.h"
 
 #include "avcodec.h"
@@ -193,7 +194,10 @@ typedef struct EXRContext {
 
 uint8_t *offset_table;
 
+uint16_t gamma_table[65536];
+
 Half2FloatTables h2f_tables;
+Float2HalfTables f2h_tables;
 } EXRContext;
 
 static int zip_uncompress(const EXRContext *s, const uint8_t *src, int 
compressed_size,
@@ -1401,8 +1405,13 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
 }
 } else if (s->pixel_type == EXR_HALF) {
 // 16-bit
-for (int x = 0; x < xsize; x++, ptr_x += step)
-AV_WN16A(ptr_x, bytestream_get_le16(&src));
+if (trc_func && (!c || (c < 3 && s->desc->flags & 
AV_PIX_FMT_FLAG_PLANAR))) {
+for (int x = 0; x < xsize; x++, ptr_x += step)
+AV_WN16A(ptr_x, 
s->gamma_table[bytestream_get_le16(&src)]);
+} else {
+for (int x = 0; x < xsize; x++, ptr_x += step)
+AV_WN16A(ptr_x, bytestream_get_le16(&src));
+}
 }
 
 // Zero out the end if xmax+1 is not w
@@ -2212,8 +2221,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*picture,
 static av_cold int decode_init(AVCodecContext *avctx)
 {
 EXRContext *s = avctx->priv_data;
+uint32_t i;
+union av_intfloat32 t;
+float one_gamma = 1.0f / s->gamma;
+av_csp_trc_function trc_func = NULL;
 
 ff_init_half2float_tables(&s->h2f_tables);
+ff_init_float2half_tables(&s->f2h_tables);
 
 s->avctx  = avctx;
 
@@ -2223,6 +2237,26 @@ static av_cold int decode_init(AVCodecContext *avctx)
 ff_bswapdsp_init(&s->bbdsp);
 #endif
 
+trc_func = av_csp_trc_func_from_id(s->apply_trc_type);
+if (trc_func) {
+for (i = 0; i < 65536; ++i) {
+t.i = half2float(i, &s->h2f_tables);
+t.f = trc_func(t.f);
+s->gamma_table[i] = float2half(av_float2int(t.f), &s->f2h_tables);
+}
+} else if (one_gamma != 1.0f) {
+for (i = 0; i < 65536; ++i) {
+t.i = half2float(i, &s->h2f_tables);
+/* If negative value we reuse half value */
+if (t.f <= 0.0f) {
+s->gamma_table[i] = i;
+} else {
+t.f = powf(t.f, one_gamma);
+s->gamma_table[i] = float2half(t.i, &s->f2h_tables);
+}
+}
+}
+
 // allocate thread data, used for non EXR_RAW compression types
 s->thread_data = av_calloc(avctx->thread_count, sizeof(*s->thread_data));
 if (!s->thread_data)
-- 
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] ffmpeg: add per-stream input option drop_changed

2025-03-15 Thread Marton Balint




On Sat, 15 Mar 2025, Gyan Doshi wrote:


This is a replacement in ffmpeg for the deprecated avcodec flag 
AV_CODEC_FLAG_DROPCHANGED.

This option is meant to be used when the filtergraph should not be
reinited upon input parameter changes as that leads to loss of state
in the filtergraph potentially leading to broken or aborted output,
e.g. inserting of silence with first_pts specified in aresample.

Generally useful to avoid corrupted yet decodable packets in live
streaming inputs.

This option when enabled takes precedence over reinit_filters
---
doc/ffmpeg.texi |  6 ++
fftools/ffmpeg.h|  2 ++
fftools/ffmpeg_demux.c  | 13 -
fftools/ffmpeg_filter.c | 10 ++
fftools/ffmpeg_opt.c|  3 +++
5 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index fca220a334..a73db79f94 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1373,6 +1373,12 @@ The properties where a change triggers reinitialization 
are,
for video, frame resolution or pixel format;
for audio, sample format, sample rate, channel count or channel layout.

+@item -drop_changed[:@var{stream_specifier}] @var{integer} 
(@emph{input,per-stream})
+This boolean option determines whether a frame with differing frame parameters 
mid-stream
+gets dropped instead of leading to filtergraph reinitialization, as that would 
lead to loss
+of filter state. Generally useful to avoid corrupted yet decodable packets in 
live streaming
+inputs. Default is false.
+
@item -filter_threads @var{nb_threads} (@emph{global})
Defines how many threads are used to process a filter pipeline. Each pipeline
will produce a thread pool with this many threads available for parallel 
processing.
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 86a3e10c6b..5869979214 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -232,6 +232,7 @@ typedef struct OptionsContext {
SpecifierOptList filter_scripts;
#endif
SpecifierOptList reinit_filters;
+SpecifierOptList drop_changed;
SpecifierOptList fix_sub_duration;
SpecifierOptList fix_sub_duration_heartbeat;
SpecifierOptList canvas_sizes;
@@ -262,6 +263,7 @@ enum IFilterFlags {
IFILTER_FLAG_REINIT = (1 << 1),
IFILTER_FLAG_CFR= (1 << 2),
IFILTER_FLAG_CROP   = (1 << 3),
+IFILTER_FLAG_DROPCHANGED= (1 << 4),
};

typedef struct InputFilterOptions {
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index b8171e336e..292b718f14 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -67,6 +67,7 @@ typedef struct DemuxStream {
int  reinit_filters;
int  autorotate;
int  apply_cropping;
+int  drop_changed;


int  wrap_correction_done;
@@ -1099,7 +1100,8 @@ int ist_filter_add(InputStream *ist, InputFilter 
*ifilter, int is_simple,
return AVERROR(ENOMEM);

opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
-   IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
+   IFILTER_FLAG_REINIT * !!(ds->reinit_filters) |
+   IFILTER_FLAG_DROPCHANGED* !!(ds->drop_changed);

return 0;
}
@@ -1410,6 +1412,15 @@ static int ist_add(const OptionsContext *o, Demuxer *d, 
AVStream *st, AVDictiona
ds->reinit_filters = -1;
opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, 
&ds->reinit_filters);

+ds->drop_changed = 0;
+opt_match_per_stream_int(ist, &o->drop_changed, ic, st, &ds->drop_changed);
+
+if (ds->drop_changed && ds->reinit_filters) {
+if (ds->reinit_filters > 0)
+av_log(ist, AV_LOG_ERROR, "drop_changed and reinit_filters both set, 
which is contradictory; ignoring reinit_filters.\n");


I'd rather simply return an error, instead of continuing, unless there is 
a very good reason to allow conflicting options and fall back to one or 
the other.



+ds->reinit_filters = 0;
+}
+
ist->user_set_discard = AVDISCARD_NONE;

if ((o->video_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO) ||
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ef35c3988f..fddfbceec1 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -126,6 +126,7 @@ typedef struct InputFilterPriv {

int eof;
int bound;
+uint64_tnb_dropped;

// parameters configured for this input
int format;
@@ -2898,6 +2899,13 @@ static int send_frame(FilterGraph *fg, FilterGraphThread 
*fgt,
} else if (ifp->downmixinfo_present)
need_reinit |= DOWNMIX_CHANGED;

+if (need_reinit && (ifp->opts.flags & IFILTER_FLAG_DROPCHANGED)) {
+ifp->nb_dropped++;
+av_log(fg, AV_LOG_DEBUG, "Avoiding reinit; dropping frame pts: %s bound for 
%s\n", av_ts2str(frame->pts), ifilter->name);


Maybe it would make sense to use AV_LO

[FFmpeg-devel] [PATCH 1/3] avcodec/decode: Move is_open check to, avcodec_receive_frame()

2025-03-15 Thread Andreas Rheinhardt
Patches attached.

- Andreas
From 9636bd44f005059938e9f8526eba4a3a9af38914 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt 
Date: Mon, 10 Mar 2025 16:14:26 +0100
Subject: [PATCH 1/3] avcodec/decode: Move is_open check to
 avcodec_receive_frame()

It also applies to scenarios where ff_encode_receive_frame()
is used. Also remove the redundant av_codec_is_decoder().

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/avcodec.c | 3 +++
 libavcodec/decode.c  | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index e7e2c09222..64c1788c57 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -718,6 +718,9 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
 {
 av_frame_unref(frame);
 
+if (!avcodec_is_open(avctx))
+return AVERROR(EINVAL);
+
 if (av_codec_is_decoder(avctx->codec))
 return ff_decode_receive_frame(avctx, frame);
 return ff_encode_receive_frame(avctx, frame);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index c5a577f4f1..3a1c35a55f 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -817,9 +817,6 @@ int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 AVCodecInternal *avci = avctx->internal;
 int ret;
 
-if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
-return AVERROR(EINVAL);
-
 if (avci->buffer_frame->buf[0]) {
 av_frame_move_ref(frame, avci->buffer_frame);
 } else {
-- 
2.45.2

From bc8357f6ab0bcbc53e21b619dde4e3471fa7885d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt 
Date: Mon, 10 Mar 2025 16:40:39 +0100
Subject: [PATCH 2/3] avcodec/codec_internal: Add dedicated is_decoder flag to
 FFCodec

Allows to simplify av_codec_is_decoder() and av_codec_is_encoder().

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/codec_internal.h | 13 -
 libavcodec/utils.c  |  8 ++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index b2df8e729a..2b9c7354a0 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -133,7 +133,12 @@ typedef struct FFCodec {
 /**
  * Internal codec capabilities FF_CODEC_CAP_*.
  */
-unsigned caps_internal:27;
+unsigned caps_internal:26;
+
+/**
+ * Is this a decoder?
+ */
+unsigned is_decoder:1;
 
 /**
  * This field determines the video color ranges supported by an encoder.
@@ -309,21 +314,27 @@ int ff_default_get_supported_config(const struct AVCodecContext *avctx,
 #endif
 
 #define FF_CODEC_DECODE_CB(func)  \
+.is_decoder= 1,   \
 .cb_type   = FF_CODEC_CB_TYPE_DECODE, \
 .cb.decode = (func)
 #define FF_CODEC_DECODE_SUB_CB(func)  \
+.is_decoder= 1,   \
 .cb_type   = FF_CODEC_CB_TYPE_DECODE_SUB, \
 .cb.decode_sub = (func)
 #define FF_CODEC_RECEIVE_FRAME_CB(func)   \
+.is_decoder= 1,   \
 .cb_type   = FF_CODEC_CB_TYPE_RECEIVE_FRAME,  \
 .cb.receive_frame  = (func)
 #define FF_CODEC_ENCODE_CB(func)  \
+.is_decoder= 0,   \
 .cb_type   = FF_CODEC_CB_TYPE_ENCODE, \
 .cb.encode = (func)
 #define FF_CODEC_ENCODE_SUB_CB(func)  \
+.is_decoder= 0,   \
 .cb_type   = FF_CODEC_CB_TYPE_ENCODE_SUB, \
 .cb.encode_sub = (func)
 #define FF_CODEC_RECEIVE_PACKET_CB(func)  \
+.is_decoder= 0,   \
 .cb_type   = FF_CODEC_CB_TYPE_RECEIVE_PACKET, \
 .cb.receive_packet = (func)
 
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 0aa5a6f55e..90867ed6b1 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -79,17 +79,13 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
 int av_codec_is_encoder(const AVCodec *avcodec)
 {
 const FFCodec *const codec = ffcodec(avcodec);
-return codec && (codec->cb_type == FF_CODEC_CB_TYPE_ENCODE ||
- codec->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB ||
- codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET);
+return codec && !codec->is_decoder;
 }
 
 int av_codec_is_decoder(const AVCodec *avcodec)
 {
 const FFCodec *const codec = ffcodec(avcodec);
-return codec && (codec->cb_type == FF_CODEC_CB_TYPE_DECODE ||
- codec->cb_type == FF_CODEC_CB_TYPE_DECODE_SUB ||
- codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME);
+return codec && codec->is_decoder;
 }
 
 int ff_set_dimensions(AVCodecContext *s, int width, int height)
-- 
2.45.2

From 4da22ec6fc5e752b3e6

[FFmpeg-devel] [PATCH] swscale/swscale_unscaled: account for semi planar formats with data in the msb

2025-03-15 Thread James Almer
Fixes fate failures introduced by recent tests that exercise the faulty code.

Signed-off-by: James Almer 
---
 libswscale/swscale_unscaled.c | 74 ++-
 tests/ref/pixfmt/p410-nv24|  2 +-
 tests/ref/pixfmt/p410-p412be  |  2 +-
 tests/ref/pixfmt/p410-p412le  |  2 +-
 tests/ref/pixfmt/p410-p416be  |  2 +-
 tests/ref/pixfmt/p410-p416le  |  2 +-
 tests/ref/pixfmt/p412-nv24|  2 +-
 tests/ref/pixfmt/p412-p410be  |  2 +-
 tests/ref/pixfmt/p412-p410le  |  2 +-
 tests/ref/pixfmt/p412-p416be  |  2 +-
 tests/ref/pixfmt/p412-p416le  |  2 +-
 11 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 1ab36b9568..92d5386567 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -2146,17 +2146,17 @@ static int packedCopyWrapper(SwsInternal *c, const 
uint8_t *const src[],
 if (c->opts.dither == SWS_DITHER_NONE) {\
 for (i = 0; i < height; i++) {\
 for (j = 0; j < length-7; j+=8) {\
-tmp = (bswap(src[j+0]) + bias)>>shift; dst[j+0] = dbswap(tmp - 
(tmp>>dst_depth));\
-tmp = (bswap(src[j+1]) + bias)>>shift; dst[j+1] = dbswap(tmp - 
(tmp>>dst_depth));\
-tmp = (bswap(src[j+2]) + bias)>>shift; dst[j+2] = dbswap(tmp - 
(tmp>>dst_depth));\
-tmp = (bswap(src[j+3]) + bias)>>shift; dst[j+3] = dbswap(tmp - 
(tmp>>dst_depth));\
-tmp = (bswap(src[j+4]) + bias)>>shift; dst[j+4] = dbswap(tmp - 
(tmp>>dst_depth));\
-tmp = (bswap(src[j+5]) + bias)>>shift; dst[j+5] = dbswap(tmp - 
(tmp>>dst_depth));\
-tmp = (bswap(src[j+6]) + bias)>>shift; dst[j+6] = dbswap(tmp - 
(tmp>>dst_depth));\
-tmp = (bswap(src[j+7]) + bias)>>shift; dst[j+7] = dbswap(tmp - 
(tmp>>dst_depth));\
+tmp = ((bswap(src[j+0]) >> src_shift) + bias)>>shift; dst[j+0] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+1]) >> src_shift) + bias)>>shift; dst[j+1] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+2]) >> src_shift) + bias)>>shift; dst[j+2] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+3]) >> src_shift) + bias)>>shift; dst[j+3] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+4]) >> src_shift) + bias)>>shift; dst[j+4] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+5]) >> src_shift) + bias)>>shift; dst[j+5] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+6]) >> src_shift) + bias)>>shift; dst[j+6] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+7]) >> src_shift) + bias)>>shift; dst[j+7] 
= dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
 }\
 for (; j < length; j++) {\
-tmp = (bswap(src[j]) + bias)>>shift; dst[j] = dbswap(tmp - 
(tmp>>dst_depth));\
+tmp = (bswap(src[j]) + bias)>>shift; dst[j] = dbswap(tmp - 
(tmp>>dst_depth) << dst_shift);\
 }\
 dst += dstStride;\
 src += srcStride;\
@@ -2165,17 +2165,17 @@ static int packedCopyWrapper(SwsInternal *c, const 
uint8_t *const src[],
 for (i = 0; i < height; i++) {\
 const uint8_t *dither= dithers[shift-1][i&7];\
 for (j = 0; j < length-7; j+=8) {\
-tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = 
dbswap(tmp - (tmp>>dst_depth));\
-tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = 
dbswap(tmp - (tmp>>dst_depth));\
-tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = 
dbswap(tmp - (tmp>>dst_depth));\
-tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = 
dbswap(tmp - (tmp>>dst_depth));\
-tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = 
dbswap(tmp - (tmp>>dst_depth));\
-tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = 
dbswap(tmp - (tmp>>dst_depth));\
-tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = 
dbswap(tmp - (tmp>>dst_depth));\
-tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = 
dbswap(tmp - (tmp>>dst_depth));\
+tmp = ((bswap(src[j+0]) >> src_shift) + dither[0])>>shift; 
dst[j+0] = dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+1]) >> src_shift) + dither[1])>>shift; 
dst[j+1] = dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+2]) >> src_shift) + dither[2])>>shift; 
dst[j+2] = dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+3]) >> src_shift) + dither[3])>>shift; 
dst[j+3] = dbswap((tmp - (tmp>>dst_depth)) << dst_shift);\
+tmp = ((bswap(src[j+4]) >> src_shift) + dither[4])>>shift; 
dst[j+4] = dbswap((tmp - (tmp>>dst_depth

Re: [FFmpeg-devel] [PATCH] libavfilter: guard against ff_draw_init/ff_draw_init2 failures

2025-03-15 Thread Michael Niedermayer
Hi

On Mon, Mar 10, 2025 at 10:18:44AM -0400, Nil Fons Miret via ffmpeg-devel wrote:
> Thanks for the clarification, attaching an updated patch. The only
> change is the one comment on qrencode.c.

will apply

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
conveniently.
New school: Use the highest level language in which the latest supercomputer
can solve the problem without the user falling asleep waiting.


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] avcodec/exrdec: restore applying color transfer characteristics for float16 samples

2025-03-15 Thread James Almer

On 3/15/2025 8:35 PM, Michael Niedermayer wrote:

Hi

On Thu, Mar 13, 2025 at 11:08:09PM -0300, James Almer wrote:

Regression since 0e917389fe73c932049635d947bba076f1709589.
This change also reverts commit 431805c096738da7661a0baee2b12fe9724dcc95.

Signed-off-by: James Almer 
---
  libavcodec/exr.c | 38 --
  1 file changed, 36 insertions(+), 2 deletions(-)


We dont do that for any other codec.
For every other case we export all the color and gamma information
but do not modify the sample values to some "normalized" representation

Its also lossy to do it in the decoder like this

thx
We're still doing it for the float path, so in that case you may want to 
remove it from there too.




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] avcodec/exrdec: restore applying color transfer characteristics for float16 samples

2025-03-15 Thread Michael Niedermayer
Hi

On Thu, Mar 13, 2025 at 11:08:09PM -0300, James Almer wrote:
> Regression since 0e917389fe73c932049635d947bba076f1709589.
> This change also reverts commit 431805c096738da7661a0baee2b12fe9724dcc95.
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/exr.c | 38 --
>  1 file changed, 36 insertions(+), 2 deletions(-)

We dont do that for any other codec.
For every other case we export all the color and gamma information
but do not modify the sample values to some "normalized" representation

Its also lossy to do it in the decoder like this

thx

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

Frequently ignored answer#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.


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] avcodec/exrdec: restore applying color transfer characteristics for float16 samples

2025-03-15 Thread Michael Niedermayer
Hi

On Sat, Mar 15, 2025 at 08:36:33PM -0300, James Almer wrote:
> On 3/15/2025 8:35 PM, Michael Niedermayer wrote:
> > Hi
> > 
> > On Thu, Mar 13, 2025 at 11:08:09PM -0300, James Almer wrote:
> > > Regression since 0e917389fe73c932049635d947bba076f1709589.
> > > This change also reverts commit 431805c096738da7661a0baee2b12fe9724dcc95.
> > > 
> > > Signed-off-by: James Almer 
> > > ---
> > >   libavcodec/exr.c | 38 --
> > >   1 file changed, 36 insertions(+), 2 deletions(-)
> > 
> > We dont do that for any other codec.
> > For every other case we export all the color and gamma information
> > but do not modify the sample values to some "normalized" representation
> > 
> > Its also lossy to do it in the decoder like this
> > 
> > thx
> We're still doing it for the float path, so in that case you may want to
> remove it from there too.

I think we should remove it, but I think I have no samples for that code path.
So i would not be able to test ...

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The greatest way to live with honor in this world is to be what we pretend
to be. -- 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 v8 0/8] Properly decode ogg metadata in ogg/{vorbis, flac, opus} chained bitstreams

2025-03-15 Thread Romain Beauxis
Hi all!


Le jeu. 13 mars 2025 à 08:43, Michael Niedermayer
 a écrit :
>
> Hi Romain
>
> On Tue, Mar 11, 2025 at 11:56:37AM -0500, Romain Beauxis wrote:
> > Le mar. 11 mars 2025 à 11:55, Romain Beauxis
> >  a écrit :
> > >
> > > This is a series of patches to allow proper decoding of ogg metadata in 
> > > chained
> > > `ogg/vorbis, `ogg/flac` and `ogg/opus` streams.
> > >
> > > ## Changes since last version:
> > > * Moved textual reference output for tests to test/ref/fate
> > > * Updated test binary to only output stream metadata when
> > >   AVSTREAM_EVENT_FLAG_METADATA_UPDATED flag is set.
> >
> > Again, forgot to add that test samples are available here:
> > https://www.dropbox.com/scl/fo/xrtrna2rxr1j354hrtymq/AGwemlxHYecBLNmQ8Fsy--4?rlkey=lzilr4m9w4gfdqygoe172vvy8&dl=0

Any update on this? Or concerns re: the samples?

I've got more work ready to send, I'd love to finish this patch set to
get the next one rolling.

Thanks y'all!
-- Romain
___
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/exrdec: restore applying color transfer characteristics for float16 samples

2025-03-15 Thread James Almer

On 3/15/2025 8:42 PM, Michael Niedermayer wrote:

Hi

On Sat, Mar 15, 2025 at 08:36:33PM -0300, James Almer wrote:

On 3/15/2025 8:35 PM, Michael Niedermayer wrote:

Hi

On Thu, Mar 13, 2025 at 11:08:09PM -0300, James Almer wrote:

Regression since 0e917389fe73c932049635d947bba076f1709589.
This change also reverts commit 431805c096738da7661a0baee2b12fe9724dcc95.

Signed-off-by: James Almer 
---
   libavcodec/exr.c | 38 --
   1 file changed, 36 insertions(+), 2 deletions(-)


We dont do that for any other codec.
For every other case we export all the color and gamma information
but do not modify the sample values to some "normalized" representation

Its also lossy to do it in the decoder like this

thx

We're still doing it for the float path, so in that case you may want to
remove it from there too.


I think we should remove it, but I think I have no samples for that code path.
So i would not be able to test ...

thx


Even with no samples it should be a straightforward change.
But even then, since this feature includes two AVOptions that would be 
broken after such removal (and in fact currently are for half float 
samples), we should IMO deprecate them and remove the feature once the 
options are gone. That includes applying this patch to restore the 
functionality with half float samples.




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 v3] ffbuild: read library linker objects from a file

2025-03-15 Thread Gyan Doshi




On 2025-03-13 06:32 pm, Gyan Doshi wrote:

The linker command can exceed the maximum argument limit on MinGW,
especially for libavcodec.

The objects list is now stored in a file and passed to the linker.
---
v3:
   for reasons unknown to me, static linking doesn't appear to
   work on linux with escaped variables, so removed those.
   Someone please test on linux both static and shared builds.


Both static and shared build tested on Ubuntu (WSL).
Plan to push tomorrow.

Regards,
Gyan




  .gitignore  | 1 +
  ffbuild/common.mak  | 2 +-
  ffbuild/library.mak | 8 ++--
  3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9cfc78b414..430abaf91b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
  *.a
  *.o
+*.objs
  *.o.*
  *.d
  *.def
diff --git a/ffbuild/common.mak b/ffbuild/common.mak
index 023adb8567..ca45a0f368 100644
--- a/ffbuild/common.mak
+++ b/ffbuild/common.mak
@@ -214,7 +214,7 @@ $(TOOLOBJS): | tools
  
  OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(SHLIBOBJS) $(STLIBOBJS) $(TESTOBJS))
  
-CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.pc *.ptx *.ptx.gz *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb

+CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx 
*.ptx.gz *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
  LIBSUFFIXES   = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
  
  define RULES

diff --git a/ffbuild/library.mak b/ffbuild/library.mak
index 793e9d41fa..72e3872157 100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@ -35,8 +35,10 @@ OBJS += $(SHLIBOBJS)
  endif
  $(SUBDIR)$(LIBNAME): $(OBJS) $(STLIBOBJS)
$(RM) $@
-   $(AR) $(ARFLAGS) $(AR_O) $^
+   $(Q)echo $^ > $@.objs
+   $(AR) $(ARFLAGS) $(AR_O) @$@.objs
$(RANLIB) $@
+   -$(RM) $@.objs
  
  install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
  
@@ -66,8 +68,10 @@ $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
  
  $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SHLIBOBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver

$(SLIB_CREATE_DEF_CMD)
-   $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) $$(filter %.o,$$^) 
$(FFEXTRALIBS)
+   $(Q)echo $$(filter %.o,$$^) > $$@.objs
+   $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) @$$@.objs 
$(FFEXTRALIBS)
$(SLIB_EXTRA_CMD)
+   -$(RM) $$@.objs
  
  ifdef SUBDIR

  $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)


___
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 09/13] avcodec/sanm: codec4/5/33/34 decoder

2025-03-15 Thread Manuel Lauss
This codec works on 4x4 pixel tiles, which can be generated and also
read from the datastream.  Codec5 does not recognize the "skip-block"
command; codecs33/34 are the same as 4/5 but with a different tileset
generator.

Signed-off-by: Manuel Lauss 
---
v2: had left+top swapped resulted in weird visuals in e.g. L5PLAY.ANM

codec33/34 are untested since I have no video files using it.  I think
they are used only in the SEGA-CD Version of Rebel Assault 1, along
with codec31/32 which are modifications of codec1.  But the latest DOS
EXE had the code in it so I implemented it here as well.

 libavcodec/sanm.c | 229 ++
 1 file changed, 229 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 6080144235..eecfefd43b 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -293,6 +293,8 @@ typedef struct SANMVideoContext {
 int8_t p8x8glyphs[NGLYPHS][64];
 uint8_t c47itbl[0x1];
 uint8_t c23lut[256];
+uint8_t c4tbl[2][256][16];
+uint16_t c4param;
 } SANMVideoContext;
 
 typedef struct SANMFrameHeader {
@@ -480,6 +482,142 @@ static av_cold int init_buffers(SANMVideoContext *ctx)
 return 0;
 }
 
+static void codec33_gen_tiles(SANMVideoContext *ctx, int8_t param1)
+{
+uint8_t *dst = &(ctx->c4tbl[0][0][0]);
+int i, j, k, l, m, n, o, p;
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+p = (j + k) / 2;
+j = (j + p) / 2;
+m = l / 2;
+n = (i + param1);
+o = (k + param1);
+
+*dst++ = p; *dst++ = p; *dst++ = j; *dst++ = n;
+*dst++ = p; *dst++ = p; *dst++ = j; *dst++ = i;
+*dst++ = m; *dst++ = m; *dst++ = p; *dst++ = j;
+*dst++ = l; *dst++ = l; *dst++ = m; *dst++ = p;
+}
+}
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+n = ((j + l) / 2);
+m = ((l + n) / 2);
+
+*dst++ = j; *dst++ = j; *dst++ = j; *dst++ = j;
+*dst++ = n; *dst++ = n; *dst++ = n; *dst++ = n;
+*dst++ = m; *dst++ = m; *dst++ = m; *dst++ = m;
+*dst++ = l; *dst++ = l; *dst++ = l; *dst++ = l;
+}
+}
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = (j + m) / 2;
+o = m / 2;
+p = j & 0xff;
+
+*dst++ = p; *dst++ = p; *dst++ = n; *dst++ = m;
+*dst++ = p; *dst++ = p; *dst++ = n; *dst++ = m;
+*dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
+*dst++ = m; *dst++ = m; *dst++ = o; *dst++ = l;
+}
+}
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = m / 2;
+
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+}
+}
+}
+
+static void codec4_gen_tiles(SANMVideoContext *ctx, uint16_t param1)
+{
+uint8_t *dst = &(ctx->c4tbl[0][0][0]);
+int i, j, k, l, m, n, o;
+
+for (i = 1; i < 16; i += 2) {
+for (k = 0; k < 16; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = (j + m) / 2;
+o = (l + m) / 2;
+if (j == m || l == m) {
+*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
+*dst++ = j; *dst++ = l; *dst++ = j; *dst++ = j;
+*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
+*dst++ = l; *dst++ = l; *dst++ = j; *dst++ = l;
+} else {
+*dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
+*dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
+*dst++ = o; *dst++ = o; *dst++ = m; *dst++ = n;
+*dst++ = l; *dst++ = l; *dst++ = o; *dst++ = m;
+}
+}
+}
+
+for (i = 0; i < 16; i += 2) {
+for (k = 0; k < 16; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = (j + m) / 2;
+o = (l + m) / 2;
+if (m == j || m == l) {
+*dst++ = j; *dst++ = j; *dst++ = l; *dst++ = j;
+*dst++ = j; *dst++ = j; *dst++ = j; *dst++ = l;
+*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = l;
+*dst++ = j; *dst++ = l; *dst++ = j; *dst++ = l;
+} else {
+*dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
+*dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
+*dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
+ 

[FFmpeg-devel] [PATCH v2 06/13] avcodec/sanm: codec2 decoder

2025-03-15 Thread Manuel Lauss
this codec consists of 4 byte packets: 2bytes delta-x, 1 byte delta-y
and 1 byte color to put at that spot.
Used in Rebel Assault 1 only.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 0c8ca73508..c5099dc999 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -607,6 +607,24 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 return 0;
 }
 
+static int old_codec2(SANMVideoContext *ctx, int top,
+  int left, int width, int height)
+{
+uint8_t *dst = (uint8_t *)ctx->frm0, col;
+int16_t xpos = left, ypos = top;
+
+while (bytestream2_get_bytes_left(&ctx->gb) > 3) {
+xpos += bytestream2_get_le16u(&ctx->gb);
+ypos += bytestream2_get_byteu(&ctx->gb);
+col = bytestream2_get_byteu(&ctx->gb);
+if (xpos >= 0 && ypos >= 0 &&
+xpos < ctx->width && ypos < ctx->height) {
+*(dst + xpos + ypos * ctx->pitch) = col;
+}
+}
+return 0;
+}
+
 static inline void codec37_mv(uint8_t *dst, const uint8_t *src,
   int height, int stride, int x, int y)
 {
@@ -1313,6 +1331,8 @@ static int process_frame_obj(SANMVideoContext *ctx)
 case 1:
 case 3:
 return old_codec1(ctx, top, left, w, h, codec == 3);
+case 2:
+return old_codec2(ctx, top, left, w, h);
 case 37:
 return old_codec37(ctx, w, h);
 case 47:
-- 
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 v2 03/13] avcodec/sanm: better frame size detection for old codecs

2025-03-15 Thread Manuel Lauss
The size of the video frame (FOBJ) of the old codecs (ANIMv0/1/2) can
very reliably be determined:
- ANIMv0/1 (=Rebel Assault 1) uses a 384x242 internal buffer for
  everything.  The codec parameters only describe the size and offset
  of the specific FOBJ on that buffer.
- ANIMv2 titles usually use one of the fullscreen codecs (37/47/48)
  as first FOBJ, and their dimensions can generally be trusted.
- RA2 uses 424x260 as internal buffer, use that if encountered:
  08PLAY.SAN does not use codec37 so we need to guess using the
  codec coordinates.
- ignore sizes smaller than 2x2 or larger than 800x600.
- some game videos have an initial fobj with either 1x1 or -1x-1
  pixels in size, ignore them with a warning (Full Throttle
  and the Rebel Assault 2 xxRETRY.SAN videos).

Once a known/valid dimension set has been discovered, use it and
don't change it for subsequent FOBJs, rather clamp the large frame
to the determined dimensions.

Tested with RA1, RA2, Full Throttle, Dig, Outlaws, SotE and MotS
videos.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 63 ---
 1 file changed, 49 insertions(+), 14 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 65ca525b9d..38cdb533eb 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -264,7 +264,7 @@ typedef struct SANMVideoContext {
 AVCodecContext *avctx;
 GetByteContext gb;
 
-int version, subversion;
+int version, subversion, have_dimensions;
 uint32_t pal[PALETTE_SIZE];
 int16_t delta_pal[PALETTE_DELTA];
 
@@ -1244,21 +1244,56 @@ static int process_frame_obj(SANMVideoContext *ctx)
 uint16_t w = bytestream2_get_le16u(&ctx->gb);
 uint16_t h = bytestream2_get_le16u(&ctx->gb);
 
-if (!w || !h) {
-av_log(ctx->avctx, AV_LOG_ERROR, "Dimensions are invalid.\n");
-return AVERROR_INVALIDDATA;
+if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) {
+av_log(ctx->avctx, AV_LOG_WARNING,
+   "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n",
+   codec, w, h, left, top);
+return 0;
 }
 
-if (ctx->width < left + w || ctx->height < top + h) {
-int ret = ff_set_dimensions(ctx->avctx, FFMAX(left + w, ctx->width),
-FFMAX(top + h, ctx->height));
-if (ret < 0)
-return ret;
-init_sizes(ctx, FFMAX(left + w, ctx->width),
-   FFMAX(top + h, ctx->height));
-if (init_buffers(ctx)) {
-av_log(ctx->avctx, AV_LOG_ERROR, "Error resizing buffers.\n");
-return AVERROR(ENOMEM);
+if (!ctx->have_dimensions) {
+int xres, yres;
+if (ctx->subversion < 2) {
+/* Rebel Assault 1: 384x242 internal size */
+xres = 384;
+yres = 242;
+ctx->have_dimensions = 1;
+} else if (codec == 37 || codec == 47 || codec == 48) {
+/* these codecs work on full frames, trust their dimensions */
+xres = w;
+yres = h;
+ctx->have_dimensions = 1;
+} else {
+/* Rebel Assault 2: 424x260 internal size */
+if (((left + w) == 424) && ((top + h) == 260))
+ctx->have_dimensions = 1;
+
+xres = FFMAX(left + w, ctx->width);
+yres = FFMAX(top + h, ctx->height);
+}
+
+if (ctx->width < xres || ctx->height < yres) {
+int ret = ff_set_dimensions(ctx->avctx, xres, yres);
+if (ret < 0)
+return ret;
+init_sizes(ctx, xres, yres);
+if (init_buffers(ctx)) {
+av_log(ctx->avctx, AV_LOG_ERROR, "Error resizing buffers.\n");
+return AVERROR(ENOMEM);
+}
+}
+} else {
+if (((left + w > ctx->width) || (top + h > ctx->height))
+&& (codec >= 37)) {
+/* correct unexpected overly large frames: this happens
+ * for instance with The Dig's sq1.san video: it has a few
+ * (all black) 640x480 frames halfway in, while the rest is
+ * 320x200.
+ */
+av_log(ctx->avctx, AV_LOG_WARNING,
+   "resizing too large fobj: c%d  %d %d @ %d %d\n", codec, w, 
h, left, top);
+w = ctx->width;
+h = ctx->height;
 }
 }
 bytestream2_skip(&ctx->gb, 4);
-- 
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 v2 07/13] avcodec/sanm: codec23 decoder

2025-03-15 Thread Manuel Lauss
This codec alternatingly skips and changes existing pixels.
A second 16bit parameter in the FOBJ header indicates how to do
the pixel changes: either by specifying a LUT in the codec datastream
or by adding a constant value to the pixel.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 66 +--
 1 file changed, 64 insertions(+), 2 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index c5099dc999..aca5bf49ec 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -292,6 +292,7 @@ typedef struct SANMVideoContext {
 int8_t p4x4glyphs[NGLYPHS][16];
 int8_t p8x8glyphs[NGLYPHS][64];
 uint8_t c47itbl[0x1];
+uint8_t c23lut[256];
 } SANMVideoContext;
 
 typedef struct SANMFrameHeader {
@@ -557,6 +558,62 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, 
const int out_size)
 return 0;
 }
 
+static int old_codec23(SANMVideoContext *ctx, int top, int left, int width,
+   int height, uint8_t param, uint16_t param2)
+{
+const uint32_t maxpxo = ctx->height * ctx->pitch;
+uint8_t *dst, lut[256], c;
+int i, j, k, pc, sk;
+int32_t pxoff;
+
+if (ctx->subversion < 2) {
+/* Rebel Assault 1: constant offset + 0xd0 */
+for (i = 0; i < 256; i++)
+lut[i] = (i + param + 0xd0) & 0xff;
+} else if (param2 == 256) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 256)
+return AVERROR_INVALIDDATA;
+bytestream2_get_bufferu(&ctx->gb, ctx->c23lut, 256);
+} else if (param2 < 256) {
+for (i = 0; i < 256; i++)
+lut[i] = (i + param2) & 0xff;
+} else {
+memcpy(lut, ctx->c23lut, 256);
+}
+if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+return 0;  /* some c23 frames just set up the LUT */
+
+dst = (uint8_t *)ctx->frm0;
+for (i = 0; i < height; i++) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+return 0;
+pxoff = left + ((top + i) * ctx->pitch);
+k = bytestream2_get_le16u(&ctx->gb);
+sk = 1;
+pc = 0;
+while (k > 0 && pc <= width) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+return AVERROR_INVALIDDATA;
+j = bytestream2_get_byteu(&ctx->gb);
+if (sk) {
+pxoff += j;
+pc += j;
+} else {
+while (j--) {
+if (pxoff >=0 && pxoff < maxpxo) {
+c = *(dst + pxoff);
+*(dst + pxoff) = lut[c];
+}
+pxoff++;
+pc++;
+}
+}
+sk ^= 1;
+}
+}
+return 0;
+}
+
 static int old_codec1(SANMVideoContext *ctx, int top,
   int left, int width, int height, int opaque)
 {
@@ -1258,11 +1315,15 @@ static int old_codec48(SANMVideoContext *ctx, int 
width, int height)
 
 static int process_frame_obj(SANMVideoContext *ctx)
 {
-uint16_t codec = bytestream2_get_le16u(&ctx->gb);
+uint16_t parm2;
+uint8_t  codec = bytestream2_get_byteu(&ctx->gb);
+uint8_t  param = bytestream2_get_byteu(&ctx->gb);
 int16_t  left  = bytestream2_get_le16u(&ctx->gb);
 int16_t  top   = bytestream2_get_le16u(&ctx->gb);
 uint16_t w = bytestream2_get_le16u(&ctx->gb);
 uint16_t h = bytestream2_get_le16u(&ctx->gb);
+bytestream2_skip(&ctx->gb, 2);
+parm2 = bytestream2_get_le16u(&ctx->gb);
 
 if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) {
 av_log(ctx->avctx, AV_LOG_WARNING,
@@ -1316,7 +1377,6 @@ static int process_frame_obj(SANMVideoContext *ctx)
 h = ctx->height;
 }
 }
-bytestream2_skip(&ctx->gb, 4);
 
 /* on first FOBJ, when the codec is not one of the
  * full-buffer codecs (37/47/48), frm0 needs to be cleared.
@@ -1333,6 +1393,8 @@ static int process_frame_obj(SANMVideoContext *ctx)
 return old_codec1(ctx, top, left, w, h, codec == 3);
 case 2:
 return old_codec2(ctx, top, left, w, h);
+case 23:
+return old_codec23(ctx, top, left, w, h, param, parm2);
 case 37:
 return old_codec37(ctx, w, h);
 case 47:
-- 
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 v2 05/13] avcodec/sanm: fix codec3

2025-03-15 Thread Manuel Lauss
codec3 is codec1 which writes zero values instead of skipping them.
This fixes a lot of RA1 videos.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 069bc0400a..0c8ca73508 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -558,7 +558,7 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, 
const int out_size)
 }
 
 static int old_codec1(SANMVideoContext *ctx, int top,
-  int left, int width, int height)
+  int left, int width, int height, int opaque)
 {
 int i, j, len, flag, code, val, end, pxoff;
 const int maxpxo = ctx->height * ctx->pitch;
@@ -581,7 +581,7 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 code = (code >> 1) + 1;
 if (flag) {
 val = bytestream2_get_byteu(&ctx->gb);
-if (val) {
+if (val || opaque) {
 for (j = 0; j < code; j++) {
 if (pxoff >= 0 && pxoff < maxpxo)
 *(dst + pxoff) = val;
@@ -595,7 +595,7 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 return AVERROR_INVALIDDATA;
 for (j = 0; j < code; j++) {
 val = bytestream2_get_byteu(&ctx->gb);
-if ((pxoff >= 0) && (pxoff < maxpxo) && val)
+if ((pxoff >= 0) && (pxoff < maxpxo) && (val || opaque))
 *(dst + pxoff) = val;
 pxoff++;
 }
@@ -1312,7 +1312,7 @@ static int process_frame_obj(SANMVideoContext *ctx)
 switch (codec) {
 case 1:
 case 3:
-return old_codec1(ctx, top, left, w, h);
+return old_codec1(ctx, top, left, w, h, codec == 3);
 case 37:
 return old_codec37(ctx, w, h);
 case 47:
-- 
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 v2 13/13] MAINTAINERS: add Manuel Lauss as sanm.c/smush.c Maintainer

2025-03-15 Thread Manuel Lauss
As requested by Michael Niedermayer.

Signed-off-by: Manuel Lauss 
---
v2: newly added.

 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9714581c6b..917eca458e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -244,6 +244,7 @@ Codecs:
   rpza.cRoberto Togni
   rtjpeg.c, rtjpeg.hReimar Doeffinger
   rv10.cMichael Niedermayer
+  sanm.cManuel Lauss
   smc.c Mike Melanson
   snow* Michael Niedermayer, Loren Merritt
   sonic.c   Alex Beregszaszi
@@ -465,6 +466,7 @@ Muxers/Demuxers:
   sdp.c Martin Storsjo
   segafilm.cMike Melanson
   segment.c Stefano Sabatini
+  smush.c   Manuel Lauss
   spdif*Anssi Hannula
   srtdec.c  Aurelien Jacobs
   swf.c Baptiste Coudurier
-- 
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 v2 12/13] avcodec/sanm: ignore codec45

2025-03-15 Thread Manuel Lauss
Codec45 is used in some RA2 videos on top of codec37.

It consists of 2 tables (768 and 32768 bytes), and datapackets
like codec2 (delta-x, delta-y) with a pixel counter instead of a color value.
It then reads the 4 surrounding pixels, looks up 3 separate values
for each in table1, adds them together to form an index into
table2 for a new pixel value, in a row.

The data coming in gets the x/y coordinates out of the visible
area very quickly (2-3 iterations); I don't see any visual
difference between the ffmpeg-produced frames and ones captured
with dosbox from rebel assault 2, which leads me to believe this
codec never worked as intended.

Signed-off-by: Manuel Lauss 
---
v2: newly added.

 libavcodec/sanm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index b86f67c3bf..7e39c5eeb0 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -1676,6 +1676,8 @@ static int process_frame_obj(SANMVideoContext *ctx, 
GetByteContext *gb)
 return old_codec23(ctx, gb, top, left, w, h, param, parm2);
 case 37:
 return old_codec37(ctx, w, h);
+case 45:
+return 0;
 case 47:
 return old_codec47(ctx, w, h);
 case 48:
-- 
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 v2 00/13] avcodec/sanm: various improvements

2025-03-15 Thread Manuel Lauss
This patchset improves especially support for SMUSHv1 (Rebel Assault 1),
adds missing codecs and functions and improves reliability of SMUSHv1/v2.

Changes in v2:
- reordered first 3 patches as some regressed things without the following
  patch applied.
- fixed codec4 left/top being swapped, resulting in weird visuals in L5PLAY.ANM
- additional handling for unaligned objects in file (see #4)
- reimplement ANIMv1 store/fetch handling (see #11)
- added codec45 to ignore (see #12 for an explanation)
- add myself as sanm.c/smush.c Maintainer, as requested by Michael (#13)

There are still a few palette issues in RA1: when the first FRME does not
contain any video data, the palette seems to be all-black until the first
NPAL (=new palette) chunk is encountered, although every ANM and SAN file
have a full palette in their header.

Manuel Lauss (13):
  avcodec/sanm: disable left/top for fullscreen codecs
  avcodec/sanm: FOBJ left/top are signed values
  avcodec/sanm: better frame size detection for old codecs
  avcodec/sanm: better ANIMv1 engine support
  avcodec/sanm: fix codec3
  avcodec/sanm: codec2 decoder
  avcodec/sanm: codec23 decoder
  avcodec/sanm: codec21 decoder
  avcodec/sanm: codec4/5/33/34 decoder
  avcodec/sanm: codec37: reimplement comp4
  avcodec/sanm: implement STOR/FTCH for ANIMv1
  avcodec/sanm: ignore codec45
  MAINTAINERS: add Manuel Lauss as sanm.c/smush.c Maintainer

 MAINTAINERS   |   2 +
 libavcodec/sanm.c | 687 --
 2 files changed, 598 insertions(+), 91 deletions(-)

-- 
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 v2 11/13] avcodec/sanm: implement STOR/FTCH for ANIMv1

2025-03-15 Thread Manuel Lauss
Handle STOR/FTCH the same way the RA1 game engine does:
On STOR, save the next following FOBJ (not the decoded image)
in a buffer; decode it on FTCH.
The RA1 codecs and the fobj handler now take an explicit
GetByteContext in order to be able to replay stored data.

Used extensively by Rebel Assault 1 for e.g. backgrounds and
the cockpit overlay.

For ANIMv2 keep the current system to store the decoded image, as
replaying a FOBJ would not work with codecs37/47/48 due to sequence
violations.

Signed-off-by: Manuel Lauss 
---
v2: reimplemented by giving the RA1 codecs an explicit GetByteContext*
to support the replay of data from different memory.

 libavcodec/sanm.c | 226 +++---
 1 file changed, 154 insertions(+), 72 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 2d7a0eeb32..b86f67c3bf 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -598,7 +598,8 @@ static void codec4_gen_tiles(SANMVideoContext *ctx, 
uint16_t param1)
 }
 
 
-static int codec4_load_tiles(SANMVideoContext *ctx, uint16_t param2, uint8_t 
clr)
+static int codec4_load_tiles(SANMVideoContext *ctx, GetByteContext *gb,
+uint16_t param2, uint8_t clr)
 {
 uint8_t c, *dst = (uint8_t *)&(ctx->c4tbl[1][0][0]);
 uint32_t loop = param2 * 8;
@@ -606,11 +607,11 @@ static int codec4_load_tiles(SANMVideoContext *ctx, 
uint16_t param2, uint8_t clr
 if (param2 > 256)
 return AVERROR_INVALIDDATA;
 
-if (bytestream2_get_bytes_left(&ctx->gb) < loop)
+if (bytestream2_get_bytes_left(gb) < loop)
 return AVERROR_INVALIDDATA;
 
 while (loop--) {
-c = bytestream2_get_byteu(&ctx->gb);
+c = bytestream2_get_byteu(gb);
 *dst++ = (c >> 4) + clr;
 *dst++ = (c & 0xf) + clr;
 }
@@ -671,8 +672,8 @@ static av_cold int decode_end(AVCodecContext *avctx)
 return 0;
 }
 
-static int old_codec4(SANMVideoContext *ctx, int top, int left, int w, int h,
-  uint8_t param, uint16_t param2, int codec)
+static int old_codec4(SANMVideoContext *ctx, GetByteContext *gb, int top, int 
left,
+ int w, int h, uint8_t param, uint16_t param2, int codec)
 {
 const uint16_t p = ctx->pitch;
 const uint32_t maxpxo = ctx->height * p;
@@ -688,7 +689,7 @@ static int old_codec4(SANMVideoContext *ctx, int top, int 
left, int w, int h,
 ctx->c4param = param;
 }
 if (param2 > 0) {
-ret = codec4_load_tiles(ctx, param2, param);
+ret = codec4_load_tiles(ctx, gb, param2, param);
 if (ret)
 return ret;
 }
@@ -702,9 +703,9 @@ static int old_codec4(SANMVideoContext *ctx, int top, int 
left, int w, int h,
 pxoff = j + left + ((top + i) * p);
 if (param2 > 0) {
 if (bits == 0) {
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+if (bytestream2_get_bytes_left(gb) < 1)
 return AVERROR_INVALIDDATA;
-mask = bytestream2_get_byteu(&ctx->gb);
+mask = bytestream2_get_byteu(gb);
 bits = 8;
 }
 bit = !!(mask & 0x80);
@@ -714,9 +715,9 @@ static int old_codec4(SANMVideoContext *ctx, int top, int 
left, int w, int h,
 bit = 0;
 }
 
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+if (bytestream2_get_bytes_left(gb) < 1)
 return AVERROR_INVALIDDATA;
-idx = bytestream2_get_byteu(&ctx->gb);
+idx = bytestream2_get_byteu(gb);
 if ((bit == 0) && (idx == 0x80) && (codec != 5))
 continue;
 
@@ -756,23 +757,23 @@ static int old_codec4(SANMVideoContext *ctx, int top, int 
left, int w, int h,
 return 0;
 }
 
-static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size)
+static int rle_decode(SANMVideoContext *ctx, GetByteContext *gb, uint8_t *dst, 
const int out_size)
 {
 int opcode, color, run_len, left = out_size;
 
 while (left > 0) {
-opcode = bytestream2_get_byte(&ctx->gb);
+opcode = bytestream2_get_byte(gb);
 run_len = (opcode >> 1) + 1;
-if (run_len > left || bytestream2_get_bytes_left(&ctx->gb) <= 0)
+if (run_len > left || bytestream2_get_bytes_left(gb) <= 0)
 return AVERROR_INVALIDDATA;
 
 if (opcode & 1) {
-color = bytestream2_get_byte(&ctx->gb);
+color = bytestream2_get_byte(gb);
 memset(dst, color, run_len);
 } else {
-if (bytestream2_get_bytes_left(&ctx->gb) < run_len)
+if (bytestream2_get_bytes_left(gb) < run_len)
 return AVERROR_INVALIDDATA;
-bytestream2_get_bufferu(&ctx->gb, dst, run_len);
+bytestream2_get_bufferu(gb, dst, run_len);
 }
 
 dst  += run_len;
@@ -782,8 +783,8 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *

[FFmpeg-devel] [PATCH v2 10/13] avcodec/sanm: codec37: reimplement comp4

2025-03-15 Thread Manuel Lauss
Compression 4 code 0 means copy from delta buffer without mv,
AND start of a skip run.  This gets rid of the extra case and column
index manipulation and implements this as it is implemented in the
original game exe, i.e. as a special case for after mv copy.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index eecfefd43b..2d7a0eeb32 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -1106,16 +1106,14 @@ static int old_codec37(SANMVideoContext *ctx, int 
width, int height)
 t = bytestream2_get_byteu(&ctx->gb);
 for (k = 0; k < 4; k++)
 memset(dst + i + k * stride, t, 4);
-   } else if ((compr == 4) && (code == 0)) {
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
-return AVERROR_INVALIDDATA;
-skip_run = bytestream2_get_byteu(&ctx->gb) + 1;
-i -= 4;
} else {
 mx = c37_mv[(mvoff * 255 + code) * 2];
 my = c37_mv[(mvoff * 255 + code) * 2 + 1];
 codec37_mv(dst + i, prev + i + mx + my * stride,
ctx->height, stride, i + mx, j + my);
+
+if ((compr == 4) && (code == 0))
+skip_run = bytestream2_get_byteu(&ctx->gb);
 }
 }
 dst  += stride * 4;
-- 
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 v2 02/13] avcodec/sanm: FOBJ left/top are signed values

2025-03-15 Thread Manuel Lauss
The left/top parameters of a FOBJ are signed values.  Adjust
codec1 code accordingly to not draw outside the buffer area.
Rebel Assault 1 makes heavy use of this.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 33 ++---
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 49ac9bebfe..65ca525b9d 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -558,18 +558,18 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t 
*dst, const int out_size)
 static int old_codec1(SANMVideoContext *ctx, int top,
   int left, int width, int height)
 {
-uint8_t *dst = ((uint8_t *)ctx->frm0) + left + top * ctx->pitch;
-int i, j, len, flag, code, val, pos, end;
+int i, j, len, flag, code, val, end, pxoff;
+const int maxpxo = ctx->height * ctx->pitch;
+uint8_t *dst = (uint8_t *)ctx->frm0;
 
 for (i = 0; i < height; i++) {
-pos = 0;
-
 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
 return AVERROR_INVALIDDATA;
 
 len = bytestream2_get_le16u(&ctx->gb);
 end = bytestream2_tell(&ctx->gb) + len;
 
+pxoff = left + ((top + i) * ctx->pitch);
 while (bytestream2_tell(&ctx->gb) < end) {
 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
 return AVERROR_INVALIDDATA;
@@ -577,25 +577,28 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 code = bytestream2_get_byteu(&ctx->gb);
 flag = code & 1;
 code = (code >> 1) + 1;
-if (pos + code > width)
-return AVERROR_INVALIDDATA;
 if (flag) {
 val = bytestream2_get_byteu(&ctx->gb);
-if (val)
-memset(dst + pos, val, code);
-pos += code;
+if (val) {
+for (j = 0; j < code; j++) {
+if (pxoff >= 0 && pxoff < maxpxo)
+*(dst + pxoff) = val;
+pxoff++;
+}
+} else {
+pxoff += code;
+}
 } else {
 if (bytestream2_get_bytes_left(&ctx->gb) < code)
 return AVERROR_INVALIDDATA;
 for (j = 0; j < code; j++) {
 val = bytestream2_get_byteu(&ctx->gb);
-if (val)
-dst[pos] = val;
-pos++;
+if ((pxoff >= 0) && (pxoff < maxpxo) && val)
+*(dst + pxoff) = val;
+pxoff++;
 }
 }
 }
-dst += ctx->pitch;
 }
 ctx->rotate_code = 0;
 
@@ -1236,8 +1239,8 @@ static int old_codec48(SANMVideoContext *ctx, int width, 
int height)
 static int process_frame_obj(SANMVideoContext *ctx)
 {
 uint16_t codec = bytestream2_get_le16u(&ctx->gb);
-uint16_t left  = bytestream2_get_le16u(&ctx->gb);
-uint16_t top   = bytestream2_get_le16u(&ctx->gb);
+int16_t  left  = bytestream2_get_le16u(&ctx->gb);
+int16_t  top   = bytestream2_get_le16u(&ctx->gb);
 uint16_t w = bytestream2_get_le16u(&ctx->gb);
 uint16_t h = bytestream2_get_le16u(&ctx->gb);
 
-- 
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 03/30] avcodec: remove deprecated FF_API_DROPCHANGED

2025-03-15 Thread Gyan Doshi



On 2025-02-24 03:14 pm, Gyan Doshi wrote:



On 2025-02-24 03:36 am, James Almer wrote:

Deprecated since 2023-07-15.


Can you wait to push till I port this to ffmpeg_dec?


Patch for replacement posted at 
https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/341210.html


Regards,
Gyan





Regards,
Gyan




Signed-off-by: James Almer 
---
  libavcodec/avcodec.c   |  4 ---
  libavcodec/avcodec.h   |  9 ---
  libavcodec/decode.c    | 52 --
  libavcodec/internal.h  |  9 ---
  libavcodec/options_table.h |  3 ---
  libavcodec/version_major.h |  1 -
  6 files changed, 78 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index e7e2c09222..3f97f5d161 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -462,10 +462,6 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
    av_bsf_free(&avci->bsf);
  -#if FF_API_DROPCHANGED
- av_channel_layout_uninit(&avci->initial_ch_layout);
-#endif
-
  #if CONFIG_LCMS2
  ff_icc_context_uninit(&avci->icc);
  #endif
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index f6de3c6b42..c35e65868e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -234,15 +234,6 @@ typedef struct RcOverride{
   * Use qpel MC.
   */
  #define AV_CODEC_FLAG_QPEL    (1 <<  4)
-#if FF_API_DROPCHANGED
-/**
- * Don't output frames whose parameters differ from first
- * decoded frame in stream.
- *
- * @deprecated callers should implement this functionality in their 
own code

- */
-#define AV_CODEC_FLAG_DROPCHANGED (1 <<  5)
-#endif
  /**
   * Request the encoder to output reconstructed frames, i.e.\ frames 
that would
   * be produced by decoding the encoded bistream. These frames may 
be retrieved

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index cac7e620d2..a28279bd36 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -840,53 +840,6 @@ int ff_decode_receive_frame(AVCodecContext 
*avctx, AVFrame *frame)

    avctx->frame_num++;
  -#if FF_API_DROPCHANGED
-    if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
-
-    if (avctx->frame_num == 1) {
-    avci->initial_format = frame->format;
-    switch(avctx->codec_type) {
-    case AVMEDIA_TYPE_VIDEO:
-    avci->initial_width  = frame->width;
-    avci->initial_height = frame->height;
-    break;
-    case AVMEDIA_TYPE_AUDIO:
-    avci->initial_sample_rate = frame->sample_rate ? 
frame->sample_rate :

- avctx->sample_rate;
-    ret = 
av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout);

-    if (ret < 0)
-    goto fail;
-    break;
-    }
-    }
-
-    if (avctx->frame_num > 1) {
-    int changed = avci->initial_format != frame->format;
-
-    switch(avctx->codec_type) {
-    case AVMEDIA_TYPE_VIDEO:
-    changed |= avci->initial_width  != frame->width ||
-   avci->initial_height != frame->height;
-    break;
-    case AVMEDIA_TYPE_AUDIO:
-    changed |= avci->initial_sample_rate    != 
frame->sample_rate ||
-   avci->initial_sample_rate    != 
avctx->sample_rate ||
- av_channel_layout_compare(&avci->initial_ch_layout, 
&frame->ch_layout);

-    break;
-    }
-
-    if (changed) {
-    avci->changed_frames_dropped++;
-    av_log(avctx, AV_LOG_INFO, "dropped changed frame 
#%"PRId64" pts %"PRId64

-    " drop count: %d \n",
- avctx->frame_num, frame->pts,
- avci->changed_frames_dropped);
-    ret = AVERROR_INPUT_CHANGED;
-    goto fail;
-    }
-    }
-    }
-#endif
  return 0;
  fail:
  av_frame_unref(frame);
@@ -2065,11 +2018,6 @@ int ff_decode_preinit(AVCodecContext *avctx)
  return ret;
  }
  -#if FF_API_DROPCHANGED
-    if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED)
-    av_log(avctx, AV_LOG_WARNING, "The dropchanged flag is 
deprecated.\n");

-#endif
-
  return 0;
  }
  diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 62a37f473f..137fd52745 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -145,15 +145,6 @@ typedef struct AVCodecInternal {
  AVFrame *buffer_frame;
  int draining_done;
  -#if FF_API_DROPCHANGED
-    /* used when avctx flag AV_CODEC_FLAG_DROPCHANGED is set */
-    int changed_frames_dropped;
-    int initial_format;
-    int initial_width, initial_height;
-    int initial_sample_rate;
-    AVChannelLayout initial_ch_layout;
-#endif
-
  #if CONFIG_LCMS2
  FFIccContext icc; /* used to read and write embedded ICC 
profiles */

  #endif
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index c115d8c18c..1711e56cd3 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_t

Re: [FFmpeg-devel] Subject: [PATCH 01/17] avcodec/vlc: Merge VLCElem and RL_VLC_ELEM

2025-03-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Patches attached.
> 
> - Andreas
> 
Will apply this patchset tomorrow unless there are objections.

- 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 1/2] avcodec/mpeg12dec: Use saturated addition when combining, error_count

2025-03-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Patches attached.
> 
> - Andreas
> 

Will apply this patchset tomorrow unless there are objections.

- 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] avcodec: Mark init and close functions as av_cold

2025-03-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> Patch attached.
>>
>> - Andreas
>>
> 
> Now truely attached.
> 
> - Andreas
> 

Will apply this patch tomorrow unless there are objections.

- 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] [PATCH] avcodec/exr: deprecate gamma and apply_trc options

2025-03-15 Thread James Almer
Decoders should not modify sample values, as that's the job of a library like 
swscale.

Signed-off-by: James Almer 
---
 libavcodec/exr.c   | 38 ++
 libavcodec/version_major.h |  1 +
 2 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index e1e05902c6..0bd9ce9ebe 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -189,15 +189,17 @@ typedef struct EXRContext {
 const char *layer;
 int selected_part;
 
-enum AVColorTransferCharacteristic apply_trc_type;
-float gamma;
 
 uint8_t *offset_table;
 
+#if FF_API_EXR_GAMMA
+enum AVColorTransferCharacteristic apply_trc_type;
+float gamma;
 uint16_t gamma_table[65536];
+Float2HalfTables f2h_tables;
+#endif
 
 Half2FloatTables h2f_tables;
-Float2HalfTables f2h_tables;
 } EXRContext;
 
 static int zip_uncompress(const EXRContext *s, const uint8_t *src, int 
compressed_size,
@@ -1194,8 +1196,10 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
 int data_xoffset, data_yoffset, data_window_offset, xsize, ysize;
 int i, x, buf_size = s->buf_size;
 int c, rgb_channel_count;
+#if FF_API_EXR_GAMMA
 float one_gamma = 1.0f / s->gamma;
 av_csp_trc_function trc_func = av_csp_trc_func_from_id(s->apply_trc_type);
+#endif
 int ret;
 
 line_offset = AV_RL64(s->gb.buffer + jobnr * 8);
@@ -1387,6 +1391,7 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
 s->compression == EXR_DWAA ||
 s->compression == EXR_DWAB) {
 // 32-bit
+#if FF_API_EXR_GAMMA
 if (trc_func && (!c || (c < 3 && s->desc->flags & 
AV_PIX_FMT_FLAG_PLANAR))) {
 for (int x = 0; x < xsize; x++, ptr_x += step) {
 float f = av_int2float(bytestream_get_le32(&src));
@@ -1399,19 +1404,20 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
 f = powf(f, one_gamma);
 AV_WN32A(ptr_x, av_float2int(f));
 }
-} else {
+} else
+#endif
 for (int x = 0; x < xsize; x++, ptr_x += step)
 AV_WN32A(ptr_x, bytestream_get_le32(&src));
-}
 } else if (s->pixel_type == EXR_HALF) {
 // 16-bit
+#if FF_API_EXR_GAMMA
 if (one_gamma != 1.f || (trc_func && (!c || (c < 3 && 
s->desc->flags & AV_PIX_FMT_FLAG_PLANAR {
 for (int x = 0; x < xsize; x++, ptr_x += step)
 AV_WN16A(ptr_x, 
s->gamma_table[bytestream_get_le16(&src)]);
-} else {
+} else
+#endif
 for (int x = 0; x < xsize; x++, ptr_x += step)
 AV_WN16A(ptr_x, bytestream_get_le16(&src));
-}
 }
 
 // Zero out the end if xmax+1 is not w
@@ -2093,10 +2099,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*picture,
 return AVERROR_INVALIDDATA;
 }
 
+#if FF_API_EXR_GAMMA
 if (s->apply_trc_type != AVCOL_TRC_UNSPECIFIED)
 avctx->color_trc = s->apply_trc_type;
 else if (s->gamma > 0.f && s->gamma < 1.0001f)
 avctx->color_trc = AVCOL_TRC_LINEAR;
+#endif
 
 switch (s->compression) {
 case EXR_RAW:
@@ -2221,13 +2229,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*picture,
 static av_cold int decode_init(AVCodecContext *avctx)
 {
 EXRContext *s = avctx->priv_data;
+#if FF_API_EXR_GAMMA
 uint32_t i;
 union av_intfloat32 t;
 float one_gamma = 1.0f / s->gamma;
 av_csp_trc_function trc_func = NULL;
+ff_init_float2half_tables(&s->f2h_tables);
+#endif
 
 ff_init_half2float_tables(&s->h2f_tables);
-ff_init_float2half_tables(&s->f2h_tables);
 
 s->avctx  = avctx;
 
@@ -2237,6 +2247,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 ff_bswapdsp_init(&s->bbdsp);
 #endif
 
+#if FF_API_EXR_GAMMA
 trc_func = av_csp_trc_func_from_id(s->apply_trc_type);
 if (trc_func) {
 for (i = 0; i < 65536; ++i) {
@@ -2256,6 +2267,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 }
 }
 }
+#endif
 
 // allocate thread data, used for non EXR_RAW compression types
 s->thread_data = av_calloc(avctx->thread_count, sizeof(*s->thread_data));
@@ -2298,12 +2310,13 @@ static const AVOption options[] = {
 AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
 { "part",  "Set the decoding part", OFFSET(selected_part),
 AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VD },
-{ "gamma", "Set the float gamma value when decoding", OFFSET(gamma),
-AV_OPT_TYPE_FLOAT, { .dbl = 1.0f }, 0.001, FLT_MAX, VD },
+#if FF_API_EXR_GAMMA
+{ "gamma", "Set the float gamma value w

Re: [FFmpeg-devel] [FFmpeg-cvslog] swscale: use 16-bit intermediate precision for RGB/XYZ conversion

2025-03-15 Thread Michael Niedermayer
Hi

On Fri, Mar 14, 2025 at 09:44:22PM +0100, Niklas Haas wrote:
> On Fri, 14 Mar 2025 01:09:30 +0100 Niklas Haas  wrote:
> > On Fri, 14 Mar 2025 00:54:25 +0100 Michael Niedermayer 
> >  wrote:
> > > Hi
> > >
> > > On Sun, Jan 26, 2025 at 07:26:59PM +0100, Michael Niedermayer wrote:
> > > > On Thu, Dec 26, 2024 at 07:33:23PM +, Niklas Haas wrote:
> > > > > ffmpeg | branch: master | Niklas Haas  | Mon Dec 16 
> > > > > 14:49:39 2024 +0100| [af6d52eec66961f6a502b0f2f390c12226d087cd] | 
> > > > > committer: Niklas Haas
> > > > >
> > > > > swscale: use 16-bit intermediate precision for RGB/XYZ conversion
> > > > >
> > > > > The current logic uses 12-bit linear light math, which is woefully 
> > > > > insufficient
> > > > > and leads to nasty postarization artifacts. This patch simply 
> > > > > switches the
> > > > > internal logic to 16-bit precision.
> > > > >
> > > > > This raises the memory requirement of these tables from 32 kB to 272 
> > > > > kB.
> > > > >
> > > > > All relevant FATE tests updated for improved accuracy.
> > > > >
> > > > > Fixes: #4829
> > > > > Signed-off-by: Niklas Haas 
> > > > > Sponsored-by: Sovereign Tech Fund
> > > > >
> > > > > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=af6d52eec66961f6a502b0f2f390c12226d087cd
> > > > > ---
> > > >
> > > > this breaks on x86-32
> > >
> > > ping
> > >
> > > the fate tests for a major architecture are broken since this
> > > This impacts future bisections over that range for example
> >
> > My bad, missed this email for some reason.
> >
> > Will investigate and fix tomorrow.
> 
> So, I found the bug, but I don't know how to fix it properly.
> 
> The problem is that tha XYZ/RGB conversion tables are calculated using excess
> precision from the x87 FPU. This results in slightly different rounding 
> behavior
> in exactly one case (i == 3415).
> 
> Fixing this requires setting -mfpmath=sse at compile time. Strangely, I was
> not able to force the compiler to discard the excess precision even with
> forcing -fexcess-precision=standard and storing every single subexpression to
> a `volatile double`.
> 
> How do we deal with such cases generally? I can think of several options, such
> as hard-coding the table values (unappealing), or somehow using integer math
> (very unappealing, how do we calculate an integer power without massive loss
> of precision?)

if its one case, would a
if(i == 3415)
abcd= 12345.98765

fix it ?

do i understand correctly that you want to compute
pow(i / 4095.0, xyzgamma)
or something like that without floats ?

exp(log(i/4095) * xyzgamma)

is a classic one, here you just need a fixed point implemenattion of
log and exp
see log16 and exp16 from tests/tiny_psnr.c, maybe they are neough
or could serve as examples for higher precission ones

thx

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

The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"


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] avcodec/exrdec: restore applying color transfer characteristics for float16 samples

2025-03-15 Thread Michael Niedermayer
On Sat, Mar 15, 2025 at 09:09:08PM -0300, James Almer wrote:
> On 3/15/2025 8:42 PM, Michael Niedermayer wrote:
> > Hi
> > 
> > On Sat, Mar 15, 2025 at 08:36:33PM -0300, James Almer wrote:
> > > On 3/15/2025 8:35 PM, Michael Niedermayer wrote:
> > > > Hi
> > > > 
> > > > On Thu, Mar 13, 2025 at 11:08:09PM -0300, James Almer wrote:
> > > > > Regression since 0e917389fe73c932049635d947bba076f1709589.
> > > > > This change also reverts commit 
> > > > > 431805c096738da7661a0baee2b12fe9724dcc95.
> > > > > 
> > > > > Signed-off-by: James Almer 
> > > > > ---
> > > > >libavcodec/exr.c | 38 --
> > > > >1 file changed, 36 insertions(+), 2 deletions(-)
> > > > 
> > > > We dont do that for any other codec.
> > > > For every other case we export all the color and gamma information
> > > > but do not modify the sample values to some "normalized" representation
> > > > 
> > > > Its also lossy to do it in the decoder like this
> > > > 
> > > > thx
> > > We're still doing it for the float path, so in that case you may want to
> > > remove it from there too.
> > 
> > I think we should remove it, but I think I have no samples for that code 
> > path.
> > So i would not be able to test ...
> > 
> > thx
> 
> Even with no samples it should be a straightforward change.
> But even then, since this feature includes two AVOptions that would be
> broken after such removal (and in fact currently are for half float
> samples), we should IMO deprecate them and remove the feature once the
> options are gone. That includes applying this patch to restore the
> functionality with half float samples.

sure, feel free to restore it and deprecate them
if thats whatr people prefer

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What is kyc? Its a tool that makes you give out your real ID, while criminals
give out a forged ID card.


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