[FFmpeg-devel] [PATCH] avcodec/cuviddec: update amount of decoder surfaces from within sequence decode callback

2023-06-05 Thread Roman Arzumanyan
Hello,

This patch reduces vRAM usage by cuvid decoder implementation.
The number of surfaces used for decoding is updated within the parser
sequence decode callback.
Also the "surfaces" AVDictionary option specific to cuvid was removed in
favor of "extra_hw_surfaces".

vRAM consumption was tested on various videos and savings are between 1%
for 360p resolution up to 21% for some 1080p H.264 videos.
Decoding performance was tested on various H.264 and H.265 videos in
different resolutions from 360p and higher, no performance penalty was
found.
From 32a1b016e88fa40b983318d4583750ef250a78d9 Mon Sep 17 00:00:00 2001
From: Roman Arzumanyan 
Date: Thu, 1 Jun 2023 11:17:39 +0300
Subject: [PATCH] libavcodec/cuviddec: determine DPB size from within cuvid
 parser

---
 libavcodec/cuviddec.c | 29 +++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 3d43bbd466..759ed49870 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -115,6 +115,12 @@ typedef struct CuvidParsedFrame
 
 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, ctx->cudl, x)
 
+// NV recommends [2;4] range
+#define CUVID_MAX_DISPLAY_DELAY (4)
+
+// Actual DPB size will be determined by parser.
+#define CUVID_DEFAULT_NUM_SURFACES (CUVID_MAX_DISPLAY_DELAY + 1)
+
 static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* format)
 {
 AVCodecContext *avctx = opaque;
@@ -309,6 +315,25 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
 return 0;
 }
 
+if (ctx->nb_surfaces < format->min_num_decode_surfaces + 3)
+ctx->nb_surfaces = format->min_num_decode_surfaces + 3;
+
+if (avctx->extra_hw_frames > 0)
+ctx->nb_surfaces += avctx->extra_hw_frames;
+
+if (0 > av_fifo_realloc2(ctx->frame_queue, ctx->nb_surfaces * sizeof(CuvidParsedFrame))) {
+av_log(avctx, AV_LOG_ERROR, "Failed to recreate frame queue on video sequence callback\n");
+ctx->internal_error = AVERROR(EINVAL);
+return 0;
+}
+
+ctx->key_frame = av_realloc_array(ctx->key_frame, ctx->nb_surfaces, sizeof(int));
+if (!ctx->key_frame) {
+av_log(avctx, AV_LOG_ERROR, "Failed to recreate key frame queue on video sequence callback\n");
+ctx->internal_error = AVERROR(EINVAL);
+return 0;
+}
+
 cuinfo.ulNumDecodeSurfaces = ctx->nb_surfaces;
 cuinfo.ulNumOutputSurfaces = 1;
 cuinfo.ulCreationFlags = cudaVideoCreate_PreferCUVID;
@@ -846,6 +871,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
 goto error;
 }
 
+ctx->nb_surfaces = CUVID_DEFAULT_NUM_SURFACES;
 ctx->frame_queue = av_fifo_alloc2(ctx->nb_surfaces, sizeof(CuvidParsedFrame), 0);
 if (!ctx->frame_queue) {
 ret = AVERROR(ENOMEM);
@@ -993,7 +1019,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
 }
 
 ctx->cuparseinfo.ulMaxNumDecodeSurfaces = ctx->nb_surfaces;
-ctx->cuparseinfo.ulMaxDisplayDelay = (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : 4;
+ctx->cuparseinfo.ulMaxDisplayDelay = (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : CUVID_MAX_DISPLAY_DELAY;
 ctx->cuparseinfo.pUserData = avctx;
 ctx->cuparseinfo.pfnSequenceCallback = cuvid_handle_video_sequence;
 ctx->cuparseinfo.pfnDecodePicture = cuvid_handle_picture_decode;
@@ -1097,7 +1123,6 @@ static const AVOption options[] = {
 { "bob",  "Bob deinterlacing",   0, AV_OPT_TYPE_CONST, { .i64 = cudaVideoDeinterlaceMode_Bob  }, 0, 0, VD, "deint" },
 { "adaptive", "Adaptive deinterlacing",  0, AV_OPT_TYPE_CONST, { .i64 = cudaVideoDeinterlaceMode_Adaptive }, 0, 0, VD, "deint" },
 { "gpu",  "GPU to be used for decoding", OFFSET(cu_gpu), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VD },
-{ "surfaces", "Maximum surfaces to be used for decoding", OFFSET(nb_surfaces), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, VD },
 { "drop_second_field", "Drop second field when deinterlacing", OFFSET(drop_second_field), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
 { "crop", "Crop (top)x(bottom)x(left)x(right)", OFFSET(crop_expr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VD },
 { "resize",   "Resize (width)x(height)", OFFSET(resize_expr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VD },
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 1/3] avutil/dict: add av_dict_pop

2023-06-05 Thread Stefano Sabatini
Il dom 4 giu 2023, 16:34 Marvin Scholz  ha scritto:

> On 4 Jun 2023, at 16:25, Stefano Sabatini wrote:
> [...]
> > About your patch, please mention that the pop operation is
> > destructive. We probably want to make that behavior configurable
> > through flags, but I'm fine to keep the current behavior for
> > consistency with the set(NULL) operation.
>
> What do you mean by "destructive"?
>

 I mean that the dictionary structure will be freed when the last element
is popped.
___
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] avutil/dict: add av_dict_pop

2023-06-05 Thread Anton Khirnov
Quoting Marvin Scholz (2023-05-01 13:44:54)
> diff --git a/libavutil/dict.h b/libavutil/dict.h
> index 713c9e361a..b2ab55a026 100644
> --- a/libavutil/dict.h
> +++ b/libavutil/dict.h
> @@ -172,6 +172,26 @@ int av_dict_set(AVDictionary **pm, const char *key, 
> const char *value, int flags
>   */
>  int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int 
> flags);
>  
> +/**
> + * Remove the entry with the given key from the dictionary.
> + *
> + * Search for an entry matching `key` and remove it, if found. Optionally
> + * the found key and/or value can be returned using the `out_key`/`out_value`
> + * arguments.
> + *
> + * If more than one entry matches, only one entry is removed and returned
> + * on each call. Which entry is returned first in that case is undefined.
> + *
> + * @param pmPointer to a pointer to a dictionary struct.
> + * @param key   Entry key to match.
> + * @param out_key   Pointer whose pointee will be set to the matched
> + *  entry key. Must be freed by the caller. May be NULL.
> + * @param out_value Pointer whose pointee will be set to the matched
> + *  entry value. Must be freed by the caller. May be NULL.

freed using av_free()

Should also mention what the function's return value is.


> diff --git a/tests/ref/fate/dict b/tests/ref/fate/dict
> index 7205e4c845..bdb097cb03 100644
> --- a/tests/ref/fate/dict
> +++ b/tests/ref/fate/dict
> @@ -48,3 +48,15 @@ Testing av_dict_set_int()
>  Testing av_dict_set() with existing AVDictionaryEntry.key as key
>  new val OK
>  new val OK
> +
> +Testing av_dict_pop() with existing AVDictionaryEntry.key as key
> +test-key: test-value (Return code: 0)
> +(null)
> +
> +Testing av_dict_pop() with nonexistent key
> +(null): (null) (Return code: -2)

I don't think anything guarantees that ENOENT has to be -2 on all
platforms we support.

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

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


Re: [FFmpeg-devel] [PATCH 3/3] avutil/dict: constify av_dict_get return

2023-06-05 Thread Anton Khirnov
Quoting Marvin Scholz (2023-05-01 13:44:56)
> ---
>  doc/examples/qsv_transcode.c   |  2 +-
>  libavcodec/libaomenc.c |  2 +-
>  libavcodec/libkvazaar.c|  2 +-
>  libavcodec/libsvtav1.c |  2 +-
>  libavcodec/libvpxenc.c |  2 +-
>  libavcodec/libx264.c   |  2 +-
>  libavcodec/libx265.c   |  2 +-
>  libavcodec/mjpegdec.c  |  2 +-
>  libavcodec/qsvenc.c|  2 +-
>  libavfilter/avfilter.c |  2 +-
>  libavfilter/f_bench.c  |  2 +-
>  libavfilter/f_drawgraph.c  |  2 +-
>  libavfilter/f_select.c |  4 +--
>  libavfilter/vf_cover_rect.c|  2 +-
>  libavfilter/vf_drawtext.c  |  2 +-
>  libavformat/aiffenc.c  |  2 +-
>  libavformat/argo_asf.c |  2 +-
>  libavformat/asfenc.c   |  6 ++--
>  libavformat/au.c   |  2 +-
>  libavformat/avformat.h |  2 +-
>  libavformat/avidec.c   |  2 +-
>  libavformat/avienc.c   |  2 +-
>  libavformat/avio.c |  4 +--
>  libavformat/dashenc.c  |  6 ++--
>  libavformat/dvenc.c|  2 +-
>  libavformat/flacdec.c  |  2 +-
>  libavformat/flacenc.c  |  6 ++--
>  libavformat/flvdec.c   |  2 +-
>  libavformat/gxfenc.c   |  2 +-
>  libavformat/http.c |  8 +++---
>  libavformat/id3v2.c|  6 ++--
>  libavformat/id3v2enc.c |  2 +-
>  libavformat/imfdec.c   |  2 +-
>  libavformat/matroskadec.c  |  2 +-
>  libavformat/mov.c  |  6 ++--
>  libavformat/movenc.c   | 46 +++---
>  libavformat/mp3enc.c   |  6 ++--
>  libavformat/mpegtsenc.c|  6 ++--
>  libavformat/mux.c  |  2 +-
>  libavformat/mux_utils.c|  2 +-
>  libavformat/mxfenc.c   | 14 -
>  libavformat/riffenc.c  |  2 +-
>  libavformat/rmenc.c|  2 +-
>  libavformat/sapenc.c   |  2 +-
>  libavformat/sdp.c  |  2 +-
>  libavformat/segment.c  |  4 +--
>  libavformat/soxenc.c   |  2 +-
>  libavformat/tee.c  |  2 +-
>  libavformat/ttmlenc.c  |  4 +--
>  libavformat/wavenc.c   |  4 +--
>  libavformat/webmdashenc.c  | 30 +--
>  libavutil/dict.c   |  9 +-
>  libavutil/dict.h   |  5 
>  libavutil/hwcontext_cuda.c |  2 +-
>  libavutil/hwcontext_qsv.c  |  2 +-
>  libavutil/hwcontext_vulkan.c   |  8 +++---
>  libavutil/version.h|  1 +
>  tests/api/api-threadmessage-test.c |  2 +-
>  58 files changed, 136 insertions(+), 123 deletions(-)

IMO this is an API break, and so should be postponed until the next
major bump.

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

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


Re: [FFmpeg-devel] [PATCH 1/3] avutil/dict: add av_dict_pop

2023-06-05 Thread Anton Khirnov
Quoting Stefano Sabatini (2023-06-05 10:08:07)
> Il dom 4 giu 2023, 16:34 Marvin Scholz  ha scritto:
> 
> > On 4 Jun 2023, at 16:25, Stefano Sabatini wrote:
> > [...]
> > > About your patch, please mention that the pop operation is
> > > destructive. We probably want to make that behavior configurable
> > > through flags, but I'm fine to keep the current behavior for
> > > consistency with the set(NULL) operation.
> >
> > What do you mean by "destructive"?
> >
> 
>  I mean that the dictionary structure will be freed when the last element
> is popped.

It is explicitly mentioned in the documentation that NULL is a valid
representation of an empty dictionary, so I don't think there's anything
destructive here.

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/cuviddec: update amount of decoder surfaces from within sequence decode callback

2023-06-05 Thread Anton Khirnov
Quoting Roman Arzumanyan (2023-06-05 09:30:07)
> Hello,
> 
> This patch reduces vRAM usage by cuvid decoder implementation.
> The number of surfaces used for decoding is updated within the parser
> sequence decode callback.
> Also the "surfaces" AVDictionary option specific to cuvid was removed in
> favor of "extra_hw_surfaces".

This can break existing workflows, you should deprecated the option
instead and only remove it after some time has passed.

> 
> vRAM consumption was tested on various videos and savings are between 1%
> for 360p resolution up to 21% for some 1080p H.264 videos.
> Decoding performance was tested on various H.264 and H.265 videos in
> different resolutions from 360p and higher, no performance penalty was
> found.
> 
> From 32a1b016e88fa40b983318d4583750ef250a78d9 Mon Sep 17 00:00:00 2001
> From: Roman Arzumanyan 
> Date: Thu, 1 Jun 2023 11:17:39 +0300
> Subject: [PATCH] libavcodec/cuviddec: determine DPB size from within cuvid
>  parser
> 
> ---
>  libavcodec/cuviddec.c | 29 +++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
> index 3d43bbd466..759ed49870 100644
> --- a/libavcodec/cuviddec.c
> +++ b/libavcodec/cuviddec.c
> @@ -115,6 +115,12 @@ typedef struct CuvidParsedFrame
>  
>  #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, ctx->cudl, x)
>  
> +// NV recommends [2;4] range
> +#define CUVID_MAX_DISPLAY_DELAY (4)
> +
> +// Actual DPB size will be determined by parser.
> +#define CUVID_DEFAULT_NUM_SURFACES (CUVID_MAX_DISPLAY_DELAY + 1)
> +
>  static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* 
> format)
>  {
>  AVCodecContext *avctx = opaque;
> @@ -309,6 +315,25 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
> *opaque, CUVIDEOFORMAT* form
>  return 0;
>  }
>  
> +if (ctx->nb_surfaces < format->min_num_decode_surfaces + 3)
> +ctx->nb_surfaces = format->min_num_decode_surfaces + 3;

FFMAX()

> +
> +if (avctx->extra_hw_frames > 0)
> +ctx->nb_surfaces += avctx->extra_hw_frames;
> +
> +if (0 > av_fifo_realloc2(ctx->frame_queue, ctx->nb_surfaces * 
> sizeof(CuvidParsedFrame))) {

this is the old deprecated AVFifoBuffer API, you cannot use it with
AVFifo objects

you should also forward the actual error code

> +av_log(avctx, AV_LOG_ERROR, "Failed to recreate frame queue on video 
> sequence callback\n");
> +ctx->internal_error = AVERROR(EINVAL);
> +return 0;
> +}
> +
> +ctx->key_frame = av_realloc_array(ctx->key_frame, ctx->nb_surfaces, 
> sizeof(int));
> +if (!ctx->key_frame) {
> +av_log(avctx, AV_LOG_ERROR, "Failed to recreate key frame queue on 
> video sequence callback\n");
> +ctx->internal_error = AVERROR(EINVAL);

Leaks key_frame on failure and should be ENOMEM.

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

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


Re: [FFmpeg-devel] [PATCH v2] avcodec/noise_bsf: Check for wrapped frames

2023-06-05 Thread Anton Khirnov
Quoting Michael Niedermayer (2023-06-04 21:53:22)
> Wrapped frames contain pointers so they need specific code to
> noise them, the generic code would lead to segfaults
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/noise_bsf.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c
> index 168f3aa373..2985a8ec4f 100644
> --- a/libavcodec/noise_bsf.c
> +++ b/libavcodec/noise_bsf.c
> @@ -86,6 +86,13 @@ static int noise_init(AVBSFContext *ctx)
>  return AVERROR(ENOMEM);
>  }
>  
> +if (ctx->par_in->codec_id == AV_CODEC_ID_WRAPPED_AVFRAME &&
> +strcmp(s->amount_str, "0")
> +) {

Why is this on a separate line?

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/cuviddec: update amount of decoder surfaces from within sequence decode callback

2023-06-05 Thread Roman Arzumanyan
Thanks for the review, Anton. Please find the updated patch attached.
BTW - what do you mean by "you should also forward the actual error code"?
Within the cuvid_handle_video_sequence() function in case of error,
function still returns 0 and sets internal context error, so I kept
behavior intact. Do I miss something?

пн, 5 июн. 2023 г. в 13:19, Anton Khirnov :

> Quoting Roman Arzumanyan (2023-06-05 09:30:07)
> > Hello,
> >
> > This patch reduces vRAM usage by cuvid decoder implementation.
> > The number of surfaces used for decoding is updated within the parser
> > sequence decode callback.
> > Also the "surfaces" AVDictionary option specific to cuvid was removed in
> > favor of "extra_hw_surfaces".
>
> This can break existing workflows, you should deprecated the option
> instead and only remove it after some time has passed.
>
> >
> > vRAM consumption was tested on various videos and savings are between 1%
> > for 360p resolution up to 21% for some 1080p H.264 videos.
> > Decoding performance was tested on various H.264 and H.265 videos in
> > different resolutions from 360p and higher, no performance penalty was
> > found.
> >
> > From 32a1b016e88fa40b983318d4583750ef250a78d9 Mon Sep 17 00:00:00 2001
> > From: Roman Arzumanyan 
> > Date: Thu, 1 Jun 2023 11:17:39 +0300
> > Subject: [PATCH] libavcodec/cuviddec: determine DPB size from within
> cuvid
> >  parser
> >
> > ---
> >  libavcodec/cuviddec.c | 29 +++--
> >  1 file changed, 27 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
> > index 3d43bbd466..759ed49870 100644
> > --- a/libavcodec/cuviddec.c
> > +++ b/libavcodec/cuviddec.c
> > @@ -115,6 +115,12 @@ typedef struct CuvidParsedFrame
> >
> >  #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, ctx->cudl, x)
> >
> > +// NV recommends [2;4] range
> > +#define CUVID_MAX_DISPLAY_DELAY (4)
> > +
> > +// Actual DPB size will be determined by parser.
> > +#define CUVID_DEFAULT_NUM_SURFACES (CUVID_MAX_DISPLAY_DELAY + 1)
> > +
> >  static int CUDAAPI cuvid_handle_video_sequence(void *opaque,
> CUVIDEOFORMAT* format)
> >  {
> >  AVCodecContext *avctx = opaque;
> > @@ -309,6 +315,25 @@ static int CUDAAPI cuvid_handle_video_sequence(void
> *opaque, CUVIDEOFORMAT* form
> >  return 0;
> >  }
> >
> > +if (ctx->nb_surfaces < format->min_num_decode_surfaces + 3)
> > +ctx->nb_surfaces = format->min_num_decode_surfaces + 3;
>
> FFMAX()
>
> > +
> > +if (avctx->extra_hw_frames > 0)
> > +ctx->nb_surfaces += avctx->extra_hw_frames;
> > +
> > +if (0 > av_fifo_realloc2(ctx->frame_queue, ctx->nb_surfaces *
> sizeof(CuvidParsedFrame))) {
>
> this is the old deprecated AVFifoBuffer API, you cannot use it with
> AVFifo objects
>
> you should also forward the actual error code
>
> > +av_log(avctx, AV_LOG_ERROR, "Failed to recreate frame queue on
> video sequence callback\n");
> > +ctx->internal_error = AVERROR(EINVAL);
> > +return 0;
> > +}
> > +
> > +ctx->key_frame = av_realloc_array(ctx->key_frame, ctx->nb_surfaces,
> sizeof(int));
> > +if (!ctx->key_frame) {
> > +av_log(avctx, AV_LOG_ERROR, "Failed to recreate key frame queue
> on video sequence callback\n");
> > +ctx->internal_error = AVERROR(EINVAL);
>
> Leaks key_frame on failure and should be ENOMEM.
>
> --
> Anton Khirnov
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
From 4aeff36c9d79c046e726bcc18a311754ace5c47e Mon Sep 17 00:00:00 2001
From: Roman Arzumanyan 
Date: Thu, 1 Jun 2023 11:17:39 +0300
Subject: [PATCH] libavcodec/cuviddec: determine amount of decoded surfaces
 from within cuvid parser

---
 libavcodec/cuviddec.c | 34 --
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 3d43bbd466..ef25c1d470 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -115,6 +115,12 @@ typedef struct CuvidParsedFrame
 
 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, ctx->cudl, x)
 
+// NV recommends [2;4] range
+#define CUVID_MAX_DISPLAY_DELAY (4)
+
+// Actual pool size will be determined by parser.
+#define CUVID_DEFAULT_NUM_SURFACES (CUVID_MAX_DISPLAY_DELAY + 1)
+
 static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* format)
 {
 AVCodecContext *avctx = opaque;
@@ -124,6 +130,7 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
 CUVIDDECODECREATEINFO cuinfo;
 int surface_fmt;
 int chroma_444;
+int fifo_size_inc;
 
 int old_width = avctx->width;
 int old_height = avctx->height;
@@ -309,6 +316,25 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
 return 0;
 }
 
+fifo_size_in

Re: [FFmpeg-devel] [PATCH] Optimization: support for libx264's mb_info

2023-06-05 Thread Carotti, Elias
Hi,
please find attached the patch which I updated according to your
suggestions.
Best,
Elias




On Sun, 2023-06-04 at 17:29 +0200, Stefano Sabatini wrote:
> CAUTION: This email originated from outside of the organization. Do
> not click links or open attachments unless you can confirm the sender
> and know the content is safe.
> 
> 
> 
> On date Monday 2023-05-29 17:56:55 +, Carotti, Elias wrote:
> [...]
> > From 7cb97ee977197e310a932b2d7a53bf5c6e0e Mon Sep 17 00:00:00
> > 2001
> > From: Elias Carotti 
> > Date: Wed, 19 Apr 2023 11:49:39 +0200
> > Subject: [PATCH] Add support for libx264's MB_INFO
> > 
> > libx264's x264_image_properties_t, which is passed to the encoding
> > function,
> > contains a field to pass down information on the portions of the
> > frame which
> > changed with respect to the previous one (used for prediction) to
> > mark
> > unchanged macroblocks P_SKIP.
> > ---
> >  libavcodec/libx264.c    | 81 +
> >  libavutil/Makefile  |  4 ++
> >  libavutil/frame.h   | 10 +
> >  libavutil/video_hint_info.c | 89
> > +
> >  libavutil/video_hint_info.h | 87
> > 
> >  5 files changed, 271 insertions(+)
> >  create mode 100644 libavutil/video_hint_info.c
> >  create mode 100644 libavutil/video_hint_info.h
> > 
> > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > index 5736f1efa7..32fa80d0a1 100644
> > --- a/libavcodec/libx264.c
> > +++ b/libavcodec/libx264.c
> > @@ -30,6 +30,7 @@
> >  #include "libavutil/stereo3d.h"
> >  #include "libavutil/time.h"
> >  #include "libavutil/intreadwrite.h"
> > +#include "libavutil/video_hint_info.h"
> >  #include "avcodec.h"
> >  #include "codec_internal.h"
> >  #include "encode.h"
> > @@ -48,6 +49,9 @@
> >  // from x264.h, for quant_offsets, Macroblocks are 16x16
> >  // blocks of pixels (with respect to the luma plane)
> >  #define MB_SIZE 16
> > +#define MB_LSIZE 4
> > +#define MB_FLOOR(x)  ((x) >> (MB_LSIZE))
> > +#define MB_CEIL(x)   MB_FLOOR((x) + (MB_SIZE - 1))
> > 
> >  typedef struct X264Opaque {
> >  #if FF_API_REORDERED_OPAQUE
> > @@ -123,6 +127,8 @@ typedef struct X264Context {
> >   * encounter a frame with ROI side data.
> >   */
> >  int roi_warned;
> > +
> > +    int mb_info;
> >  } X264Context;
> > 
> >  static void X264_log(void *p, int level, const char *fmt, va_list
> > args)
> > @@ -295,6 +301,7 @@ static void free_picture(x264_picture_t *pic)
> >  av_free(pic->extra_sei.payloads[i].payload);
> >  av_freep(&pic->extra_sei.payloads);
> >  av_freep(&pic->prop.quant_offsets);
> > +    av_freep(&pic->prop.mb_info);
> >  pic->extra_sei.num_payloads = 0;
> >  }
> > 
> > @@ -320,6 +327,64 @@ static enum AVPixelFormat csp_to_pixfmt(int
> > csp)
> >  return AV_PIX_FMT_NONE;
> >  }
> > 
> > +static int setup_mb_info(AVCodecContext *ctx, x264_picture_t *pic,
> > + const AVFrame *frame,
> > + const AVVideoHint *info)
> > +{
> 
> > +    int mb_width = (frame->width + MB_SIZE - 1) / MB_SIZE;
> > +    int mb_height = (frame->height + MB_SIZE - 1) / MB_SIZE;
> 
> 
> > +
> > +    const AVVideoRect *mbinfo_rects;
> > +    int nb_rects;
> > +    uint8_t *mbinfo;
> > +
> > +    mbinfo_rects = (const AVVideoRect *)av_video_hint_rects(info);
> > +    nb_rects = info->nb_rects;
> > +
> > +    mbinfo = av_calloc(mb_width * mb_height, sizeof(*mbinfo));
> > +    if (!mbinfo)
> > +    return AVERROR(ENOMEM);
> > +
> 
> > +    if (info->type == AV_VIDEO_HINT_CHANGED) {
> > +    /* Sets the default as constant, i.e. P_SKIP-able, then
> > selectively resets the flag */
> > +    memset(mbinfo, X264_MBINFO_CONSTANT, sizeof(*mbinfo) *
> > mb_width * mb_height);
> > +
> > +    for (int i = 0; i < nb_rects; i++) {
> > +    int min_y = MB_FLOOR(mbinfo_rects->y);
> > +    int max_y = MB_CEIL(mbinfo_rects->y + mbinfo_rects-
> > >height);
> > +    int min_x = MB_FLOOR(mbinfo_rects->x);
> > +    int max_x = MB_CEIL(mbinfo_rects->x + mbinfo_rects-
> > >width);
> > +
> > +    for (int mb_y = min_y; mb_y < max_y; ++mb_y) {
> > +    memset(mbinfo + mb_y * mb_width + min_x, 0, max_x
> > - min_x);
> > +    }
> > +
> > +    mbinfo_rects++;
> > +    }
> > +    } else {
> > +    /* Sets the default as changed, i.e. *not* P_SKIP-able,
> > then selectively sets the flag */
> > +    memset(mbinfo, 0, sizeof(*mbinfo) * mb_width * mb_height);
> > +
> > +    for (int i = 0; i < nb_rects; i++) {
> > +    int min_y = MB_CEIL(mbinfo_rects->y);
> > +    int max_y = MB_FLOOR(mbinfo_rects->y + mbinfo_rects-
> > >height);
> > +    int min_x = MB_CEIL(mbinfo_rects->x);
> > +    int max_x = MB_FLOOR(mbinfo_rects->x + mbinfo_rects-
> > >width);
> > +
> > +    for (int mb_y = min_y; mb_y < max_y; ++mb_y) {
> > +    memset(m

Re: [FFmpeg-devel] [PATCH v4 0/2] Animated JPEG XL Support

2023-06-05 Thread Leo Izen

On 6/2/23 11:03, Leo Izen wrote:

On 5/26/23 16:55, Leo Izen wrote:

Changes from v3:
  - Use avctx->internal->in_pkt instead of allocating a new packet.

Leo Izen (2):
   avcodec/libjxldec: add animated decode support
   avformat/jpegxl_anim_dec: add animated JPEG XL demuxer



Will rebase onto master and merge soon, if there's no objections.

- Leo Izen (Traneptora / thebombzen)



Pushed as 99da411322e1 and fa11c4c7fa39.

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

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


Re: [FFmpeg-devel] [PATCH v2 5/5] aarch64: Add Windows runtime detection of the dotprod instructions

2023-06-05 Thread James Zern
On Tue, May 30, 2023 at 5:31 AM Martin Storsjö  wrote:
>
> For Windows, there's no publicly defined constant for checking for
> the i8mm extension yet.
> ---
>  libavutil/aarch64/cpu.c | 10 ++
>  1 file changed, 10 insertions(+)
>
> diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c
> index ffb00f6dd2..4b97530240 100644
> --- a/libavutil/aarch64/cpu.c
> +++ b/libavutil/aarch64/cpu.c
> @@ -94,6 +94,16 @@ static int detect_flags(void)
>  return flags;
>  }
>
> +#elif defined(_WIN32)
> +#include 
> +
> +static int detect_flags(void)
> +{
> +int flags = 0;
> +if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE))

I think this requires a recent Windows SDK, is compatibility a concern?
lgtm otherwise.
___
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/jpeg2000htdec: Check for invalid magref length.

2023-06-05 Thread etemesicaleb
From: caleb 

---
 libavcodec/jpeg2000htdec.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index 51cd96e0f1..474d671ee0 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -1101,8 +1101,8 @@ static void jpeg2000_decode_sigprop_segment(Jpeg2000Cblk 
*cblk, uint16_t width,
  * See procedure decodeSigPropMag at Rec. ITU-T T.814, 7.5.
 */
 static int
-jpeg2000_decode_magref_segment(Jpeg2000Cblk *cblk, uint16_t width, uint16_t 
block_height, uint8_t *magref_segment,
-   uint32_t magref_length, uint8_t pLSB, int32_t 
*sample_buf, uint8_t *block_states)
+jpeg2000_decode_magref_segment(const Jpeg2000DecoderContext *s,Jpeg2000Cblk 
*cblk, uint16_t width, uint16_t block_height, uint8_t *magref_segment,
+   uint32_t magref_length, uint8_t pLSB, int32_t 
*sample_buf, uint8_t *block_states)
 {
 
 StateVars mag_ref   = { 0 };
@@ -,6 +,10 @@ jpeg2000_decode_magref_segment(Jpeg2000Cblk *cblk, 
uint16_t width, uint16_t bloc
 uint16_t i_start= 0;
 int32_t *sp;
 
+if (magref_length < 2){
+av_log(s->avctx,AV_LOG_ERROR,"Invalid magnitude refinement length\n");
+return AVERROR_INVALIDDATA;
+}
 jpeg2000_init_mag_ref(&mag_ref, magref_length);
 
 for (int n1 = 0; n1 < num_v_stripe; n1++) {
@@ -1261,7 +1265,7 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, 
Jpeg2000CodingStyle *c
 pLSB - 1, sample_buf, block_states);
 
 if (cblk->npasses > 2)
-if ((ret = jpeg2000_decode_magref_segment(cblk, width, height, Dref, 
Lref,
+if ((ret = jpeg2000_decode_magref_segment(s,cblk, width, height, Dref, 
Lref,
   pLSB - 1, sample_buf, block_states)) 
< 0)
 goto free;
 
-- 
2.40.1

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

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


Re: [FFmpeg-devel] [PATCH] tools/target_dec_fuzzer: Test lowres

2023-06-05 Thread Michael Niedermayer
On Sun, Jan 08, 2023 at 01:59:08PM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  tools/target_dec_fuzzer.c | 4 
>  1 file changed, 4 insertions(+)

will apply


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


Re: [FFmpeg-devel] [PATCH v2] avcodec/noise_bsf: Check for wrapped frames

2023-06-05 Thread Michael Niedermayer
On Mon, Jun 05, 2023 at 12:21:13PM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2023-06-04 21:53:22)
> > Wrapped frames contain pointers so they need specific code to
> > noise them, the generic code would lead to segfaults
> > 
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/noise_bsf.c | 7 +++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c
> > index 168f3aa373..2985a8ec4f 100644
> > --- a/libavcodec/noise_bsf.c
> > +++ b/libavcodec/noise_bsf.c
> > @@ -86,6 +86,13 @@ static int noise_init(AVBSFContext *ctx)
> >  return AVERROR(ENOMEM);
> >  }
> >  
> > +if (ctx->par_in->codec_id == AV_CODEC_ID_WRAPPED_AVFRAME &&
> > +strcmp(s->amount_str, "0")
> > +) {
> 
> Why is this on a separate line?

Probably because i pressed the enter key. Ill remove the \n

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


Re: [FFmpeg-devel] [PATCH v10 0/6] Support enhanced flv in FFmpeg

2023-06-05 Thread Steven Liu
Neal Gompa  于2023年5月31日周三 13:47写道:
>
> On Mon, May 15, 2023 at 10:41 PM Neal Gompa  wrote:
> >
> > On Mon, May 15, 2023 at 4:32 AM Steven Liu  wrote:
> > >
> > > Reference file: 
> > > https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
> > > The Enhanced flv has been supported by OBS, Simple Realtime Server, 
> > > mpegts.js.
> > > you can publish hevc, av1 or vp9 codec stream to Youtube over rtmp.
> > > The enhanced flv documentation contributors include
> > > Jean-Baptiste Kempf (FFmpeg, VideoLAN).
> > > So this should be support by ffmpeg too.
> > >
> > > v8:
> > > Support vp9 codec according to enhanced flv.
> > > Support PacketTypeCodedFrames type for hevc in flv.
> > > v9:
> > > Add dependency codec object files for flvenc in Makefile.
> > > Move the hevc,av1,vp9 codec out of FF_COMPLIANCE_UNOFFICIAL.
> > >
> > > v10:
> > > modify first patch comment like the others before commit.
> > > exheader mode should only happened in video stream this patchset.
> > >
> > > Steven Liu (6):
> > >   avformat/flvenc: support mux hevc in enhanced flv
> > >   avformat/flvdec: support demux hevc in enhanced flv
> > >   avformat/flvenc: support mux av1 in enhanced flv
> > >   avformat/flvdec: support demux av1 in enhanced flv
> > >   avformat/flvenc: support mux vp9 in enhanced flv
> > >   avformat/flvdec: support demux vp9 in enhanced flv
> > >
> > >  libavformat/Makefile |  2 +-
> > >  libavformat/flv.h| 15 +
> > >  libavformat/flvdec.c | 73 +++-
> > >  libavformat/flvenc.c | 58 +--
> > >  4 files changed, 130 insertions(+), 18 deletions(-)
> > >
> >
> > This version works for me. Thanks for this work!
> >
> > Tested-by: Neal Gompa 
> > Reviewed-by: Neal Gompa 
> >
>
> Is this patch set going to get pushed to master anytime soon?

Hi Neal,

Do you agree move the enhanced flv support into experimental flags?



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