Re: [FFmpeg-devel] [PATCH v4 1/1] avfilter/vf_colorspace: use colorspace negotiation API

2024-04-05 Thread Niklas Haas
On Thu, 04 Apr 2024 19:05:14 +0200 Nicolas Gaullier 
 wrote:
> Fixes a regression due to the fact that the colorspace filter does
> not use the new API introduced by 8c7934f73ab6c568acaa.
> The scale filter uses it since 45e09a30419cc2a7251e, and the setparams
> filter since 3bf80df3ccd32aed23f0.
> 
> Example:
> ffprobe -f lavfi yuvtestsrc,setparams=color_primaries=bt470bg:color_trc=
> bt470bg:colorspace=bt470bg,colorspace=bt709:range=tv,scale,showinfo
> 
> Before:
>   color_range:unknown color_space:bt470bg ...
> After:
>   color_range:tv color_space:bt709 ...
> 
> Signed-off-by: Nicolas Gaullier 
> ---
>  libavfilter/vf_colorspace.c | 62 +
>  1 file changed, 36 insertions(+), 26 deletions(-)
> 
> diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c
> index d181e81ace..7bacd7892a 100644
> --- a/libavfilter/vf_colorspace.c
> +++ b/libavfilter/vf_colorspace.c
> @@ -433,8 +433,7 @@ static int create_filtergraph(AVFilterContext *ctx,
>  if (out->color_trc   != s->out_trc) s->out_txchr = NULL;
>  if (in->colorspace   != s->in_csp ||
>  in->color_range  != s->in_rng)  s->in_lumacoef   = NULL;
> -if (out->colorspace  != s->out_csp ||
> -out->color_range != s->out_rng) s->out_lumacoef  = NULL;
> +if (out->color_range != s->out_rng) s->rgb2yuv   = NULL;
>  
>  if (!s->out_primaries || !s->in_primaries) {
>  s->in_prm = in->color_primaries;
> @@ -563,26 +562,8 @@ static int create_filtergraph(AVFilterContext *ctx,
>  redo_yuv2rgb = 1;
>  }
>  
> -if (!s->out_lumacoef) {
> -s->out_csp = out->colorspace;
> +if (!s->rgb2yuv) {
>  s->out_rng = out->color_range;
> -s->out_lumacoef = av_csp_luma_coeffs_from_avcsp(s->out_csp);
> -if (!s->out_lumacoef) {
> -if (s->out_csp == AVCOL_SPC_UNSPECIFIED) {
> -if (s->user_all == CS_UNSPECIFIED) {
> -av_log(ctx, AV_LOG_ERROR,
> -   "Please specify output colorspace\n");
> -} else {
> -av_log(ctx, AV_LOG_ERROR,
> -   "Unsupported output color property %d\n", 
> s->user_all);
> -}
> -} else {
> -av_log(ctx, AV_LOG_ERROR,
> -   "Unsupported output colorspace %d (%s)\n", s->out_csp,
> -   av_color_space_name(s->out_csp));
> -}
> -return AVERROR(EINVAL);
> -}
>  redo_rgb2yuv = 1;
>  }
>  
> @@ -687,6 +668,26 @@ static av_cold int init(AVFilterContext *ctx)
>  {
>  ColorSpaceContext *s = ctx->priv;
>  
> +s->out_csp  = s->user_csp == AVCOL_SPC_UNSPECIFIED ?
> +  default_csp[FFMIN(s->user_all, CS_NB)] : s->user_csp;
> +s->out_lumacoef = av_csp_luma_coeffs_from_avcsp(s->out_csp);
> +if (!s->out_lumacoef) {
> +if (s->out_csp == AVCOL_SPC_UNSPECIFIED) {
> +if (s->user_all == CS_UNSPECIFIED) {
> +av_log(ctx, AV_LOG_ERROR,
> +   "Please specify output colorspace\n");
> +} else {
> +av_log(ctx, AV_LOG_ERROR,
> +   "Unsupported output color property %d\n", 
> s->user_all);
> +}
> +} else {
> +av_log(ctx, AV_LOG_ERROR,
> +   "Unsupported output colorspace %d (%s)\n", s->out_csp,
> +   av_color_space_name(s->out_csp));
> +}
> +return AVERROR(EINVAL);
> +}
> +
>  ff_colorspacedsp_init(>dsp);
>  
>  return 0;
> @@ -735,6 +736,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  return res;
>  }
>  
> +out->colorspace =  s->out_csp;
> +out->color_range = s->user_rng == AVCOL_RANGE_UNSPECIFIED ?
> +   in->color_range : s->user_rng;
>  out->color_primaries = s->user_prm == AVCOL_PRI_UNSPECIFIED ?
> default_prm[FFMIN(s->user_all, CS_NB)] : 
> s->user_prm;
>  if (s->user_trc == AVCOL_TRC_UNSPECIFIED) {
> @@ -746,10 +750,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  } else {
>  out->color_trc   = s->user_trc;
>  }
> -out->colorspace  = s->user_csp == AVCOL_SPC_UNSPECIFIED ?
> -   default_csp[FFMIN(s->user_all, CS_NB)] : 
> s->user_csp;
> -out->color_range = s->user_rng == AVCOL_RANGE_UNSPECIFIED ?
> -   in->color_range : s->user_rng;
>  if (rgb_sz != s->rgb_sz) {
>  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(out->format);
>  int uvw = in->width >> desc->log2_chroma_w;
> @@ -841,8 +841,18 @@ static int query_formats(AVFilterContext *ctx)
>  };
>  int res;
>  ColorSpaceContext *s = ctx->priv;
> +AVFilterLink *outlink = ctx->outputs[0];
>  AVFilterFormats *formats = ff_make_format_list(pix_fmts);
>  
> +   

[FFmpeg-devel] [PATCH 14/15] avcodec/mpeg12dec: Remove redundant mpeg_enc_ctx_allocated

2024-04-05 Thread Andreas Rheinhardt
Use context_initialized from the underlying MpegEncContext
instead. Also don't check before ff_mpv_common_end()
in mpeg_decode_end().

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12dec.c | 36 
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 45627e702d..21a214ef5b 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -71,7 +71,6 @@ enum Mpeg2ClosedCaptionsFormat {
 
 typedef struct Mpeg1Context {
 MpegEncContext mpeg_enc_ctx;
-int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
 int repeat_field;   /* true if we must repeat the field */
 AVPanScan pan_scan; /* some temporary storage for the panscan */
 AVStereo3D stereo3d;
@@ -803,7 +802,6 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx)
 ff_mpeg12_init_vlcs();
 
 s2->chroma_format  = 1;
-s->mpeg_enc_ctx_allocated  = 0;
 s->repeat_field= 0;
 avctx->color_range = AVCOL_RANGE_MPEG;
 return 0;
@@ -817,16 +815,14 @@ static int 
mpeg_decode_update_thread_context(AVCodecContext *avctx,
 MpegEncContext *s = >mpeg_enc_ctx, *s1 = _from->mpeg_enc_ctx;
 int err;
 
-if (avctx == avctx_from   ||
-!ctx_from->mpeg_enc_ctx_allocated ||
-!s1->context_initialized)
+if (avctx == avctx_from || !s1->context_initialized)
 return 0;
 
 err = ff_mpeg_update_thread_context(avctx, avctx_from);
 if (err)
 return err;
 
-if (!ctx->mpeg_enc_ctx_allocated)
+if (!s->context_initialized)
 memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
 
 return 0;
@@ -961,7 +957,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
 }
 
-if ((s1->mpeg_enc_ctx_allocated == 0)   ||
+if (!s->context_initialized ||
 avctx->coded_width   != s->width||
 avctx->coded_height  != s->height   ||
 s1->save_width   != s->width||
@@ -969,10 +965,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
 av_cmp_q(s1->save_aspect, s->avctx->sample_aspect_ratio) ||
 (s1->save_progressive_seq != s->progressive_sequence && 
FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
 0) {
-if (s1->mpeg_enc_ctx_allocated) {
+if (s->context_initialized)
 ff_mpv_common_end(s);
-s1->mpeg_enc_ctx_allocated = 0;
-}
 
 ret = ff_set_dimensions(avctx, s->width, s->height);
 if (ret < 0)
@@ -1029,8 +1023,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 if ((ret = ff_mpv_common_init(s)) < 0)
 return ret;
-
-s1->mpeg_enc_ctx_allocated = 1;
 }
 return 0;
 }
@@ -1233,7 +1225,7 @@ static int 
mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
 s->mpeg_f_code[0][1] += !s->mpeg_f_code[0][1];
 s->mpeg_f_code[1][0] += !s->mpeg_f_code[1][0];
 s->mpeg_f_code[1][1] += !s->mpeg_f_code[1][1];
-if (!s->pict_type && s1->mpeg_enc_ctx_allocated) {
+if (!s->pict_type && s->context_initialized) {
 av_log(s->avctx, AV_LOG_ERROR, "Missing picture start code\n");
 if (s->avctx->err_recognition & AV_EF_EXPLODE)
 return AVERROR_INVALIDDATA;
@@ -1740,7 +1732,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
 Mpeg1Context *s1  = avctx->priv_data;
 MpegEncContext *s = >mpeg_enc_ctx;
 
-if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr)
+if (!s->context_initialized || !s->current_picture_ptr)
 return 0;
 
 if (s->avctx->hwaccel) {
@@ -1881,10 +1873,9 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
 
 /* start new MPEG-1 context decoding */
 s->out_format = FMT_MPEG1;
-if (s1->mpeg_enc_ctx_allocated) {
+if (s->context_initialized)
 ff_mpv_common_end(s);
-s1->mpeg_enc_ctx_allocated = 0;
-}
+
 s->width= avctx->coded_width;
 s->height   = avctx->coded_height;
 avctx->has_b_frames = 0; // true?
@@ -1894,7 +1885,6 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
 
 if ((ret = ff_mpv_common_init(s)) < 0)
 return ret;
-s1->mpeg_enc_ctx_allocated = 1;
 
 for (i = 0; i < 64; i++) {
 int j = s->idsp.idct_permutation[i];
@@ -2448,7 +2438,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame 
*picture,
 break;
 }
 
-if (!s->mpeg_enc_ctx_allocated)
+if (!s2->context_initialized)
 break;
 
 if (s2->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
@@ -2546,9 +2536,8 @@ static int mpeg_decode_frame(AVCodecContext *avctx, 
AVFrame *picture,
 return buf_size;
 }
 
-if 

[FFmpeg-devel] [PATCH 15/15] avcodec/mpegvideo_dec, h264_slice: Return proper error codes

2024-04-05 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_slice.c| 2 +-
 libavcodec/mpegvideo_dec.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 4b01c54147..a346839902 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -483,7 +483,7 @@ static int h264_frame_start(H264Context *h)
 
 if (!ff_thread_can_start_frame(h->avctx)) {
 av_log(h->avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP 
state\n");
-return -1;
+return AVERROR_BUG;
 }
 
 release_unused_pictures(h, 1);
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index d337a6565b..4353f1fd68 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -328,7 +328,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 
 if (!ff_thread_can_start_frame(avctx)) {
 av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP 
state\n");
-return -1;
+return AVERROR_BUG;
 }
 
 /* mark & release old frames */
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 12/15] avcodec/mpegvideo_dec: Move getting Picture slot into alloc_picture()

2024-04-05 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c | 63 --
 1 file changed, 26 insertions(+), 37 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index b6ef4e5582..d337a6565b 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -235,12 +235,20 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s)
 return err;
 }
 
-static int alloc_picture(MpegEncContext *s, Picture *pic)
+static int alloc_picture(MpegEncContext *s, Picture **picp, int reference)
 {
 AVCodecContext *avctx = s->avctx;
+int idx = ff_find_unused_picture(s->avctx, s->picture, 0);
+Picture *pic;
 int ret;
 
+if (idx < 0)
+return idx;
+
+pic = >picture[idx];
+
 pic->tf.f = pic->f;
+pic->reference = reference;
 
 /* WM Image / Screen codecs allocate internal buffers with different
  * dimensions / colorspaces; ignore user-defined callbacks for these. */
@@ -248,7 +256,7 @@ static int alloc_picture(MpegEncContext *s, Picture *pic)
 avctx->codec_id != AV_CODEC_ID_VC1IMAGE  &&
 avctx->codec_id != AV_CODEC_ID_MSS2) {
 ret = ff_thread_get_ext_buffer(avctx, >tf,
-   pic->reference ? AV_GET_BUFFER_FLAG_REF 
: 0);
+   reference ? AV_GET_BUFFER_FLAG_REF : 0);
 } else {
 pic->f->width  = avctx->width;
 pic->f->height = avctx->height;
@@ -262,9 +270,14 @@ static int alloc_picture(MpegEncContext *s, Picture *pic)
 if (ret < 0)
 goto fail;
 
-return ff_alloc_picture(s->avctx, pic, >me, >sc, 0, s->out_format,
-s->mb_stride, s->mb_width, s->mb_height, 
s->b8_stride,
->linesize, >uvlinesize);
+ret = ff_alloc_picture(s->avctx, pic, >me, >sc, 0, s->out_format,
+   s->mb_stride, s->mb_width, s->mb_height, 
s->b8_stride,
+   >linesize, >uvlinesize);
+if (ret < 0)
+goto fail;
+*picp = pic;
+
+return 0;
 fail:
 ff_mpeg_unref_picture(pic);
 return ret;
@@ -272,27 +285,16 @@ fail:
 
 static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp)
 {
-int idx = ff_find_unused_picture(s->avctx, s->picture, 0);
 Picture *pic;
-int ret;
-
-if (idx < 0)
-return idx;
-
-pic = >picture[idx];
-
-pic->reference= 3;
-pic->f->pict_type = AV_PICTURE_TYPE_P;
-
-ret = alloc_picture(s, pic);
+int ret = alloc_picture(s, picp, 1);
 if (ret < 0)
 return ret;
 
+pic = *picp;
+
 ff_thread_report_progress(>tf, INT_MAX, 0);
 ff_thread_report_progress(>tf, INT_MAX, 1);
 
-*picp = pic;
-
 return 0;
 }
 
@@ -320,8 +322,7 @@ static void color_frame(AVFrame *frame, int luma)
  */
 int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
 {
-Picture *pic;
-int idx, ret;
+int ret;
 
 s->mb_skipped = 0;
 
@@ -351,23 +352,11 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 ff_mpeg_unref_picture(>last_picture);
 ff_mpeg_unref_picture(>next_picture);
 
-idx = ff_find_unused_picture(s->avctx, s->picture, 0);
-if (idx < 0) {
-av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
-return idx;
-}
-pic = >picture[idx];
-
-pic->reference = 0;
-if (!s->droppable) {
-if (s->pict_type != AV_PICTURE_TYPE_B)
-pic->reference = 3;
-}
-
-if (alloc_picture(s, pic) < 0)
-return -1;
+ret = alloc_picture(s, >current_picture_ptr,
+s->pict_type != AV_PICTURE_TYPE_B && !s->droppable);
+if (ret < 0)
+return ret;
 
-s->current_picture_ptr = pic;
 s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * 
!!s->top_field_first;
 s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * 
(!s->progressive_frame &&
 
!s->progressive_sequence);
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 13/15] avcodec/mpegvideo: Remove pointless check

2024-04-05 Thread Andreas Rheinhardt
Possible since 315c956cbd14f021e49dac7fc0b906fad1672aad.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 8a733afdb8..7af823b8bd 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -789,9 +789,6 @@ void ff_mpv_common_end(MpegEncContext *s)
 av_freep(>bitstream_buffer);
 s->allocated_bitstream_buffer_size = 0;
 
-if (!s->avctx)
-return;
-
 if (s->picture) {
 for (int i = 0; i < MAX_PICTURE_COUNT; i++)
 ff_mpv_picture_free(>picture[i]);
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 02/15] avcodec/mpegutils: Move definitions to better places

2024-04-05 Thread Andreas Rheinhardt
FRAME_SKIPPED -> h263dec.h
CANDIDATE_MB_TYPE_* -> mpegvideoenc.h
INPLACE_OFFSET -> mpegvideoenc.h
enum OutputFormat -> mpegvideo.h

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h263dec.c   |  1 -
 libavcodec/h263dec.h   |  5 +
 libavcodec/intelh263dec.c  |  2 --
 libavcodec/mpeg4videoenc.c |  1 -
 libavcodec/mpegpicture.c   |  2 +-
 libavcodec/mpegutils.h | 34 --
 libavcodec/mpegvideo.h | 12 +---
 libavcodec/mpegvideoenc.h  | 19 +++
 libavcodec/nvdec_mpeg12.c  |  1 +
 libavcodec/ratecontrol.c   |  1 -
 libavcodec/rv10.c  |  1 -
 libavcodec/vc1dec.c|  1 +
 12 files changed, 36 insertions(+), 44 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 910df7585f..48bd467f30 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -42,7 +42,6 @@
 #include "mpeg4video.h"
 #include "mpeg4videodec.h"
 #include "mpeg4videodefs.h"
-#include "mpegutils.h"
 #include "mpegvideo.h"
 #include "mpegvideodec.h"
 #include "msmpeg4dec.h"
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index 89c5fcf58f..a01acc0834 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -23,6 +23,11 @@
 #include "mpegvideo.h"
 #include "vlc.h"
 
+/**
+ * Return value for header parsers if frame is not coded.
+ * */
+#define FRAME_SKIPPED 100
+
 // The defines below define the number of bits that are read at once for
 // reading vlc values. Changing these may improve speed and data cache needs
 // be aware though that decreasing them may need the number of stages that is
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index f8eeb6b44e..5d34892ef7 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -19,12 +19,10 @@
  */
 
 #include "codec_internal.h"
-#include "mpegutils.h"
 #include "mpegvideo.h"
 #include "mpegvideodec.h"
 #include "h263data.h"
 #include "h263dec.h"
-#include "mpegvideodata.h"
 
 /* don't understand why they choose a different header ! */
 int ff_intel_h263_decode_picture_header(MpegEncContext *s)
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index f806ad8a74..71dda802e2 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -26,7 +26,6 @@
 #include "libavutil/opt.h"
 #include "libavutil/thread.h"
 #include "codec_internal.h"
-#include "mpegutils.h"
 #include "mpegvideo.h"
 #include "h263.h"
 #include "h263enc.h"
diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index 5bf85bb7fe..06b6daa01a 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -29,7 +29,7 @@
 #include "avcodec.h"
 #include "motion_est.h"
 #include "mpegpicture.h"
-#include "mpegutils.h"
+#include "mpegvideo.h"
 #include "refstruct.h"
 #include "threadframe.h"
 
diff --git a/libavcodec/mpegutils.h b/libavcodec/mpegutils.h
index 386110bb8c..3da1e7ed38 100644
--- a/libavcodec/mpegutils.h
+++ b/libavcodec/mpegutils.h
@@ -27,11 +27,6 @@
 
 #include "avcodec.h"
 
-/**
- * Return value for header parsers if frame is not coded.
- * */
-#define FRAME_SKIPPED 100
-
 /* picture type */
 #define PICT_TOP_FIELD 1
 #define PICT_BOTTOM_FIELD  2
@@ -93,35 +88,6 @@
 
 #define HAS_CBP(a)   ((a) & MB_TYPE_CBP)
 
-/* MB types for encoding */
-#define CANDIDATE_MB_TYPE_INTRA  (1 <<  0)
-#define CANDIDATE_MB_TYPE_INTER  (1 <<  1)
-#define CANDIDATE_MB_TYPE_INTER4V(1 <<  2)
-#define CANDIDATE_MB_TYPE_SKIPPED(1 <<  3)
-
-#define CANDIDATE_MB_TYPE_DIRECT (1 <<  4)
-#define CANDIDATE_MB_TYPE_FORWARD(1 <<  5)
-#define CANDIDATE_MB_TYPE_BACKWARD   (1 <<  6)
-#define CANDIDATE_MB_TYPE_BIDIR  (1 <<  7)
-
-#define CANDIDATE_MB_TYPE_INTER_I(1 <<  8)
-#define CANDIDATE_MB_TYPE_FORWARD_I  (1 <<  9)
-#define CANDIDATE_MB_TYPE_BACKWARD_I (1 << 10)
-#define CANDIDATE_MB_TYPE_BIDIR_I(1 << 11)
-
-#define CANDIDATE_MB_TYPE_DIRECT0(1 << 12)
-
-#define INPLACE_OFFSET 16
-
-enum OutputFormat {
-FMT_MPEG1,
-FMT_H261,
-FMT_H263,
-FMT_MJPEG,
-FMT_SPEEDHQ,
-};
-
-
 /**
  * Draw a horizontal band if supported.
  *
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index d7c2f57682..215df0fd5b 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -28,7 +28,6 @@
 #ifndef AVCODEC_MPEGVIDEO_H
 #define AVCODEC_MPEGVIDEO_H
 
-#include "avcodec.h"
 #include "blockdsp.h"
 #include "error_resilience.h"
 #include "fdctdsp.h"
@@ -44,7 +43,6 @@
 #include "pixblockdsp.h"
 #include "put_bits.h"
 #include "ratecontrol.h"
-#include "mpegutils.h"
 #include "qpeldsp.h"
 #include "videodsp.h"
 
@@ -61,6 +59,14 @@ typedef struct ScanTable {
 uint8_t raster_end[64];
 } ScanTable;
 
+enum OutputFormat {
+FMT_MPEG1,
+FMT_H261,
+FMT_H263,
+FMT_MJPEG,
+FMT_SPEEDHQ,
+};
+
 /**
  * MpegEncContext.
  */
@@ -283,7 +289,7 @@ typedef struct MpegEncContext {
 int mb_x, mb_y;
 int mb_skip_run;
 int mb_intra;
-uint16_t *mb_type;  ///< Table for 

[FFmpeg-devel] [PATCH 03/15] avcodec/mpeg12: Remove always-false check

2024-04-05 Thread Andreas Rheinhardt
Forgotten in 7800cc6e82068c6dfb5af53817f03dfda794c568.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 8d88820c46..62d7fd1814 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -180,8 +180,6 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb,
 component = index <= 3 ? 0 : index - 4 + 1;
 
 diff = decode_dc(gb, component);
-if (diff >= 0x)
-return AVERROR_INVALIDDATA;
 
 dc  = last_dc[component];
 dc += diff;
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 04/15] avcodec/mpegvideo_dec, mpeg12dec: Move MPEG1/2 code to mpeg12dec.c

2024-04-05 Thread Andreas Rheinhardt
Up until now, ff_mpv_frame_start() offsets the data of the current
picture and doubles the linesizes of all pictures if the current
picture is field-based so that data and linesize allow to address
the current field only.

This is done based upon the current picture_structure value.
Only two mpegvideo-based decoders ever set this field: mpeg1/2
and VC-1; but the latter only does it after ff_mpv_frame_start()
(when using hardware-acceleration and in order to signal it to
the DXVA2 hwaccel) in which case no offset is applied in
ff_mpv_frame_start(). So only one decoder actually wants this
offset*; therefore move the code performing it to mpeg12dec.c.

*: VC-1 doubles linesize when using field_mode (not only the picture's
linesize, but also uvlinesize and linesize), yet it does not offset
anything. This is further proof that this should not be performed
generically.

Also move MPEG-1/2 specific setting of the top-field-first flag.
(The change here implies that the AVFrame in current_picture
may have different top-field-first flags than the AVFrame
from current_picture_ptr, but this doesn't matter as only
the latter's are used.)

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12dec.c | 15 +++
 libavcodec/mpegvideo_dec.c | 19 ---
 2 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 4ad1eb6572..fb8bba3287 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1299,6 +1299,21 @@ static int mpeg_field_start(MpegEncContext *s, const 
uint8_t *buf, int buf_size)
 if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
 return ret;
 
+if (s->picture_structure != PICT_FRAME) {
+s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST *
+((s->picture_structure == PICT_TOP_FIELD) == s->first_field);
+
+for (int i = 0; i < 4; i++) {
+if (s->picture_structure == PICT_BOTTOM_FIELD) {
+s->current_picture.f->data[i] = 
FF_PTR_ADD(s->current_picture.f->data[i],
+   
s->current_picture.f->linesize[i]);
+}
+s->current_picture.f->linesize[i] *= 2;
+s->last_picture.f->linesize[i]*= 2;
+s->next_picture.f->linesize[i]*= 2;
+}
+}
+
 ff_mpeg_er_frame_start(s);
 
 /* first check if we must repeat the frame */
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 88facfc39d..1ced9a52ed 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -348,14 +348,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 return -1;
 
 s->current_picture_ptr = pic;
-// FIXME use only the vars from current_pic
 s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * 
!!s->top_field_first;
-if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
-s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
-if (s->picture_structure != PICT_FRAME)
-s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST *
-((s->picture_structure == PICT_TOP_FIELD) == s->first_field);
-}
 s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * 
(!s->progressive_frame &&
 
!s->progressive_sequence);
 s->current_picture_ptr->field_picture  =  s->picture_structure != 
PICT_FRAME;
@@ -454,18 +447,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
  
s->last_picture_ptr->f->buf[0]));
 
-if (s->picture_structure != PICT_FRAME) {
-for (int i = 0; i < 4; i++) {
-if (s->picture_structure == PICT_BOTTOM_FIELD) {
-s->current_picture.f->data[i] = 
FF_PTR_ADD(s->current_picture.f->data[i],
-   
s->current_picture.f->linesize[i]);
-}
-s->current_picture.f->linesize[i] *= 2;
-s->last_picture.f->linesize[i]*= 2;
-s->next_picture.f->linesize[i]*= 2;
-}
-}
-
 /* set dequantizer, we can't do it during init as
  * it might change for MPEG-4 and we can't do it in the header
  * decode as init is not called for MPEG-4 there yet */
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH] fate/ffmpeg: Avoid dependency on samples

2024-04-05 Thread Andreas Rheinhardt
Creating vsynth_lena.yuv needs the FATE suite,
yet several tests in ffmpeg.mak without a dependency
on samples used it as input file. Fix this by using
vsynth1.yuv (which does not have such a dependency)
instead.
Also use vsynth1.yuv in fate-shortest to avoid
the samples dependency in this test, too.

Fixes ticket #10947.

Signed-off-by: Andreas Rheinhardt 
---
 tests/fate/ffmpeg.mak   |  30 +++
 tests/ref/fate/ffmpeg-filter-in-eof | 100 +++
 tests/ref/fate/ffmpeg-loopback-decoding | 104 
 tests/ref/fate/force_key_frames |   8 +-
 tests/ref/fate/shortest | 100 +++
 5 files changed, 171 insertions(+), 171 deletions(-)

diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index 49dbba4a6b..dc102750a0 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -16,10 +16,10 @@ fate-ffmpeg-filter_colorkey: CMD = framecrc 
-auto_conversion_filters -idct simpl
 FATE_FFMPEG-$(call FILTERFRAMECRC, COLOR) += fate-ffmpeg-lavfi
 fate-ffmpeg-lavfi: CMD = framecrc -lavfi color=d=1:r=5 -fflags +bitexact
 
-FATE_SAMPLES_FFMPEG-$(call ENCDEC2, MPEG4, RAWVIDEO, AVI, RAWVIDEO_DEMUXER 
FRAMECRC_MUXER) += fate-force_key_frames
-fate-force_key_frames: tests/data/vsynth_lena.yuv
+FATE_FFMPEG-$(call ENCDEC2, MPEG4, RAWVIDEO, AVI, RAWVIDEO_DEMUXER 
FRAMECRC_MUXER) += fate-force_key_frames
+fate-force_key_frames: tests/data/vsynth1.yuv
 fate-force_key_frames: CMD = enc_dec \
-  "rawvideo -s 352x288 -pix_fmt yuv420p" tests/data/vsynth_lena.yuv \
+  "rawvideo -s 352x288 -pix_fmt yuv420p" tests/data/vsynth1.yuv\
   avi "-c mpeg4 -g 240 -qscale 10 -force_key_frames 0.5,0:00:01.5" \
   framecrc "" "-skip_frame nokey"
 
@@ -89,12 +89,12 @@ fate-unknown_layout-ac3: CMD = md5 -auto_conversion_filters 
\
   -guess_layout_max 0 -f s32le -ac 1 -ar 44100 -i $(TARGET_PATH)/$(AREF) \
   -f ac3 -flags +bitexact -c ac3_fixed
 
-FATE_SAMPLES_FFMPEG-$(call FILTERDEMDEC, AMIX ARESAMPLE SINE, RAWVIDEO, \
+FATE_FFMPEG-$(call FILTERDEMDEC, AMIX ARESAMPLE SINE, RAWVIDEO, \
PCM_S16LE RAWVIDEO, LAVFI_INDEV  \
MPEG4_ENCODER AC3_FIXED_ENCODER) \
+= fate-shortest
-fate-shortest: tests/data/vsynth_lena.yuv
-fate-shortest: CMD = framecrc -auto_conversion_filters -f lavfi -i 
"sine=3000:d=10" -f lavfi -i "sine=1000:d=1" -sws_flags +accurate_rnd+bitexact 
-fflags +bitexact -flags +bitexact -idct simple -f rawvideo -s 352x288 -pix_fmt 
yuv420p -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv -filter_complex 
"[0:a:0][1:a:0]amix=inputs=2[audio]" -map 2:v:0 -map "[audio]" -sws_flags 
+accurate_rnd+bitexact -fflags +bitexact -flags +bitexact -idct simple -dct 
fastint -qscale 10 -threads 1 -c:v mpeg4 -c:a ac3_fixed -shortest
+fate-shortest: tests/data/vsynth1.yuv
+fate-shortest: CMD = framecrc -auto_conversion_filters -f lavfi -i 
"sine=3000:d=10" -f lavfi -i "sine=1000:d=1" -sws_flags +accurate_rnd+bitexact 
-fflags +bitexact -flags +bitexact -idct simple -f rawvideo -s 352x288 -pix_fmt 
yuv420p -i $(TARGET_PATH)/tests/data/vsynth1.yuv -filter_complex 
"[0:a:0][1:a:0]amix=inputs=2[audio]" -map 2:v:0 -map "[audio]" -sws_flags 
+accurate_rnd+bitexact -fflags +bitexact -flags +bitexact -idct simple -dct 
fastint -qscale 10 -threads 1 -c:v mpeg4 -c:a ac3_fixed -shortest
 
 # test interleaving video with a sparse subtitle stream
 FATE_SAMPLES_FFMPEG-$(call ALLYES, COLOR_FILTER, VOBSUB_DEMUXER, 
MATROSKA_DEMUXER,, \
@@ -242,24 +242,24 @@ FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MOV, , SETTS_BSF) += 
fate-ffmpeg-bsf-input
 # Test behaviour when a complex filtergraph returns EOF on one of its inputs,
 # but other inputs are still active.
 # cf. #10803
-fate-ffmpeg-filter-in-eof: tests/data/vsynth_lena.yuv
-fate-ffmpeg-filter-in-eof: CMD = framecrc  
\
--f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i 
$(TARGET_PATH)/tests/data/vsynth_lena.yuv  \
--f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i 
$(TARGET_PATH)/tests/data/vsynth_lena.yuv  \
+fate-ffmpeg-filter-in-eof: tests/data/vsynth1.yuv
+fate-ffmpeg-filter-in-eof: CMD = framecrc  
\
+-f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i 
$(TARGET_PATH)/tests/data/vsynth1.yuv  \
+-f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i 
$(TARGET_PATH)/tests/data/vsynth1.yuv  \
 -filter_complex "[0][1]concat" -c:v rawvideo
 FATE_FFMPEG-$(call FRAMECRC, RAWVIDEO, RAWVIDEO, CONCAT_FILTER) += 
fate-ffmpeg-filter-in-eof
 
 # Test termination on streamcopy with -t as an output option.
-fate-ffmpeg-streamcopy-t: tests/data/vsynth_lena.yuv
+fate-ffmpeg-streamcopy-t: tests/data/vsynth1.yuv
 fate-ffmpeg-streamcopy-t: CMP = null
-fate-ffmpeg-streamcopy-t: CMD = ffmpeg 
   \
--stream_loop -1 -f rawvideo -s 352x288 -pix_fmt yuv420p -i 

[FFmpeg-devel] [PATCH 05/15] avcodec/mpeg12dec: Remove redundant check

2024-04-05 Thread Andreas Rheinhardt
This code only gets executed for the first field.

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

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index fb8bba3287..83ff40d237 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1301,7 +1301,7 @@ static int mpeg_field_start(MpegEncContext *s, const 
uint8_t *buf, int buf_size)
 
 if (s->picture_structure != PICT_FRAME) {
 s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST *
-((s->picture_structure == PICT_TOP_FIELD) == s->first_field);
+(s->picture_structure == 
PICT_TOP_FIELD);
 
 for (int i = 0; i < 4; i++) {
 if (s->picture_structure == PICT_BOTTOM_FIELD) {
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 06/15] avcodec/mpeg12dec: Don't pretend MPEG-1/2 to support alpha

2024-04-05 Thread Andreas Rheinhardt
(FF_PTR_ADD has to be kept although MPEG-1/2 only supports
YUV pixel formats because our decoder also supports decoding
to AV_PIX_FMT_GRAY8 depending upon CONFIG_GRAY.)

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12dec.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 83ff40d237..337654c88d 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1303,7 +1303,7 @@ static int mpeg_field_start(MpegEncContext *s, const 
uint8_t *buf, int buf_size)
 s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST *
 (s->picture_structure == 
PICT_TOP_FIELD);
 
-for (int i = 0; i < 4; i++) {
+for (int i = 0; i < 3; i++) {
 if (s->picture_structure == PICT_BOTTOM_FIELD) {
 s->current_picture.f->data[i] = 
FF_PTR_ADD(s->current_picture.f->data[i],

s->current_picture.f->linesize[i]);
@@ -1368,8 +1368,6 @@ static int mpeg_field_start(MpegEncContext *s, const 
uint8_t *buf, int buf_size)
 if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
 ff_thread_finish_setup(avctx);
 } else { // second field
-int i;
-
 if (!s->current_picture_ptr) {
 av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
 return AVERROR_INVALIDDATA;
@@ -1383,7 +1381,7 @@ static int mpeg_field_start(MpegEncContext *s, const 
uint8_t *buf, int buf_size)
 }
 }
 
-for (i = 0; i < 4; i++) {
+for (int i = 0; i < 3; i++) {
 s->current_picture.f->data[i] = s->current_picture_ptr->f->data[i];
 if (s->picture_structure == PICT_BOTTOM_FIELD)
 s->current_picture.f->data[i] +=
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 08/15] avcodec/mpeg12dec: Remove unnecessary FFCodec.close

2024-04-05 Thread Andreas Rheinhardt
The ipu decoder never calls ff_mpv_common_init() or allocates
anything else that would need to be freed.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12dec.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 337654c88d..45627e702d 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -2868,15 +2868,6 @@ static av_cold int ipu_decode_init(AVCodecContext *avctx)
 return 0;
 }
 
-static av_cold int ipu_decode_end(AVCodecContext *avctx)
-{
-IPUContext *s = avctx->priv_data;
-
-ff_mpv_common_end(>m);
-
-return 0;
-}
-
 const FFCodec ff_ipu_decoder = {
 .p.name = "ipu",
 CODEC_LONG_NAME("IPU Video"),
@@ -2885,7 +2876,5 @@ const FFCodec ff_ipu_decoder = {
 .priv_data_size = sizeof(IPUContext),
 .init   = ipu_decode_init,
 FF_CODEC_DECODE_CB(ipu_decode_frame),
-.close  = ipu_decode_end,
 .p.capabilities = AV_CODEC_CAP_DR1,
-.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 11/15] avcodec/mpegvideo_dec: Factor allocating dummy frame out

2024-04-05 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c | 64 +++---
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 4fa89e4aef..b6ef4e5582 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -270,6 +270,32 @@ fail:
 return ret;
 }
 
+static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp)
+{
+int idx = ff_find_unused_picture(s->avctx, s->picture, 0);
+Picture *pic;
+int ret;
+
+if (idx < 0)
+return idx;
+
+pic = >picture[idx];
+
+pic->reference= 3;
+pic->f->pict_type = AV_PICTURE_TYPE_P;
+
+ret = alloc_picture(s, pic);
+if (ret < 0)
+return ret;
+
+ff_thread_report_progress(>tf, INT_MAX, 0);
+ff_thread_report_progress(>tf, INT_MAX, 1);
+
+*picp = pic;
+
+return 0;
+}
+
 static void color_frame(AVFrame *frame, int luma)
 {
 int h_chroma_shift, v_chroma_shift;
@@ -379,48 +405,22 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
"warning: first frame is no keyframe\n");
 
 /* Allocate a dummy frame */
-idx = ff_find_unused_picture(s->avctx, s->picture, 0);
-if (idx < 0) {
-av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
-return idx;
-}
-s->last_picture_ptr = >picture[idx];
-
-s->last_picture_ptr->reference= 3;
-s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
-
-if (alloc_picture(s, s->last_picture_ptr) < 0) {
-s->last_picture_ptr = NULL;
-return -1;
-}
+ret = alloc_dummy_frame(s, >last_picture_ptr);
+if (ret < 0)
+return ret;
 
 if (!avctx->hwaccel) {
 int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == 
AV_CODEC_ID_H263 ? 16 : 0x80;
 color_frame(s->last_picture_ptr->f, luma_val);
 }
 
-ff_thread_report_progress(>last_picture_ptr->tf, INT_MAX, 0);
-ff_thread_report_progress(>last_picture_ptr->tf, INT_MAX, 1);
 }
 if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
 s->pict_type == AV_PICTURE_TYPE_B) {
 /* Allocate a dummy frame */
-idx = ff_find_unused_picture(s->avctx, s->picture, 0);
-if (idx < 0) {
-av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
-return idx;
-}
-s->next_picture_ptr = >picture[idx];
-
-s->next_picture_ptr->reference   = 3;
-s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
-
-if (alloc_picture(s, s->next_picture_ptr) < 0) {
-s->next_picture_ptr = NULL;
-return -1;
-}
-ff_thread_report_progress(>next_picture_ptr->tf, INT_MAX, 0);
-ff_thread_report_progress(>next_picture_ptr->tf, INT_MAX, 1);
+ret = alloc_dummy_frame(s, >next_picture_ptr);
+if (ret < 0)
+return ret;
 }
 
 if (s->last_picture_ptr) {
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 09/15] avcodec/mpegvideo_dec: Remove obsolete current_picture_ptr reuse code

2024-04-05 Thread Andreas Rheinhardt
Obsolete since at least 74d623914f02aa79447df43a742efd0929dded04.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 1059aa9825..9f674488c0 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -325,18 +325,12 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 ff_mpeg_unref_picture(>last_picture);
 ff_mpeg_unref_picture(>next_picture);
 
-if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) {
-// we already have an unused image
-// (maybe it was set before reading the header)
-pic = s->current_picture_ptr;
-} else {
 idx = ff_find_unused_picture(s->avctx, s->picture, 0);
 if (idx < 0) {
 av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
 return idx;
 }
 pic = >picture[idx];
-}
 
 pic->reference = 0;
 if (!s->droppable) {
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 10/15] avcodec/mpegvideo_dec: Remove redundant code to reset keyframe flag

2024-04-05 Thread Andreas Rheinhardt
These AVFrames are blank and therefore the flag is already unset.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 9f674488c0..4fa89e4aef 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -387,7 +387,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 s->last_picture_ptr = >picture[idx];
 
 s->last_picture_ptr->reference= 3;
-s->last_picture_ptr->f->flags &= ~AV_FRAME_FLAG_KEY;
 s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
 
 if (alloc_picture(s, s->last_picture_ptr) < 0) {
@@ -414,7 +413,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 s->next_picture_ptr = >picture[idx];
 
 s->next_picture_ptr->reference   = 3;
-s->next_picture_ptr->f->flags &= ~AV_FRAME_FLAG_KEY;
 s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
 
 if (alloc_picture(s, s->next_picture_ptr) < 0) {
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 07/15] avcodec/mpegvideo_dec: Don't emit non-keyframe warning for H.261

2024-04-05 Thread Andreas Rheinhardt
H.261 does not have keyframes (or indeed frame types) at all,
so this warning is not warranted.

Also remove an always-true check while at it.

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

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 1ced9a52ed..1059aa9825 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -380,7 +380,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && 
s->next_picture_ptr->f->buf[0])
 av_log(avctx, AV_LOG_DEBUG,
"allocating dummy last picture for B frame\n");
-else if (s->pict_type != AV_PICTURE_TYPE_I)
+else if (s->codec_id != AV_CODEC_ID_H261)
 av_log(avctx, AV_LOG_ERROR,
"warning: first frame is no keyframe\n");
 
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 01/15] avcodec/mpegvideo_enc: Don't update current_picture unnecessarily

2024-04-05 Thread Andreas Rheinhardt
current_picture is not changed after frame_start() at all
and it therefore does not need to be updated (i.e. copied to the
slice thread contexts) a second time.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d1b1917824..0e3255c0fb 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -251,7 +251,6 @@ static void 
update_duplicate_context_after_me(MpegEncContext *dst,
 {
 #define COPY(a) dst->a= src->a
 COPY(pict_type);
-COPY(current_picture);
 COPY(f_code);
 COPY(b_code);
 COPY(qscale);
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 14/31] fftools/ffmpeg_filter: accept a caller-provided output name

2024-04-05 Thread Anton Khirnov
Do not construct it from OutputStream manually.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  |  3 +++
 fftools/ffmpeg_filter.c   | 36 +++-
 fftools/ffmpeg_mux_init.c |  4 
 3 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 16497105e1..3c196c25e5 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -268,6 +268,9 @@ enum OFilterFlags {
 };
 
 typedef struct OutputFilterOptions {
+// Caller-provided name for this output
+char   *name;
+
 // Codec used for encoding, may be NULL
 const AVCodec  *enc;
 // Overrides encoder pixel formats when set.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 022c42e9c7..ceab58da19 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -188,6 +188,8 @@ typedef struct OutputFilterPriv {
 
 int index;
 
+char   *name;
+
 AVFilterContext*filter;
 
 /* desired output stream properties */
@@ -784,6 +786,10 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofp->ts_offset= opts->ts_offset;
 ofp->enc_timebase = opts->output_tb;
 
+ofp->name = av_strdup(opts->name);
+if (!ofp->name)
+return AVERROR(EINVAL);
+
 switch (ofilter->type) {
 case AVMEDIA_TYPE_VIDEO:
 ofp->width  = opts->width;
@@ -911,6 +917,7 @@ void fg_free(FilterGraph **pfg)
 
 av_freep(>linklabel);
 av_freep(>name);
+av_freep(>name);
 av_channel_layout_uninit(>ch_layout);
 av_freep(>outputs[j]);
 }
@@ -1076,9 +1083,8 @@ int init_simple_filtergraph(InputStream *ist, 
OutputStream *ost,
 
 fgp->is_simple = 1;
 
-snprintf(fgp->log_name, sizeof(fgp->log_name), "%cf#%d:%d",
- av_get_media_type_string(ost->type)[0],
- ost->file->index, ost->index);
+snprintf(fgp->log_name, sizeof(fgp->log_name), "%cf%s",
+ av_get_media_type_string(ost->type)[0], opts->name);
 
 if (fg->nb_inputs != 1 || fg->nb_outputs != 1) {
 av_log(fg, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
@@ -1305,7 +1311,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 const char *pix_fmts;
 char name[255];
 
-snprintf(name, sizeof(name), "out_%d_%d", ost->file->index, ost->index);
+snprintf(name, sizeof(name), "out_%s", ofp->name);
 ret = avfilter_graph_create_filter(>filter,
avfilter_get_by_name("buffersink"),
name, NULL, NULL, graph);
@@ -1325,8 +1331,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
 }
 
-snprintf(name, sizeof(name), "scaler_out_%d_%d",
- ost->file->index, ost->index);
+snprintf(name, sizeof(name), "scaler_out_%s", ofp->name);
 if ((ret = avfilter_graph_create_filter(, 
avfilter_get_by_name("scale"),
 name, args, NULL, graph)) < 0)
 return ret;
@@ -1358,8 +1363,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 pad_idx = 0;
 }
 
-snprintf(name, sizeof(name), "trim_out_%d_%d",
- ost->file->index, ost->index);
+snprintf(name, sizeof(name), "trim_out_%s", ofp->name);
 ret = insert_trim(of->start_time, of->recording_time,
   _filter, _idx, name);
 if (ret < 0)
@@ -1384,7 +1388,7 @@ static int configure_output_audio_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 char name[255];
 int ret;
 
-snprintf(name, sizeof(name), "out_%d_%d", ost->file->index, ost->index);
+snprintf(name, sizeof(name), "out_%s", ofp->name);
 ret = avfilter_graph_create_filter(>filter,
avfilter_get_by_name("abuffersink"),
name, NULL, NULL, graph);
@@ -1424,8 +1428,7 @@ static int configure_output_audio_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 if (args.len) {
 AVFilterContext *format;
 
-snprintf(name, sizeof(name), "format_out_%d_%d",
- ost->file->index, ost->index);
+snprintf(name, sizeof(name), "format_out_%s", ofp->name);
 ret = avfilter_graph_create_filter(,
avfilter_get_by_name("aformat"),
name, args.str, NULL, graph);
@@ -1452,8 +1455,7 @@ static int configure_output_audio_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 }
 }
 
-snprintf(name, sizeof(name), "trim for output stream %d:%d",
- ost->file->index, ost->index);
+snprintf(name, sizeof(name), "trim for output %s", ofp->name);
 ret = 

[FFmpeg-devel] [PATCH 27/31] fftools/ffmpeg_filter: only store complex filtergraphs in global array

2024-04-05 Thread Anton Khirnov
Store simple filtergraphs in the stream they feed. Keeping the two
separate will be useful in following commits.
---
 fftools/ffmpeg.c|  5 +
 fftools/ffmpeg.h|  3 +++
 fftools/ffmpeg_filter.c | 16 +---
 fftools/ffmpeg_mux.c|  1 +
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0ee76d69b5..1f50ed6805 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -787,6 +787,11 @@ static int check_keyboard_interaction(int64_t cur_time)
 (n = sscanf(buf, "%63[^ ] %lf %255[^ ] %255[^\n]", target, , 
command, arg)) >= 3) {
 av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f 
command:%s arg:%s",
target, time, command, arg);
+for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) 
{
+if (ost->fg_simple)
+fg_send_command(ost->fg_simple, time, target, command, arg,
+key == 'C');
+}
 for (i = 0; i < nb_filtergraphs; i++)
 fg_send_command(filtergraphs[i], time, target, command, arg,
 key == 'C');
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6446a141b5..882d241bdb 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -582,6 +582,8 @@ typedef struct OutputStream {
 char *logfile_prefix;
 FILE *logfile;
 
+// simple filtergraph feeding this stream, if any
+FilterGraph  *fg_simple;
 OutputFilter *filter;
 
 AVDictionary *encoder_opts;
@@ -653,6 +655,7 @@ extern intnb_input_files;
 extern OutputFile   **output_files;
 extern int nb_output_files;
 
+// complex filtergraphs
 extern FilterGraph **filtergraphs;
 extern intnb_filtergraphs;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3988cf5fc2..388c8919fd 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1009,16 +1009,25 @@ int fg_create(FilterGraph **pfg, char *graph_desc, 
Scheduler *sch)
 AVFilterGraph *graph;
 int ret = 0;
 
-fgp = allocate_array_elem(, sizeof(*fgp), _filtergraphs);
+fgp = av_mallocz(sizeof(*fgp));
 if (!fgp)
 return AVERROR(ENOMEM);
 fg = >fg;
 
-if (pfg)
+if (pfg) {
 *pfg = fg;
+fg->index = -1;
+} else {
+ret = av_dynarray_add_nofree(, _filtergraphs, fgp);
+if (ret < 0) {
+av_freep();
+return ret;
+}
+
+fg->index = nb_filtergraphs - 1;
+}
 
 fg->class   = _class;
-fg->index  = nb_filtergraphs - 1;
 fgp->graph_desc = graph_desc;
 fgp->disable_conversions = !auto_conversion_filters;
 fgp->sch = sch;
@@ -1135,6 +1144,7 @@ int init_simple_filtergraph(InputStream *ist, 
OutputStream *ost,
 ret = fg_create(, graph_desc, sch);
 if (ret < 0)
 return ret;
+ost->fg_simple = fg;
 fgp = fgp_from_fg(fg);
 
 fgp->is_simple = 1;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 2b7a733501..a1583edd61 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -797,6 +797,7 @@ static void ost_free(OutputStream **post)
 ms = ms_from_ost(ost);
 
 enc_free(>enc);
+fg_free(>fg_simple);
 
 if (ost->logfile) {
 if (fclose(ost->logfile))
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 21/31] fftools/ffmpeg_filter: pass trim parameters through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Do not read them from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  |  2 ++
 fftools/ffmpeg_filter.c   | 11 +++
 fftools/ffmpeg_mux_init.c |  2 ++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 4059b1dcc3..8e773165da 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -279,6 +279,8 @@ typedef struct OutputFilterOptions {
 // Overrides encoder pixel formats when set.
 const enum AVPixelFormat *pix_fmts;
 
+int64_t trim_start_us;
+int64_t trim_duration_us;
 int64_t ts_offset;
 
 /* Desired output timebase.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index dc9556bbc1..225fa4bda2 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -220,6 +220,8 @@ typedef struct OutputFilterPriv {
 const int  *sample_rates;
 
 AVRational  enc_timebase;
+int64_t trim_start_us;
+int64_t trim_duration_us;
 // offset for output timestamps, in AV_TIME_BASE_Q
 int64_t ts_offset;
 int64_t next_pts;
@@ -812,6 +814,9 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofp->ts_offset= opts->ts_offset;
 ofp->enc_timebase = opts->output_tb;
 
+ofp->trim_start_us= opts->trim_start_us;
+ofp->trim_duration_us = opts->trim_duration_us;
+
 ofp->name = av_strdup(opts->name);
 if (!ofp->name)
 return AVERROR(EINVAL);
@@ -1349,8 +1354,6 @@ static int configure_output_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
  OutputFilter *ofilter, AVFilterInOut 
*out)
 {
 OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
-OutputStream *ost = ofilter->ost;
-OutputFile*of = ost->file;
 AVFilterContext *last_filter = out->filter_ctx;
 AVBPrint bprint;
 int pad_idx = out->pad_idx;
@@ -1411,7 +1414,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 }
 
 snprintf(name, sizeof(name), "trim_out_%s", ofp->name);
-ret = insert_trim(of->start_time, of->recording_time,
+ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
   _filter, _idx, name);
 if (ret < 0)
 return ret;
@@ -1503,7 +1506,7 @@ static int configure_output_audio_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 }
 
 snprintf(name, sizeof(name), "trim for output %s", ofp->name);
-ret = insert_trim(of->start_time, of->recording_time,
+ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
   _filter, _idx, name);
 if (ret < 0)
 goto fail;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 51c31eeb72..6e19b98abd 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1389,6 +1389,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 .sws_opts= o->g->sws_dict,
 .swr_opts= o->g->swr_opts,
 .output_tb = enc_tb,
+.trim_start_us= mux->of.start_time,
+.trim_duration_us = mux->of.recording_time,
 .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
  0 : mux->of.start_time,
 .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt |
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 12/31] fftools/ffmpeg_filter: pass vsync method through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Do not read it from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  |  3 ++-
 fftools/ffmpeg_filter.c   |  9 +---
 fftools/ffmpeg_mux.c  |  2 +-
 fftools/ffmpeg_mux.h  |  3 +++
 fftools/ffmpeg_mux_init.c | 45 ++-
 5 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 598ca2fa96..fa8f7d8324 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -287,6 +287,8 @@ typedef struct OutputFilterOptions {
 int width;
 int height;
 
+enum VideoSyncMethod vsync_method;
+
 int sample_rate;
 AVChannelLayout ch_layout;
 } OutputFilterOptions;
@@ -549,7 +551,6 @@ typedef struct OutputStream {
 /* video only */
 AVRational frame_rate;
 AVRational max_frame_rate;
-enum VideoSyncMethod vsync_method;
 int is_cfr;
 int force_fps;
 #if FFMPEG_OPT_TOP
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3c25d2ed65..d906b72576 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -175,6 +175,8 @@ typedef struct FPSConvContext {
 int   last_dropped;
 int   dropped_keyframe;
 
+enum VideoSyncMethod vsync_method;
+
 AVRationalframerate;
 AVRationalframerate_max;
 const AVRational *framerate_supported;
@@ -799,6 +801,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 if (!ofp->fps.last_frame)
 return AVERROR(ENOMEM);
 
+ofp->fps.vsync_method= opts->vsync_method;
 ofp->fps.framerate   = ost->frame_rate;
 ofp->fps.framerate_max   = ost->max_frame_rate;
 ofp->fps.framerate_supported = ost->force_fps && opts->enc ?
@@ -2072,9 +2075,9 @@ static void video_sync_process(OutputFilterPriv *ofp, 
AVFrame *frame,
 
 if (delta0 < 0 &&
 delta > 0 &&
-ost->vsync_method != VSYNC_PASSTHROUGH
+fps->vsync_method != VSYNC_PASSTHROUGH
 #if FFMPEG_OPT_VSYNC_DROP
-&& ost->vsync_method != VSYNC_DROP
+&& fps->vsync_method != VSYNC_DROP
 #endif
 ) {
 if (delta0 < -0.6) {
@@ -2086,7 +2089,7 @@ static void video_sync_process(OutputFilterPriv *ofp, 
AVFrame *frame,
 delta0 = 0;
 }
 
-switch (ost->vsync_method) {
+switch (fps->vsync_method) {
 case VSYNC_VSCFR:
 if (fps->frame_number == 0 && delta0 >= 0.5) {
 av_log(ost, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", 
(int)lrintf(delta0));
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index e8e5c677b8..253c2e58d4 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -140,7 +140,7 @@ static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket 
*pkt)
 OutputStream *ost = >ost;
 
 #if FFMPEG_OPT_VSYNC_DROP
-if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP)
+if (ost->type == AVMEDIA_TYPE_VIDEO && ms->ts_drop)
 pkt->pts = pkt->dts = AV_NOPTS_VALUE;
 #endif
 
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index 16af6d38ba..f8b6f7a790 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -75,6 +75,9 @@ typedef struct MuxStream {
 int copy_initial_nonkeyframes;
 int copy_prior_start;
 int streamcopy_started;
+#if FFMPEG_OPT_VSYNC_DROP
+int ts_drop;
+#endif
 } MuxStream;
 
 typedef struct Muxer {
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index b031cc59d2..6ffa4b7491 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -580,8 +580,10 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, 
const char *name)
 }
 
 static int new_stream_video(Muxer *mux, const OptionsContext *o,
-OutputStream *ost, int *keep_pix_fmt)
+OutputStream *ost, int *keep_pix_fmt,
+enum VideoSyncMethod *vsync_method)
 {
+MuxStream   *ms = ms_from_ost(ost);
 AVFormatContext *oc = mux->fc;
 AVStream *st;
 char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = 
NULL;
@@ -773,49 +775,52 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
 #endif
 
 #if FFMPEG_OPT_VSYNC
-ost->vsync_method = video_sync_method;
+*vsync_method = video_sync_method;
 #else
-ost->vsync_method = VSYNC_AUTO;
+*vsync_method = VSYNC_AUTO;
 #endif
 MATCH_PER_STREAM_OPT(fps_mode, str, fps_mode, oc, st);
 if (fps_mode) {
-ret = parse_and_set_vsync(fps_mode, >vsync_method, 
ost->file->index, ost->index, 0);
+ret = parse_and_set_vsync(fps_mode, vsync_method, 
ost->file->index, ost->index, 0);
 if (ret < 0)
 return ret;
 }
 
 if ((ost->frame_rate.num || ost->max_frame_rate.num) &&
-

[FFmpeg-devel] [PATCH 24/31] fftools/ffmpeg_mux: drop OutputFile.format

2024-04-05 Thread Anton Khirnov
It is no longer used outside of the muxing code (where we can access the
muxer directly).
---
 fftools/ffmpeg.h  |  1 -
 fftools/ffmpeg_mux.c  | 15 +--
 fftools/ffmpeg_mux_init.c |  1 -
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 1d32009f90..7135d9563c 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -611,7 +611,6 @@ typedef struct OutputFile {
 
 int index;
 
-const AVOutputFormat *format;
 const char   *url;
 
 OutputStream **streams;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 6a64cba72d..2b7a733501 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -370,10 +370,11 @@ fail:
 return ret;
 }
 
-static void thread_set_name(OutputFile *of)
+static void thread_set_name(Muxer *mux)
 {
 char name[16];
-snprintf(name, sizeof(name), "mux%d:%s", of->index, of->format->name);
+snprintf(name, sizeof(name), "mux%d:%s",
+ mux->of.index, mux->fc->oformat->name);
 ff_thread_setname(name);
 }
 
@@ -417,7 +418,7 @@ int muxer_thread(void *arg)
 if (ret < 0)
 goto finish;
 
-thread_set_name(of);
+thread_set_name(mux);
 
 while (1) {
 OutputStream *ost;
@@ -515,8 +516,10 @@ int print_sdp(const char *filename)
 if (!avc)
 return AVERROR(ENOMEM);
 for (int i = 0; i < nb_output_files; i++) {
-if (!strcmp(output_files[i]->format->name, "rtp")) {
-avc[j] = mux_from_of(output_files[i])->fc;
+Muxer *mux = mux_from_of(output_files[i]);
+
+if (!strcmp(mux->fc->oformat->name, "rtp")) {
+avc[j] = mux->fc;
 j++;
 }
 }
@@ -756,7 +759,7 @@ int of_write_trailer(OutputFile *of)
 
 mux->last_filesize = filesize(fc->pb);
 
-if (!(of->format->flags & AVFMT_NOFILE)) {
+if (!(fc->oformat->flags & AVFMT_NOFILE)) {
 ret = avio_closep(>pb);
 if (ret < 0) {
 av_log(mux, AV_LOG_ERROR, "Error closing file: %s\n", 
av_err2str(ret));
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 9aad19a85d..ffcc20a504 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -3063,7 +3063,6 @@ int of_open(const OptionsContext *o, const char 
*filename, Scheduler *sch)
 av_strlcat(mux->log_name, oc->oformat->name, sizeof(mux->log_name));
 
 
-of->format = oc->oformat;
 if (recording_time != INT64_MAX)
 oc->duration = recording_time;
 
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 20/31] fftools/ffmpeg_filter: pass autoscale through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Do not read it from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  | 2 +-
 fftools/ffmpeg_filter.c   | 2 +-
 fftools/ffmpeg_mux_init.c | 7 ---
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index c61a670103..4059b1dcc3 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -267,6 +267,7 @@ enum OFilterFlags {
 OFILTER_FLAG_DISABLE_CONVERT= (1 << 0),
 // produce 24-bit audio
 OFILTER_FLAG_AUDIO_24BIT= (1 << 1),
+OFILTER_FLAG_AUTOSCALE  = (1 << 2),
 };
 
 typedef struct OutputFilterOptions {
@@ -565,7 +566,6 @@ typedef struct OutputStream {
 #if FFMPEG_OPT_TOP
 int top_field_first;
 #endif
-int autoscale;
 int bitexact;
 int bits_per_raw_sample;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 8aa4053716..dc9556bbc1 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1366,7 +1366,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 if (ret < 0)
 return ret;
 
-if ((ofp->width || ofp->height) && ofilter->ost->autoscale) {
+if ((ofp->width || ofp->height) && (ofp->flags & OFILTER_FLAG_AUTOSCALE)) {
 char args[255];
 AVFilterContext *filter;
 const AVDictionaryEntry *e = NULL;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 8f4b73f8a7..51c31eeb72 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1045,7 +1045,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 OutputStream *ost;
 const AVCodec *enc;
 AVStream *st;
-int ret = 0, keep_pix_fmt = 0;
+int ret = 0, keep_pix_fmt = 0, autoscale = 1;
 AVRational enc_tb = { 0, 0 };
 enum VideoSyncMethod vsync_method = VSYNC_AUTO;
 const char *bsfs = NULL, *time_base = NULL;
@@ -1170,8 +1170,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 return ret;
 
 MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
-ost->autoscale = 1;
-MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
+
+MATCH_PER_STREAM_OPT(autoscale, i, autoscale, oc, st);
 if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, 
 {
 AVBPrint bprint;
 av_bprint_init(, 0, AV_BPRINT_SIZE_UNLIMITED);
@@ -1392,6 +1392,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
  0 : mux->of.start_time,
 .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt |
+ OFILTER_FLAG_AUTOSCALE   * !!autoscale|
  OFILTER_FLAG_AUDIO_24BIT * 
!!(av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24),
 };
 
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 31/31] doc/ffmpeg: document that there can be multiple complex filtergraphs

2024-04-05 Thread Anton Khirnov
---
 doc/ffmpeg.texi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 9bd548ce4e..e996ab945f 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -2143,7 +2143,8 @@ Define a complex filtergraph, i.e. one with arbitrary 
number of inputs and/or
 outputs. For simple graphs -- those with one input and one output of the same
 type -- see the @option{-filter} options. @var{filtergraph} is a description of
 the filtergraph, as described in the ``Filtergraph syntax'' section of the
-ffmpeg-filters manual.
+ffmpeg-filters manual. This option may be specified multiple times - each use
+creates a new complex filtergraph.
 
 Inputs to a complex filtergraph may come from different source types,
 distinguished by the format of the corresponding link label:
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_filter: stop accessing encoder AVCodecContext

2024-04-05 Thread Dennis Mungai
On Fri, 5 Apr 2024 at 19:54, Gyan Doshi  wrote:

>
>
> On 2024-04-05 10:20 pm, Dennis Mungai wrote:
> >
> > Does this imply that down the line, with this and additional patchsets,
> > that FFmpeg can handle tasks such as stream copy and filtering in the
> same
> > invocation?
>
> What do you mean? If you map a stream twice, you already can do that now.
>
> Regards,
> Gyan
>

What of doing the same *without* mapping the stream twice?
A complex filtergraph could have a stream mapped, split and then passed to
a copy codec operation, for example, without needing the double re-map
implied above.
___
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 01/11] avcodec: add avcodec_get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

This replaces the myriad of existing lists in AVCodec by a unified API
call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
substantially, while also making this more trivially extensible.

In addition to the already covered lists, add two new entries for color
space and color range, mirroring the newly added negotiable fields in
libavfilter.

I decided to drop the explicit length field from the API proposed by
Andreas Rheinhardt, because having it in place ended up complicating
both the codec side and the client side implementations, while also
being strictly less flexible (it's trivial to recover a length given
a terminator, but requires allocation to add a terminator given
a length). Using a terminator also presents less of a porting challenge
for existing users of the current API.

Once the deprecation period passes for the existing public fields, the
rough plan is to move the commonly used fields (such as
pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
configuration types, and then implement the rarely used fields with
custom callbacks.
---
 doc/APIchanges  |  5 
 libavcodec/avcodec.c| 51 +
 libavcodec/avcodec.h| 27 
 libavcodec/codec.h  | 19 +++---
 libavcodec/codec_internal.h | 21 +++
 libavcodec/version.h|  4 +--
 6 files changed, 121 insertions(+), 6 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 0a39b6d7ab8..fdeae67159d 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-04-xx - xx - lavc 59.6.100 - avcodec.h
+  Add avcodec_get_supported_config() and enum AVCodecConfig; deprecate
+  AVCodec.pix_fmts, AVCodec.sample_fmts, AVCodec.supported_framerates,
+  AVCodec.supported_samplerates and AVCodec.ch_layouts.
+
 2024-04-03 - xx - lavu 59.13.100 - pixfmt.h
   Add AVCOL_SPC_IPT_C2, AVCOL_SPC_YCGCO_RE and AVCOL_SPC_YCGCO_RO
   to map new matrix coefficients defined by H.273 v3.
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 525fe516bd2..3615dc7c1f3 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -700,3 +700,54 @@ int attribute_align_arg 
avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
 return ff_decode_receive_frame(avctx, frame);
 return ff_encode_receive_frame(avctx, frame);
 }
+
+#define WRAP_CONFIG(allowed_type, field)\
+do {\
+if (codec->type != (allowed_type))  \
+return AVERROR(EINVAL); \
+*out_configs = (field); \
+return 0;   \
+} while (0)
+
+int ff_default_get_supported_config(const AVCodecContext *avctx,
+const AVCodec *codec,
+enum AVCodecConfig config,
+unsigned flags,
+const void **out_configs)
+{
+switch (config) {
+FF_DISABLE_DEPRECATION_WARNINGS
+case AV_CODEC_CONFIG_PIX_FORMAT:
+WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts);
+case AV_CODEC_CONFIG_FRAME_RATE:
+WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates);
+case AV_CODEC_CONFIG_SAMPLE_RATE:
+WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->supported_samplerates);
+case AV_CODEC_CONFIG_SAMPLE_FORMAT:
+WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->sample_fmts);
+case AV_CODEC_CONFIG_CHANNEL_LAYOUT:
+WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->ch_layouts);
+FF_ENABLE_DEPRECATION_WARNINGS
+case AV_CODEC_CONFIG_COLOR_RANGE:
+case AV_CODEC_CONFIG_COLOR_SPACE:
+*out_configs = NULL;
+return 0;
+default:
+return AVERROR(EINVAL);
+}
+}
+
+int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec 
*codec,
+ enum AVCodecConfig config, unsigned flags,
+ const void **out)
+{
+const FFCodec *codec2;
+if (!codec)
+codec = avctx->codec;
+codec2 = ffcodec(codec);
+if (codec2->get_supported_config) {
+return codec2->get_supported_config(avctx, codec, config, flags, out);
+} else {
+return ff_default_get_supported_config(avctx, codec, config, flags, 
out);
+}
+}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 83dc487251c..64f31375fc6 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2690,6 +2690,33 @@ int avcodec_get_hw_frames_parameters(AVCodecContext 
*avctx,
  enum AVPixelFormat hw_pix_fmt,
  AVBufferRef **out_frames_ref);
 
+enum AVCodecConfig {
+AV_CODEC_CONFIG_PIX_FORMAT, ///< AVPixelFormat, terminated by 
AV_PIX_FMT_NONE
+AV_CODEC_CONFIG_FRAME_RATE, 

[FFmpeg-devel] [PATCH 02/11] avcodec/encode: switch to avcodec_get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

---
 libavcodec/encode.c | 88 -
 1 file changed, 55 insertions(+), 33 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 34658d13d0c..d0e79379048 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -563,7 +563,8 @@ static int encode_preinit_video(AVCodecContext *avctx)
 {
 const AVCodec *c = avctx->codec;
 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
-int i;
+const enum AVPixelFormat *pix_fmts;
+int ret, i;
 
 if (!av_get_pix_fmt_name(avctx->pix_fmt)) {
 av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n",
@@ -571,28 +572,33 @@ static int encode_preinit_video(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if (c->pix_fmts) {
-for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
-if (avctx->pix_fmt == c->pix_fmts[i])
+ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT,
+   0, (const void **) _fmts);
+if (ret < 0)
+return ret;
+
+if (pix_fmts) {
+for (i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++)
+if (avctx->pix_fmt == pix_fmts[i])
 break;
-if (c->pix_fmts[i] == AV_PIX_FMT_NONE) {
+if (pix_fmts[i] == AV_PIX_FMT_NONE) {
 av_log(avctx, AV_LOG_ERROR,
"Specified pixel format %s is not supported by the %s 
encoder.\n",
av_get_pix_fmt_name(avctx->pix_fmt), c->name);
 
 av_log(avctx, AV_LOG_ERROR, "Supported pixel formats:\n");
-for (int p = 0; c->pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
+for (int p = 0; pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
 av_log(avctx, AV_LOG_ERROR, "  %s\n",
-   av_get_pix_fmt_name(c->pix_fmts[p]));
+   av_get_pix_fmt_name(pix_fmts[p]));
 }
 
 return AVERROR(EINVAL);
 }
-if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
-c->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
-c->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
-c->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
-c->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
+if (pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
+pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
+pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
+pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
+pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
 avctx->color_range = AVCOL_RANGE_JPEG;
 }
 
@@ -646,7 +652,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 static int encode_preinit_audio(AVCodecContext *avctx)
 {
 const AVCodec *c = avctx->codec;
-int i;
+const enum AVSampleFormat *sample_fmts;
+const int *supported_samplerates;
+const AVChannelLayout *ch_layouts;
+int ret, i;
 
 if (!av_get_sample_fmt_name(avctx->sample_fmt)) {
 av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n",
@@ -659,53 +668,66 @@ static int encode_preinit_audio(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if (c->sample_fmts) {
-for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
-if (avctx->sample_fmt == c->sample_fmts[i])
+ret = avcodec_get_supported_config(avctx, NULL, 
AV_CODEC_CONFIG_SAMPLE_FORMAT,
+   0, (const void **) _fmts);
+if (ret < 0)
+return ret;
+if (sample_fmts) {
+for (i = 0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
+if (avctx->sample_fmt == sample_fmts[i])
 break;
 if (avctx->ch_layout.nb_channels == 1 &&
 av_get_planar_sample_fmt(avctx->sample_fmt) ==
-av_get_planar_sample_fmt(c->sample_fmts[i])) {
-avctx->sample_fmt = c->sample_fmts[i];
+av_get_planar_sample_fmt(sample_fmts[i])) {
+avctx->sample_fmt = sample_fmts[i];
 break;
 }
 }
-if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
+if (sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
 av_log(avctx, AV_LOG_ERROR,
"Specified sample format %s is not supported by the %s 
encoder\n",
av_get_sample_fmt_name(avctx->sample_fmt), c->name);
 
 av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n");
-for (int p = 0; c->sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
+for (int p = 0; sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
 av_log(avctx, AV_LOG_ERROR, "  %s\n",
-   av_get_sample_fmt_name(c->sample_fmts[p]));
+   av_get_sample_fmt_name(sample_fmts[p]));
 }
 
 return AVERROR(EINVAL);
 }
 }
-if (c->supported_samplerates) {
-for (i = 0; c->supported_samplerates[i] != 0; i++)
-if 

[FFmpeg-devel] [PATCH 03/11] avcodec/allcodecs: add backcompat for new config API

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

In order to avoid breaking older clients not yet using the new API, we
need to add backwards compatibility for codecs which have switched from
init_static() to get_supported_config().

This function can be removed entirely once the deprecated static fields
are removed.
---
 libavcodec/allcodecs.c | 37 +++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f4705651fb8..a9f1797930a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -916,8 +916,41 @@ static AVOnce av_codec_static_init = AV_ONCE_INIT;
 static void av_codec_init_static(void)
 {
 for (int i = 0; codec_list[i]; i++) {
-if (codec_list[i]->init_static_data)
-codec_list[i]->init_static_data((FFCodec*)codec_list[i]);
+const FFCodec *codec = codec_list[i];
+if (codec->init_static_data) {
+codec->init_static_data((FFCodec*) codec);
+continue;
+}
+
+/* Backward compatibility with deprecated public fields */
+if (!codec->get_supported_config)
+continue;
+
+FF_DISABLE_DEPRECATION_WARNINGS
+switch (codec->p.type) {
+case AVMEDIA_TYPE_VIDEO:
+codec->get_supported_config(NULL, >p,
+AV_CODEC_CONFIG_PIX_FORMAT, 0,
+(const void **) >p.pix_fmts);
+codec->get_supported_config(NULL, >p,
+AV_CODEC_CONFIG_FRAME_RATE, 0,
+(const void **) 
>p.supported_framerates);
+break;
+case AVMEDIA_TYPE_AUDIO:
+codec->get_supported_config(NULL, >p,
+AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
+(const void **) >p.sample_fmts);
+codec->get_supported_config(NULL, >p,
+AV_CODEC_CONFIG_SAMPLE_RATE, 0,
+(const void **) 
>p.supported_samplerates);
+codec->get_supported_config(NULL, >p,
+AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
+(const void **) >p.ch_layouts);
+break;
+default:
+break;
+}
+FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
-- 
2.44.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 15/31] fftools/ffmpeg_filter: drop a redundant check

2024-04-05 Thread Anton Khirnov
fg_finalise_bindings() already checks that all filtergraph outputs are
connected.
---
 fftools/ffmpeg_filter.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ceab58da19..41d96267bc 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1472,11 +1472,6 @@ fail:
 static int configure_output_filter(FilterGraph *fg, AVFilterGraph *graph,
OutputFilter *ofilter, AVFilterInOut *out)
 {
-if (!ofilter->ost) {
-av_log(fg, AV_LOG_FATAL, "Filter %s has an unconnected output\n", 
ofilter->name);
-return AVERROR(EINVAL);
-}
-
 switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) 
{
 case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, graph, 
ofilter, out);
 case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, graph, 
ofilter, out);
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 06/31] fftools/ffmpeg_filter: pass ts offset through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Reduces the need to access OutputFile, which will allow decoupling
filtering from encoding in future commits.
---
 fftools/ffmpeg.h  | 2 ++
 fftools/ffmpeg_filter.c   | 3 +--
 fftools/ffmpeg_mux_init.c | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8455cb23e4..7288a48aa1 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -266,6 +266,8 @@ typedef struct InputFilterOptions {
 typedef struct OutputFilterOptions {
 // Codec used for encoding, may be NULL
 const AVCodec  *enc;
+
+int64_t ts_offset;
 } OutputFilterOptions;
 
 typedef struct InputFilter {
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index a59c61b312..8b05262622 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -766,7 +766,6 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
  unsigned sched_idx_enc,
  const OutputFilterOptions *opts)
 {
-const OutputFile  *of = ost->file;
 OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
 FilterGraph  *fg = ofilter->graph;
 FilterGraphPriv *fgp = fgp_from_fg(fg);
@@ -778,7 +777,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofilter->ost = ost;
 av_freep(>linklabel);
 
-ofp->ts_offset = of->start_time == AV_NOPTS_VALUE ? 0 : of->start_time;
+ofp->ts_offset= opts->ts_offset;
 ofp->enc_timebase = ost->enc_timebase;
 
 switch (ost->enc_ctx->codec_type) {
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index b5869feb80..83eab4276e 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1373,6 +1373,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
 OutputFilterOptions opts = {
 .enc = enc,
+.ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
+ 0 : mux->of.start_time,
 };
 
 if (ofilter) {
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 04/31] fftools/ffmpeg_filter: stop accessing AVCodecContext.codec

2024-04-05 Thread Anton Khirnov
Instead pass the encoder through a newly-added output options struct,
analogous to previously added input options.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  | 11 +--
 fftools/ffmpeg_filter.c   | 36 +++-
 fftools/ffmpeg_mux_init.c |  8 ++--
 3 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index a575ee70d5..8455cb23e4 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -263,6 +263,11 @@ typedef struct InputFilterOptions {
 AVFrame*fallback;
 } InputFilterOptions;
 
+typedef struct OutputFilterOptions {
+// Codec used for encoding, may be NULL
+const AVCodec  *enc;
+} OutputFilterOptions;
+
 typedef struct InputFilter {
 struct FilterGraph *graph;
 uint8_t*name;
@@ -684,7 +689,8 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, 
int file_idx, int st_id
 int filtergraph_is_simple(const FilterGraph *fg);
 int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
 char *graph_desc,
-Scheduler *sch, unsigned sch_idx_enc);
+Scheduler *sch, unsigned sch_idx_enc,
+const OutputFilterOptions *opts);
 int fg_finalise_bindings(FilterGraph *fg);
 
 /**
@@ -699,7 +705,8 @@ FrameData   *packet_data  (AVPacket *pkt);
 const FrameData *packet_data_c(AVPacket *pkt);
 
 int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
- unsigned sched_idx_enc);
+ unsigned sched_idx_enc,
+ const OutputFilterOptions *opts);
 
 /**
  * Create a new filtergraph in the global filtergraph list.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ba6c6c7673..0d359303f7 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -763,13 +763,13 @@ static int set_channel_layout(OutputFilterPriv *f, const 
AVChannelLayout *layout
 }
 
 int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
- unsigned sched_idx_enc)
+ unsigned sched_idx_enc,
+ const OutputFilterOptions *opts)
 {
 const OutputFile  *of = ost->file;
 OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
 FilterGraph  *fg = ofilter->graph;
 FilterGraphPriv *fgp = fgp_from_fg(fg);
-const AVCodec *c = ost->enc_ctx->codec;
 int ret;
 
 av_assert0(!ofilter->ost);
@@ -786,14 +786,14 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofp->height = ost->enc_ctx->height;
 if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
 ofp->format = ost->enc_ctx->pix_fmt;
-} else {
-ofp->formats = c->pix_fmts;
+} else if (opts->enc) {
+ofp->formats = opts->enc->pix_fmts;
 
 // MJPEG encoder exports a full list of supported pixel formats,
 // but the full-range ones are experimental-only.
 // Restrict the auto-conversion list unless -strict experimental
 // has been specified.
-if (!strcmp(c->name, "mjpeg")) {
+if (!strcmp(opts->enc->name, "mjpeg")) {
 // FIXME: YUV420P etc. are actually supported with full color 
range,
 // yet the latter information isn't available here.
 static const enum AVPixelFormat mjpeg_formats[] =
@@ -822,11 +822,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 
 ofp->fps.framerate   = ost->frame_rate;
 ofp->fps.framerate_max   = ost->max_frame_rate;
-ofp->fps.framerate_supported = ost->force_fps ?
-   NULL : c->supported_framerates;
+ofp->fps.framerate_supported = ost->force_fps && opts->enc ?
+   NULL : opts->enc->supported_framerates;
 
 // reduce frame rate for mpeg4 to be within the spec limits
-if (c->id == AV_CODEC_ID_MPEG4)
+if (opts->enc && opts->enc->id == AV_CODEC_ID_MPEG4)
 ofp->fps.framerate_clip = 65535;
 
 ofp->fps.dup_warning = 1000;
@@ -835,20 +835,21 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 case AVMEDIA_TYPE_AUDIO:
 if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
 ofp->format = ost->enc_ctx->sample_fmt;
-} else {
-ofp->formats = c->sample_fmts;
+} else if (opts->enc) {
+ofp->formats = opts->enc->sample_fmts;
 }
 if (ost->enc_ctx->sample_rate) {
 ofp->sample_rate = ost->enc_ctx->sample_rate;
-} else {
-ofp->sample_rates = c->supported_samplerates;
+} else if (opts->enc) {
+ofp->sample_rates = opts->enc->supported_samplerates;
 }
 if (ost->enc_ctx->ch_layout.nb_channels) {
-  

[FFmpeg-devel] [PATCH 06/11] avcodec/libaomenc: switch to get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

---
 libavcodec/libaomenc.c | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 4a71bba9c9c..899aa2b261f 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1398,16 +1398,24 @@ static const enum AVPixelFormat 
av1_pix_fmts_highbd_with_gray[] = {
 AV_PIX_FMT_NONE
 };
 
-static av_cold void av1_init_static(FFCodec *codec)
+static int av1_get_supported_config(const AVCodecContext *avctx,
+const AVCodec *codec,
+enum AVCodecConfig config,
+unsigned flags, const void **out)
 {
-int supports_monochrome = aom_codec_version() >= 20001;
-aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
-if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
-codec->p.pix_fmts = supports_monochrome ? 
av1_pix_fmts_highbd_with_gray :
-  av1_pix_fmts_highbd;
-else
-codec->p.pix_fmts = supports_monochrome ? av1_pix_fmts_with_gray :
-  av1_pix_fmts;
+if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
+int supports_monochrome = aom_codec_version() >= 20001;
+aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
+if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
+*out = supports_monochrome ? av1_pix_fmts_highbd_with_gray :
+ av1_pix_fmts_highbd;
+else
+*out = supports_monochrome ? av1_pix_fmts_with_gray :
+ av1_pix_fmts;
+return 0;
+}
+
+return ff_default_get_supported_config(avctx, codec, config, flags, out);
 }
 
 static av_cold int av1_init(AVCodecContext *avctx)
@@ -1528,5 +1536,5 @@ FFCodec ff_libaom_av1_encoder = {
   FF_CODEC_CAP_INIT_CLEANUP |
   FF_CODEC_CAP_AUTO_THREADS,
 .defaults   = defaults,
-.init_static_data = av1_init_static,
+.get_supported_config = av1_get_supported_config,
 };
-- 
2.44.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 09/11] fftools: drop unused/hacky macros

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

Having macros initialize local variables seems strange to me, and there
are no more current users of these macros. (The one that was commented
out was incorrect anyway, since the macro has changed in the meantime)
---
 fftools/cmdutils.h  | 13 -
 fftools/ffmpeg_filter.c |  2 +-
 2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index d0c773663ba..940541b9eaf 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -465,19 +465,6 @@ void *allocate_array_elem(void *array, size_t elem_size, 
int *nb_elems);
 #define GROW_ARRAY(array, nb_elems)\
 grow_array((void**), sizeof(*array), _elems, nb_elems + 1)
 
-#define GET_PIX_FMT_NAME(pix_fmt)\
-const char *name = av_get_pix_fmt_name(pix_fmt);
-
-#define GET_CODEC_NAME(id)\
-const char *name = avcodec_descriptor_get(id)->name;
-
-#define GET_SAMPLE_FMT_NAME(sample_fmt)\
-const char *name = av_get_sample_fmt_name(sample_fmt)
-
-#define GET_SAMPLE_RATE_NAME(rate)\
-char name[16];\
-snprintf(name, sizeof(name), "%d", rate);
-
 double get_rotation(const int32_t *displaymatrix);
 
 /* read file contents into a string */
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 2308abf82af..ac04841a16c 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -401,7 +401,7 @@ static void choose_ ## name (OutputFilterPriv *ofp, 
AVBPrint *bprint)  \
 }
 
 //DEF_CHOOSE_FORMAT(pix_fmts, enum AVPixelFormat, format, formats, 
AV_PIX_FMT_NONE,
-//  GET_PIX_FMT_NAME)
+//  av_get_pix_fmt_name)
 
 DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats,
   AV_SAMPLE_FMT_NONE, "%s", av_get_sample_fmt_name)
-- 
2.44.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 07/11] avcodec/codec_internal: nuke init_static_data()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

All hail get_supported_config()
---
 libavcodec/allcodecs.c  | 7 +--
 libavcodec/codec_internal.h | 8 
 2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a9f1797930a..1f22e06e710 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -916,13 +916,8 @@ static AVOnce av_codec_static_init = AV_ONCE_INIT;
 static void av_codec_init_static(void)
 {
 for (int i = 0; codec_list[i]; i++) {
-const FFCodec *codec = codec_list[i];
-if (codec->init_static_data) {
-codec->init_static_data((FFCodec*) codec);
-continue;
-}
-
 /* Backward compatibility with deprecated public fields */
+const FFCodec *codec = codec_list[i];
 if (!codec->get_supported_config)
 continue;
 
diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index 3c6328364cb..f4e97d0fbcd 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -168,14 +168,6 @@ typedef struct FFCodec {
  */
 const FFCodecDefault *defaults;
 
-/**
- * Initialize codec static data, called from av_codec_iterate().
- *
- * This is not intended for time consuming operations as it is
- * run for every codec regardless of that codec being used.
- */
-void (*init_static_data)(struct FFCodec *codec);
-
 int (*init)(struct AVCodecContext *);
 
 union {
-- 
2.44.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 08/11] fftools/opt_common: switch to avcodec_get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

While rewriting this macro, I decided to make it a bit more flexible so
it can work for all of the fields (including future fields) in a more
generic way.
---
 fftools/opt_common.c | 86 ++--
 1 file changed, 43 insertions(+), 43 deletions(-)

diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 947a226d8d1..1bf66580192 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -262,22 +262,32 @@ int show_buildconf(void *optctx, const char *opt, const 
char *arg)
 return 0;
 }
 
-#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
-if (codec->field) {  \
-const type *p = codec->field;\
- \
-printf("Supported " list_name ":");  \
-while (*p != term) { \
-get_name(*p);\
-printf(" %s", name); \
-p++; \
-}\
-printf("\n");\
-}\
+#define PRINT_CODEC_SUPPORTED(codec, config, type, name, elem, cond, fmt, ...) 
 \
+do {   
 \
+const type *elem = NULL;   
 \
+avcodec_get_supported_config(NULL, codec, config, 0,   
 \
+ (const void **) );   
 \
+if (elem) {
 \
+printf("Supported " name ":"); 
 \
+while (cond) { 
 \
+printf(" " fmt, __VA_ARGS__);  
 \
+elem++;
 \
+}  
 \
+printf("\n");  
 \
+}  
 \
+} while (0)
+
+static char *get_channel_layout_desc(const AVChannelLayout *layout,
+ char desc[], int desc_size)
+{
+av_channel_layout_describe(layout, desc, desc_size);
+return desc;
+}
 
 static void print_codec(const AVCodec *c)
 {
 int encoder = av_codec_is_encoder(c);
+char desc[128];
 
 printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
c->long_name ? c->long_name : "");
@@ -343,35 +353,19 @@ static void print_codec(const AVCodec *c)
 printf("\n");
 }
 
-if (c->supported_framerates) {
-const AVRational *fps = c->supported_framerates;
-
-printf("Supported framerates:");
-while (fps->num) {
-printf(" %d/%d", fps->num, fps->den);
-fps++;
-}
-printf("\n");
-}
-PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
-  AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
-PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
-  GET_SAMPLE_RATE_NAME);
-PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample 
formats",
-  AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
-
-if (c->ch_layouts) {
-const AVChannelLayout *p = c->ch_layouts;
-
-printf("Supported channel layouts:");
-while (p->nb_channels) {
-char name[128];
-av_channel_layout_describe(p, name, sizeof(name));
-printf(" %s", name);
-p++;
-}
-printf("\n");
-}
+PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_FRAME_RATE, AVRational, 
"framerates",
+  fps, fps->num, "%d/%d", fps->num, fps->den);
+PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_PIX_FORMAT, enum AVPixelFormat,
+  "pixel formats", fmt, *fmt != AV_PIX_FMT_NONE,
+  "%s", av_get_pix_fmt_name(*fmt));
+PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_RATE, int, "sample rates",
+  rate, *rate != 0, "%d", *rate);
+PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum 
AVSampleFormat,
+  "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
+  "%s", av_get_sample_fmt_name(*fmt));
+PRINT_CODEC_SUPPORTED(c, 

[FFmpeg-devel] [PATCH 04/11] avcodec/libx265: switch to get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

---
 libavcodec/libx265.c | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 0645cd20457..ff1e8463aa1 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -892,14 +892,24 @@ static const enum AVPixelFormat x265_csp_twelve[] = {
 AV_PIX_FMT_NONE
 };
 
-static av_cold void libx265_encode_init_csp(FFCodec *codec)
+static int libx265_get_supported_config(const AVCodecContext *avctx,
+const AVCodec *codec,
+enum AVCodecConfig config,
+unsigned flags, const void **out)
 {
-if (x265_api_get(12))
-codec->p.pix_fmts = x265_csp_twelve;
-else if (x265_api_get(10))
-codec->p.pix_fmts = x265_csp_ten;
-else if (x265_api_get(8))
-codec->p.pix_fmts = x265_csp_eight;
+if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
+if (x265_api_get(12))
+*out = x265_csp_twelve;
+else if (x265_api_get(10))
+*out = x265_csp_ten;
+else if (x265_api_get(8))
+*out = x265_csp_eight;
+else
+return AVERROR_EXTERNAL;
+return 0;
+}
+
+return ff_default_get_supported_config(avctx, codec, config, flags, out);
 }
 
 #define OFFSET(x) offsetof(libx265Context, x)
@@ -951,7 +961,7 @@ FFCodec ff_libx265_encoder = {
 .p.priv_class = ,
 .p.wrapper_name   = "libx265",
 .init = libx265_encode_init,
-.init_static_data = libx265_encode_init_csp,
+.get_supported_config = libx265_get_supported_config,
 FF_CODEC_ENCODE_CB(libx265_encode_frame),
 .close= libx265_encode_close,
 .priv_data_size   = sizeof(libx265Context),
-- 
2.44.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 05/11] avcodec/libvpxenc: switch to get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

---
 libavcodec/libvpxenc.c | 22 +++---
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index bcbdc4981e5..ac7f01e2aa9 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -2086,13 +2086,21 @@ static const enum AVPixelFormat vp9_pix_fmts_highbd[] = 
{
 AV_PIX_FMT_NONE
 };
 
-static av_cold void vp9_init_static(FFCodec *codec)
+static int vp9_get_supported_config(const AVCodecContext *avctx,
+const AVCodec *codec,
+enum AVCodecConfig config,
+unsigned flags, const void **out)
 {
-vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
-if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH)
-codec->p.pix_fmts = vp9_pix_fmts_highbd;
-else
-codec->p.pix_fmts = vp9_pix_fmts_highcol;
+if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
+vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
+if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH)
+*out = vp9_pix_fmts_highbd;
+else
+*out = vp9_pix_fmts_highcol;
+return 0;
+}
+
+return ff_default_get_supported_config(avctx, codec, config, flags, out);
 }
 
 static const AVClass class_vp9 = {
@@ -2120,6 +2128,6 @@ FFCodec ff_libvpx_vp9_encoder = {
 .caps_internal  = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
   FF_CODEC_CAP_AUTO_THREADS,
 .defaults   = defaults,
-.init_static_data = vp9_init_static,
+.get_supported_config = vp9_get_supported_config,
 };
 #endif /* CONFIG_LIBVPX_VP9_ENCODER */
-- 
2.44.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 13/31] fftools/ffmpeg: drop OutputStream.is_cfr

2024-04-05 Thread Anton Khirnov
It is used in a single place in the filtering code, so it is better to
inline it there.
---
 fftools/ffmpeg.h  | 1 -
 fftools/ffmpeg_filter.c   | 2 +-
 fftools/ffmpeg_mux_init.c | 1 -
 3 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fa8f7d8324..16497105e1 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -551,7 +551,6 @@ typedef struct OutputStream {
 /* video only */
 AVRational frame_rate;
 AVRational max_frame_rate;
-int is_cfr;
 int force_fps;
 #if FFMPEG_OPT_TOP
 int top_field_first;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index d906b72576..022c42e9c7 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1956,7 +1956,7 @@ static int choose_out_timebase(OutputFilterPriv *ofp, 
AVFrame *frame)
 fr = fr_sink;
 }
 
-if (ofilter->ost->is_cfr) {
+if (fps->vsync_method == VSYNC_CFR || fps->vsync_method == VSYNC_VSCFR) {
 if (!fr.num && !fps->framerate_max.num) {
 fr = (AVRational){25, 1};
 av_log(ofilter->ost, AV_LOG_WARNING,
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6ffa4b7491..1791905d7e 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -816,7 +816,6 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
 *vsync_method = VSYNC_VSCFR;
 }
 }
-ost->is_cfr = (*vsync_method == VSYNC_CFR || *vsync_method == 
VSYNC_VSCFR);
 #if FFMPEG_OPT_VSYNC_DROP
 if (*vsync_method == VSYNC_DROP)
 ms->ts_drop = 1;
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 29/31] fftools/ffmpeg_sched: allow filtergraphs to send to filtergraphs

2024-04-05 Thread Anton Khirnov
Will be useful for filtergraph chaining that will be added in following
commits.
---
 fftools/ffmpeg_sched.c | 94 ++
 fftools/ffmpeg_sched.h |  6 ++-
 2 files changed, 63 insertions(+), 37 deletions(-)

diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
index f8485db30b..e58b00ea97 100644
--- a/fftools/ffmpeg_sched.c
+++ b/fftools/ffmpeg_sched.c
@@ -983,20 +983,40 @@ int sch_connect(Scheduler *sch, SchedulerNode src, 
SchedulerNode dst)
 }
 case SCH_NODE_TYPE_FILTER_OUT: {
 SchFilterOut *fo;
-SchEnc  *enc;
 
 av_assert0(src.idx < sch->nb_filters &&
src.idx_stream < sch->filters[src.idx].nb_outputs);
-// filtered frames go to encoding
-av_assert0(dst.type == SCH_NODE_TYPE_ENC &&
-   dst.idx < sch->nb_enc);
+fo = >filters[src.idx].outputs[src.idx_stream];
 
-fo  = >filters[src.idx].outputs[src.idx_stream];
-enc = >enc[dst.idx];
+av_assert0(!fo->dst.type);
+fo->dst = dst;
+
+// filtered frames go to encoding or another filtergraph
+switch (dst.type) {
+case SCH_NODE_TYPE_ENC: {
+SchEnc *enc;
+
+av_assert0(dst.idx < sch->nb_enc);
+enc = >enc[dst.idx];
+
+av_assert0(!enc->src.type);
+enc->src = src;
+break;
+}
+case SCH_NODE_TYPE_FILTER_IN: {
+SchFilterIn *fi;
+
+av_assert0(dst.idx < sch->nb_filters &&
+   dst.idx_stream < sch->filters[dst.idx].nb_inputs);
+fi = >filters[dst.idx].inputs[dst.idx_stream];
+
+av_assert0(!fi->src.type);
+fi->src = src;
+break;
+}
+default: av_assert0(0);
+}
 
-av_assert0(!fo->dst.type && !enc->src.type);
-fo->dst  = dst;
-enc->src = src;
 
 break;
 }
@@ -1351,24 +1371,13 @@ static int check_acyclic(Scheduler *sch)
 goto fail;
 }
 
-// trace the transcoding graph upstream from every output stream
-// fed by a filtergraph
-for (unsigned i = 0; i < sch->nb_mux; i++) {
-SchMux *mux = >mux[i];
-
-for (unsigned j = 0; j < mux->nb_streams; j++) {
-SchMuxStream  *ms = >streams[j];
-SchedulerNode src = ms->src_sched;
-
-if (src.type != SCH_NODE_TYPE_FILTER_OUT)
-continue;
-src.idx_stream = 0;
-
-ret = check_acyclic_for_output(sch, src, filters_visited, 
filters_stack);
-if (ret < 0) {
-av_log(mux, AV_LOG_ERROR, "Transcoding graph has a cycle\n");
-goto fail;
-}
+// trace the transcoding graph upstream from every filtegraph
+for (unsigned i = 0; i < sch->nb_filters; i++) {
+ret = check_acyclic_for_output(sch, (SchedulerNode){ .idx = i },
+   filters_visited, filters_stack);
+if (ret < 0) {
+av_log(>filters[i], AV_LOG_ERROR, "Transcoding graph has a 
cycle\n");
+goto fail;
 }
 }
 
@@ -1484,13 +1493,18 @@ static int start_prepare(Scheduler *sch)
"Filtergraph input %u not connected to a source\n", j);
 return AVERROR(EINVAL);
 }
-av_assert0(fi->src.type == SCH_NODE_TYPE_DEC);
-dec = >dec[fi->src.idx];
 
-switch (dec->src.type) {
-case SCH_NODE_TYPE_DEMUX: fi->src_sched = dec->src;
   break;
-case SCH_NODE_TYPE_ENC:   fi->src_sched = 
sch->enc[dec->src.idx].src; break;
-default: av_assert0(0);
+if (fi->src.type == SCH_NODE_TYPE_FILTER_OUT)
+fi->src_sched = fi->src;
+else {
+av_assert0(fi->src.type == SCH_NODE_TYPE_DEC);
+dec = >dec[fi->src.idx];
+
+switch (dec->src.type) {
+case SCH_NODE_TYPE_DEMUX: fi->src_sched = dec->src;
   break;
+case SCH_NODE_TYPE_ENC:   fi->src_sched = 
sch->enc[dec->src.idx].src; break;
+default: av_assert0(0);
+}
 }
 }
 
@@ -2379,12 +2393,17 @@ void sch_filter_receive_finish(Scheduler *sch, unsigned 
fg_idx, unsigned in_idx)
 int sch_filter_send(Scheduler *sch, unsigned fg_idx, unsigned out_idx, AVFrame 
*frame)
 {
 SchFilterGraph *fg;
+SchedulerNode  dst;
 
 av_assert0(fg_idx < sch->nb_filters);
 fg = >filters[fg_idx];
 
 av_assert0(out_idx < fg->nb_outputs);
-return send_to_enc(sch, >enc[fg->outputs[out_idx].dst.idx], frame);
+dst = fg->outputs[out_idx].dst;
+
+return (dst.type == SCH_NODE_TYPE_ENC)?
+   send_to_enc   (sch, >enc[dst.idx], frame) :
+   send_to_filter(sch, >filters[dst.idx], dst.idx_stream, frame);
 }
 
 static int 

[FFmpeg-devel] [PATCH 22/31] fftools/ffmpeg_filter: move most of -apad logic to the muxer

2024-04-05 Thread Anton Khirnov
The decision whether -apad actually does anything is made based on muxer
properties, and so more properly belongs there. Filtering code only
receives the result.
---
 fftools/ffmpeg.h  |  3 ++-
 fftools/ffmpeg_filter.c   | 16 +++-
 fftools/ffmpeg_mux.c  |  1 -
 fftools/ffmpeg_mux.h  |  2 ++
 fftools/ffmpeg_mux_init.c | 36 +---
 5 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8e773165da..26b42a3fcd 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -320,6 +320,8 @@ typedef struct OutputFilter {
  * this stores the output linklabel, if any */
 uint8_t *linklabel;
 
+char*apad;
+
 enum AVMediaType type;
 
 atomic_uint_least64_t nb_frames_dup;
@@ -581,7 +583,6 @@ typedef struct OutputStream {
 OutputFilter *filter;
 
 AVDictionary *encoder_opts;
-char *apad;
 
 char *attachment_filename;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 225fa4bda2..ec17e99494 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -969,6 +969,7 @@ void fg_free(FilterGraph **pfg)
 
 av_freep(>linklabel);
 av_freep(>name);
+av_freep(>apad);
 av_freep(>name);
 av_channel_layout_uninit(>ch_layout);
 av_freep(>outputs[j]);
@@ -1430,8 +1431,6 @@ static int configure_output_audio_filter(FilterGraph *fg, 
AVFilterGraph *graph,
  OutputFilter *ofilter, AVFilterInOut 
*out)
 {
 OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
-OutputStream *ost = ofilter->ost;
-OutputFile*of = ost->file;
 AVFilterContext *last_filter = out->filter_ctx;
 int pad_idx = out->pad_idx;
 AVBPrint args;
@@ -1493,17 +1492,8 @@ static int configure_output_audio_filter(FilterGraph 
*fg, AVFilterGraph *graph,
 pad_idx = 0;
 }
 
-if (ost->apad && of->shortest) {
-int i;
-
-for (i = 0; i < of->nb_streams; i++)
-if (of->streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
-break;
-
-if (i < of->nb_streams) {
-AUTO_INSERT_FILTER("-apad", "apad", ost->apad);
-}
-}
+if (ofilter->apad)
+AUTO_INSERT_FILTER("-apad", "apad", ofilter->apad);
 
 snprintf(name, sizeof(name), "trim for output %s", ofp->name);
 ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 557f08b3a5..6a64cba72d 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -815,7 +815,6 @@ static void ost_free(OutputStream **post)
 av_expr_free(ost->kf.pexpr);
 
 av_freep(>logfile_prefix);
-av_freep(>apad);
 
 av_freep(>attachment_filename);
 
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index f8b6f7a790..1e9ea35412 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -78,6 +78,8 @@ typedef struct MuxStream {
 #if FFMPEG_OPT_VSYNC_DROP
 int ts_drop;
 #endif
+
+char   *apad;
 } MuxStream;
 
 typedef struct Muxer {
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6e19b98abd..a483fffa6e 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -828,6 +828,7 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
 static int new_stream_audio(Muxer *mux, const OptionsContext *o,
 OutputStream *ost)
 {
+MuxStream *ms = ms_from_ost(ost);
 AVFormatContext *oc = mux->fc;
 AVStream *st = ost->st;
 
@@ -836,7 +837,6 @@ static int new_stream_audio(Muxer *mux, const 
OptionsContext *o,
 int channels = 0;
 char *layout = NULL;
 char *sample_fmt = NULL;
-const char *apad = NULL;
 
 MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
 if (channels) {
@@ -859,12 +859,7 @@ static int new_stream_audio(Muxer *mux, const 
OptionsContext *o,
 
 MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, 
st);
 
-MATCH_PER_STREAM_OPT(apad, str, apad, oc, st);
-if (apad) {
-ost->apad = av_strdup(apad);
-if (!ost->apad)
-return AVERROR(ENOMEM);
-}
+MATCH_PER_STREAM_OPT(apad, str, ms->apad, oc, st);
 }
 
 return 0;
@@ -1890,6 +1885,33 @@ static int create_streams(Muxer *mux, const 
OptionsContext *o)
 }
 }
 
+// handle -apad
+if (mux->of.shortest) {
+int have_video = 0;
+
+for (unsigned i = 0; i < mux->of.nb_streams; i++)
+if (mux->of.streams[i]->type == AVMEDIA_TYPE_VIDEO) {
+have_video = 1;
+break;
+}
+
+for (unsigned i = 0; have_video && i < mux->of.nb_streams; i++) {
+MuxStream *ms = ms_from_ost(mux->of.streams[i]);
+OutputFilter *ofilter = ms->ost.filter;
+
+   

[FFmpeg-devel] [PATCH 23/31] fftools/ffmpeg_mux: drop OutputFile.shortest

2024-04-05 Thread Anton Khirnov
It is no longer needed outside of of_open() and its children.
---
 fftools/ffmpeg.h  |  1 -
 fftools/ffmpeg_mux_init.c | 17 +
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 26b42a3fcd..1d32009f90 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -620,7 +620,6 @@ typedef struct OutputFile {
 int64_t recording_time;  ///< desired length of the resulting file in 
microseconds == AV_TIME_BASE units
 int64_t start_time;  ///< start time in microseconds == AV_TIME_BASE 
units
 
-int shortest;
 int bitexact;
 } OutputFile;
 
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index a483fffa6e..9aad19a85d 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1886,7 +1886,7 @@ static int create_streams(Muxer *mux, const 
OptionsContext *o)
 }
 
 // handle -apad
-if (mux->of.shortest) {
+if (o->shortest) {
 int have_video = 0;
 
 for (unsigned i = 0; i < mux->of.nb_streams; i++)
@@ -1921,7 +1921,8 @@ static int create_streams(Muxer *mux, const 
OptionsContext *o)
 return 0;
 }
 
-static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t 
buf_size_us)
+static int setup_sync_queues(Muxer *mux, AVFormatContext *oc,
+ int64_t buf_size_us, int shortest)
 {
 OutputFile *of = >of;
 int nb_av_enc = 0, nb_audio_fs = 0, nb_interleaved = 0;
@@ -1947,7 +1948,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext 
*oc, int64_t buf_size_u
 limit_frames_av_enc |= (ms->max_frames < INT64_MAX) && IS_AV_ENC(ost, 
type);
 }
 
-if (!((nb_interleaved > 1 && of->shortest) ||
+if (!((nb_interleaved > 1 && shortest) ||
   (nb_interleaved > 0 && limit_frames) ||
   nb_audio_fs))
 return 0;
@@ -1963,7 +1964,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext 
*oc, int64_t buf_size_u
  * different encoders run in different threads and need external
  * synchronization, while muxer sync queues can be handled inside the muxer
  */
-if ((of->shortest && nb_av_enc > 1) || limit_frames_av_enc || nb_audio_fs) 
{
+if ((shortest && nb_av_enc > 1) || limit_frames_av_enc || nb_audio_fs) {
 int sq_idx, ret;
 
 sq_idx = sch_add_sq_enc(mux->sch, buf_size_us, mux);
@@ -1979,7 +1980,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext 
*oc, int64_t buf_size_u
 continue;
 
 ret = sch_sq_add_enc(mux->sch, sq_idx, ms->sch_idx_enc,
- of->shortest || ms->max_frames < INT64_MAX,
+ shortest || ms->max_frames < INT64_MAX,
  ms->max_frames);
 if (ret < 0)
 return ret;
@@ -2006,7 +2007,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext 
*oc, int64_t buf_size_u
 continue;
 
 ms->sq_idx_mux = sq_add_stream(mux->sq_mux,
-   of->shortest || ms->max_frames < 
INT64_MAX);
+   shortest || ms->max_frames < 
INT64_MAX);
 if (ms->sq_idx_mux < 0)
 return ms->sq_idx_mux;
 
@@ -3043,7 +3044,6 @@ int of_open(const OptionsContext *o, const char 
*filename, Scheduler *sch)
 
 of->recording_time = recording_time;
 of->start_time = o->start_time;
-of->shortest   = o->shortest;
 
 mux->limit_filesize= o->limit_filesize;
 av_dict_copy(>opts, o->g->format_opts, 0);
@@ -3159,7 +3159,8 @@ int of_open(const OptionsContext *o, const char 
*filename, Scheduler *sch)
 return err;
 }
 
-err = setup_sync_queues(mux, oc, o->shortest_buf_duration * AV_TIME_BASE);
+err = setup_sync_queues(mux, oc, o->shortest_buf_duration * AV_TIME_BASE,
+o->shortest);
 if (err < 0) {
 av_log(mux, AV_LOG_FATAL, "Error setting up output sync queues\n");
 return err;
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 28/31] fftools/ffmpeg_filter: change processing order in fg_finalise_bindings()

2024-04-05 Thread Anton Khirnov
First bind all inputs in all filtergraphs, only then check that all
outputs are bound.

Needed by the following commit.
---
 fftools/ffmpeg.h|  2 +-
 fftools/ffmpeg_filter.c | 33 ++---
 fftools/ffmpeg_opt.c| 10 --
 3 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 882d241bdb..885a7c0c10 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -724,7 +724,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream 
*ost,
 char *graph_desc,
 Scheduler *sch, unsigned sch_idx_enc,
 const OutputFilterOptions *opts);
-int fg_finalise_bindings(FilterGraph *fg);
+int fg_finalise_bindings(void);
 
 /**
  * Get our axiliary frame data attached to the frame, allocating it
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 388c8919fd..1e14962f41 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1272,7 +1272,7 @@ static int fg_complex_bind_input(FilterGraph *fg, 
InputFilter *ifilter)
 return 0;
 }
 
-int fg_finalise_bindings(FilterGraph *fg)
+static int bind_inputs(FilterGraph *fg)
 {
 // bind filtergraph inputs to input streams
 for (int i = 0; i < fg->nb_inputs; i++) {
@@ -1287,14 +1287,33 @@ int fg_finalise_bindings(FilterGraph *fg)
 return ret;
 }
 
-for (int i = 0; i < fg->nb_outputs; i++) {
-OutputFilter *output = fg->outputs[i];
-if (!output->bound) {
-av_log(filtergraphs[i], AV_LOG_FATAL,
-   "Filter %s has an unconnected output\n", output->name);
-return AVERROR(EINVAL);
+return 0;
+}
+
+int fg_finalise_bindings(void)
+{
+int ret;
+
+for (int i = 0; i < nb_filtergraphs; i++) {
+ret = bind_inputs(filtergraphs[i]);
+if (ret < 0)
+return ret;
+}
+
+// check that all outputs were bound
+for (int i = 0; i < nb_filtergraphs; i++) {
+FilterGraph *fg = filtergraphs[i];
+
+for (int j = 0; j < fg->nb_outputs; j++) {
+OutputFilter *output = fg->outputs[j];
+if (!output->bound) {
+av_log(filtergraphs[j], AV_LOG_FATAL,
+   "Filter %s has an unconnected output\n", output->name);
+return AVERROR(EINVAL);
+}
 }
 }
+
 return 0;
 }
 
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index f764da1ed4..6526e8e3e8 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1264,12 +1264,10 @@ int ffmpeg_parse_options(int argc, char **argv, 
Scheduler *sch)
 }
 
 // bind unbound filtegraph inputs/outputs and check consistency
-for (int i = 0; i < nb_filtergraphs; i++) {
-ret = fg_finalise_bindings(filtergraphs[i]);
-if (ret < 0) {
-errmsg = "binding filtergraph inputs/outputs";
-goto fail;
-}
+ret = fg_finalise_bindings();
+if (ret < 0) {
+errmsg = "binding filtergraph inputs/outputs";
+goto fail;
 }
 
 correct_input_start_times();
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 16/31] fftools/ffmpeg_filter: simplify retrieving filter type

2024-04-05 Thread Anton Khirnov
---
 fftools/ffmpeg_filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 41d96267bc..ffbc13eb70 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1472,7 +1472,7 @@ fail:
 static int configure_output_filter(FilterGraph *fg, AVFilterGraph *graph,
OutputFilter *ofilter, AVFilterInOut *out)
 {
-switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) 
{
+switch (ofilter->type) {
 case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, graph, 
ofilter, out);
 case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, graph, 
ofilter, out);
 default: av_assert0(0); return 0;
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 25/31] fftools/ffmpeg_filter: accept encoder thread count through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Stop digging through encoder options manually.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  |  2 ++
 fftools/ffmpeg_filter.c   | 20 ++--
 fftools/ffmpeg_mux_init.c |  5 +
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7135d9563c..f77ec956b3 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -291,6 +291,8 @@ typedef struct OutputFilterOptions {
 AVDictionary   *sws_opts;
 AVDictionary   *swr_opts;
 
+const char *nb_threads;
+
 // A combination of OFilterFlags.
 unsignedflags;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ec17e99494..9fc6e32960 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -59,6 +59,8 @@ typedef struct FilterGraphPriv {
 
 const char  *graph_desc;
 
+char*nb_threads;
+
 // frame for temporarily holding output from the filtergraph
 AVFrame *frame;
 // frame for sending output to the encoder
@@ -976,6 +978,7 @@ void fg_free(FilterGraph **pfg)
 }
 av_freep(>outputs);
 av_freep(>graph_desc);
+av_freep(>nb_threads);
 
 av_frame_free(>frame);
 av_frame_free(>frame_enc);
@@ -1165,6 +1168,13 @@ int init_simple_filtergraph(InputStream *ist, 
OutputStream *ost,
 if (ret < 0)
 return ret;
 
+if (opts->nb_threads) {
+av_freep(>nb_threads);
+fgp->nb_threads = av_strdup(opts->nb_threads);
+if (!fgp->nb_threads)
+return AVERROR(ENOMEM);
+}
+
 return 0;
 }
 
@@ -1735,17 +1745,15 @@ static int configure_filtergraph(FilterGraph *fg, 
FilterGraphThread *fgt)
 
 if (simple) {
 OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[0]);
-OutputStream *ost = fg->outputs[0]->ost;
 
 if (filter_nbthreads) {
 ret = av_opt_set(fgt->graph, "threads", filter_nbthreads, 0);
 if (ret < 0)
 goto fail;
-} else {
-const AVDictionaryEntry *e = NULL;
-e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
-if (e)
-av_opt_set(fgt->graph, "threads", e->value, 0);
+} else if (fgp->nb_threads) {
+ret = av_opt_set(fgt->graph, "threads", fgp->nb_threads, 0);
+if (ret < 0)
+return ret;
 }
 
 if (av_dict_count(ofp->sws_opts)) {
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index ffcc20a504..10421ae1b0 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1370,6 +1370,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 if (ost->enc &&
 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
+const AVDictionaryEntry *e;
 char name[16];
 OutputFilterOptions opts = {
 .enc = enc,
@@ -1395,6 +1396,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index);
 
+e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
+if (e)
+opts.nb_threads = e->value;
+
 // MJPEG encoder exports a full list of supported pixel formats,
 // but the full-range ones are experimental-only.
 // Restrict the auto-conversion list unless -strict experimental
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 26/31] fftools/ffmpeg_filter: drop OutputFilter.ost

2024-04-05 Thread Anton Khirnov
All remaining code accessing it only needs to know whether this
filtergraph output has been bound or not.
---
 fftools/ffmpeg.h  | 2 +-
 fftools/ffmpeg_filter.c   | 6 +++---
 fftools/ffmpeg_mux_init.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f77ec956b3..6446a141b5 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -314,12 +314,12 @@ typedef struct InputFilter {
 typedef struct OutputFilter {
 const AVClass   *class;
 
-struct OutputStream *ost;
 struct FilterGraph  *graph;
 uint8_t *name;
 
 /* for filters that are not yet bound to an output stream,
  * this stores the output linklabel, if any */
+int  bound;
 uint8_t *linklabel;
 
 char*apad;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 9fc6e32960..3988cf5fc2 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -806,10 +806,10 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 FilterGraphPriv *fgp = fgp_from_fg(fg);
 int ret;
 
-av_assert0(!ofilter->ost);
+av_assert0(!ofilter->bound);
 av_assert0(ofilter->type == ost->type);
 
-ofilter->ost = ost;
+ofilter->bound = 1;
 av_freep(>linklabel);
 
 ofp->flags= opts->flags;
@@ -1279,7 +1279,7 @@ int fg_finalise_bindings(FilterGraph *fg)
 
 for (int i = 0; i < fg->nb_outputs; i++) {
 OutputFilter *output = fg->outputs[i];
-if (!output->ost) {
+if (!output->bound) {
 av_log(filtergraphs[i], AV_LOG_FATAL,
"Filter %s has an unconnected output\n", output->name);
 return AVERROR(EINVAL);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 10421ae1b0..6d8bd5bcdf 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1827,7 +1827,7 @@ static int create_streams(Muxer *mux, const 
OptionsContext *o)
 for (int j = 0; j < fg->nb_outputs; j++) {
 OutputFilter *ofilter = fg->outputs[j];
 
-if (ofilter->linklabel || ofilter->ost)
+if (ofilter->linklabel || ofilter->bound)
 continue;
 
 auto_disable |= 1 << ofilter->type;
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH] avcodec/libaomenc: bump the minimum required version to 2.0.0

2024-04-05 Thread James Almer
v2.0.0 is already four years old and available on stable distro releases.
With this we stop setting codec capabilities during static data initialization.

Signed-off-by: James Almer 
---
 configure  |  2 +-
 libavcodec/libaomenc.c | 42 --
 2 files changed, 1 insertion(+), 43 deletions(-)

diff --git a/configure b/configure
index 493fe3cffd..f511fbae49 100755
--- a/configure
+++ b/configure
@@ -6834,7 +6834,7 @@ enabled gnutls&& require_pkg_config gnutls 
gnutls gnutls/gnutls.h gn
 enabled jni   && { [ $target_os = "android" ] && check_headers 
jni.h && enabled pthreads || die "ERROR: jni not found"; }
 enabled ladspa&& require_headers "ladspa.h dlfcn.h"
 enabled lcms2 && require_pkg_config lcms2 "lcms2 >= 2.13" lcms2.h 
cmsCreateContext
-enabled libaom&& require_pkg_config libaom "aom >= 1.0.0" 
aom/aom_codec.h aom_codec_version
+enabled libaom&& require_pkg_config libaom "aom >= 2.0.0" 
aom/aom_codec.h aom_codec_version
 enabled libaribb24&& { check_pkg_config libaribb24 "aribb24 > 1.0.3" 
"aribb24/aribb24.h" arib_instance_new ||
{ enabled gpl && require_pkg_config libaribb24 
aribb24 "aribb24/aribb24.h" arib_instance_new; } ||
die "ERROR: libaribb24 requires version higher 
than 1.0.3 or --enable-gpl."; }
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index d660afab4e..d2bdb622e0 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -155,27 +155,14 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
 [AV1E_SET_TILE_ROWS]= "AV1E_SET_TILE_ROWS",
 [AV1E_SET_ENABLE_RESTORATION] = "AV1E_SET_ENABLE_RESTORATION",
-#ifdef AOM_CTRL_AV1E_SET_ROW_MT
 [AV1E_SET_ROW_MT]   = "AV1E_SET_ROW_MT",
-#endif
-#ifdef AOM_CTRL_AV1E_SET_DENOISE_NOISE_LEVEL
 [AV1E_SET_DENOISE_NOISE_LEVEL] =  "AV1E_SET_DENOISE_NOISE_LEVEL",
-#endif
-#ifdef AOM_CTRL_AV1E_SET_DENOISE_BLOCK_SIZE
 [AV1E_SET_DENOISE_BLOCK_SIZE] =   "AV1E_SET_DENOISE_BLOCK_SIZE",
-#endif
-#ifdef AOM_CTRL_AV1E_SET_MAX_REFERENCE_FRAMES
 [AV1E_SET_MAX_REFERENCE_FRAMES] = "AV1E_SET_MAX_REFERENCE_FRAMES",
-#endif
-#ifdef AOM_CTRL_AV1E_SET_ENABLE_GLOBAL_MOTION
 [AV1E_SET_ENABLE_GLOBAL_MOTION] = "AV1E_SET_ENABLE_GLOBAL_MOTION",
-#endif
-#ifdef AOM_CTRL_AV1E_SET_ENABLE_INTRABC
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
-#endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
-#if AOM_ENCODER_ABI_VERSION >= 22
 [AV1E_SET_ENABLE_1TO4_PARTITIONS] = "AV1E_SET_ENABLE_1TO4_PARTITIONS",
 [AV1E_SET_ENABLE_AB_PARTITIONS]   = "AV1E_SET_ENABLE_AB_PARTITIONS",
 [AV1E_SET_ENABLE_RECT_PARTITIONS] = "AV1E_SET_ENABLE_RECT_PARTITIONS",
@@ -204,13 +191,10 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_REDUCED_REFERENCE_SET]= "AV1E_SET_REDUCED_REFERENCE_SET",
 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
 [AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS",
-#endif
 #ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
 [AV1E_GET_NUM_OPERATING_POINTS] = "AV1E_GET_NUM_OPERATING_POINTS",
 #endif
-#ifdef AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX
 [AV1E_GET_SEQ_LEVEL_IDX]= "AV1E_GET_SEQ_LEVEL_IDX",
-#endif
 #ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
 [AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
 #endif
@@ -691,12 +675,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
 AOMContext *ctx = avctx->priv_data;
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
 struct aom_codec_enc_cfg enccfg = { 0 };
-#ifdef AOM_FRAME_IS_INTRAONLY
 aom_codec_flags_t flags =
 (avctx->flags & AV_CODEC_FLAG_PSNR) ? AOM_CODEC_USE_PSNR : 0;
-#else
 aom_codec_flags_t flags = 0;
-#endif
 AVCPBProperties *cpb_props;
 int res;
 aom_img_fmt_t img_fmt;
@@ -886,7 +867,6 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef);
 if (ctx->enable_restoration >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION, 
ctx->enable_restoration);
-#if AOM_ENCODER_ABI_VERSION >= 22
 if (ctx->enable_rect_partitions >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_RECT_PARTITIONS, 
ctx->enable_rect_partitions);
 if (ctx->enable_1to4_partitions >= 0)
@@ -943,7 +923,6 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_ONESIDED_COMP, 
ctx->enable_onesided_comp);
 if (ctx->enable_smooth_interintra >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTERINTRA, 
ctx->enable_smooth_interintra);
-#endif
 
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
@@ -972,31 +951,19 @@ static 

[FFmpeg-devel] [PATCH 17/31] fftools/ffmpeg_filter: add an AVClass to OutputFilter

2024-04-05 Thread Anton Khirnov
Use it for logging where appropriate, avoid logging to OutputStream as
we do not own it.

This is a step towards decoupling filtering from encoding.
---
 fftools/ffmpeg.h|  2 ++
 fftools/ffmpeg_filter.c | 68 +
 2 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 3c196c25e5..786f925bc6 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -302,6 +302,8 @@ typedef struct InputFilter {
 } InputFilter;
 
 typedef struct OutputFilter {
+const AVClass   *class;
+
 struct OutputStream *ost;
 struct FilterGraph  *graph;
 uint8_t *name;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ffbc13eb70..840502bd62 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -188,6 +188,9 @@ typedef struct OutputFilterPriv {
 
 int index;
 
+void   *log_parent;
+charlog_name[32];
+
 char   *name;
 
 AVFilterContext*filter;
@@ -629,7 +632,21 @@ static char *describe_filter_link(FilterGraph *fg, 
AVFilterInOut *inout, int in)
avfilter_pad_get_name(pads, inout->pad_idx));
 }
 
-static OutputFilter *ofilter_alloc(FilterGraph *fg)
+static const char *ofilter_item_name(void *obj)
+{
+OutputFilterPriv *ofp = obj;
+return ofp->log_name;
+}
+
+static const AVClass ofilter_class = {
+.class_name= "OutputFilter",
+.version   = LIBAVUTIL_VERSION_INT,
+.item_name = ofilter_item_name,
+.parent_log_context_offset = offsetof(OutputFilterPriv, log_parent),
+.category  = AV_CLASS_CATEGORY_FILTER,
+};
+
+static OutputFilter *ofilter_alloc(FilterGraph *fg, enum AVMediaType type)
 {
 OutputFilterPriv *ofp;
 OutputFilter *ofilter;
@@ -639,10 +656,16 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
 return NULL;
 
 ofilter   = >ofilter;
+ofilter->class= _class;
+ofp->log_parent   = fg;
 ofilter->graph= fg;
+ofilter->type = type;
 ofp->format   = -1;
 ofp->index= fg->nb_outputs - 1;
 
+snprintf(ofp->log_name, sizeof(ofp->log_name), "%co%d",
+ av_get_media_type_string(type)[0], ofp->index);
+
 return ofilter;
 }
 
@@ -790,6 +813,14 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 if (!ofp->name)
 return AVERROR(EINVAL);
 
+if (fgp->is_simple) {
+// for simple filtergraph there is just one output,
+// so use only graph-level information for logging
+ofp->log_parent = NULL;
+av_strlcpy(ofp->log_name, fgp->log_name, sizeof(ofp->log_name));
+} else
+av_strlcatf(ofp->log_name, sizeof(ofp->log_name), "->%s", ofp->name);
+
 switch (ofilter->type) {
 case AVMEDIA_TYPE_VIDEO:
 ofp->width  = opts->width;
@@ -1025,7 +1056,9 @@ int fg_create(FilterGraph **pfg, char *graph_desc, 
Scheduler *sch)
 }
 
 for (AVFilterInOut *cur = outputs; cur; cur = cur->next) {
-OutputFilter *const ofilter = ofilter_alloc(fg);
+const enum AVMediaType type = 
avfilter_pad_get_type(cur->filter_ctx->output_pads,
+cur->pad_idx);
+OutputFilter *const ofilter = ofilter_alloc(fg, type);
 
 if (!ofilter) {
 ret = AVERROR(ENOMEM);
@@ -1035,8 +1068,6 @@ int fg_create(FilterGraph **pfg, char *graph_desc, 
Scheduler *sch)
 ofilter->linklabel = cur->name;
 cur->name  = NULL;
 
-ofilter->type  = 
avfilter_pad_get_type(cur->filter_ctx->output_pads,
-   cur->pad_idx);
 ofilter->name  = describe_filter_link(fg, cur, 0);
 if (!ofilter->name) {
 ret = AVERROR(ENOMEM);
@@ -1400,7 +1431,7 @@ static int configure_output_audio_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
 AVFilterContext *filt_ctx;  \
 \
-av_log(fg, AV_LOG_INFO, opt_name " is forwarded to lavfi "  \
+av_log(ofilter, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
"similarly to -af " filter_name "=%s.\n", arg);  \
 \
 ret = avfilter_graph_create_filter(_ctx,   \
@@ -1929,7 +1960,7 @@ static int choose_out_timebase(OutputFilterPriv *ofp, 
AVFrame *frame)
 // apply -enc_time_base
 if (ofp->enc_timebase.num == ENC_TIME_BASE_DEMUX &&
 (fd->dec.tb.num <= 0 || fd->dec.tb.den <= 0)) {
-av_log(ofilter->ost, AV_LOG_ERROR,
+av_log(ofp, AV_LOG_ERROR,
 

Re: [FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_filter: stop accessing encoder AVCodecContext

2024-04-05 Thread Anton Khirnov
Quoting Dennis Mungai (2024-04-05 19:07:19)
> On Fri, 5 Apr 2024 at 19:54, Gyan Doshi  wrote:
> 
> >
> >
> > On 2024-04-05 10:20 pm, Dennis Mungai wrote:
> > >
> > > Does this imply that down the line, with this and additional patchsets,
> > > that FFmpeg can handle tasks such as stream copy and filtering in the
> > same
> > > invocation?
> >
> > What do you mean? If you map a stream twice, you already can do that now.
> >
> > Regards,
> > Gyan
> >
> 
> What of doing the same *without* mapping the stream twice?

What's the issue with mapping a stream twice?

> A complex filtergraph could have a stream mapped, split and then passed to
> a copy codec operation, for example, without needing the double re-map
> implied above.

Filtergraphs process decoded frames, streamcopy bypasses them entirely.
None of this affects streamcopy.

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

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


[FFmpeg-devel] [PATCH] avcodec/libx264: bump minimum required version to 160

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

This version is four years old, and present in Debian oldstable, Ubuntu
22.04 and Leap 15.1.

Allows cleaning up both the configure check and the file substantially.
In particular, this is motivated by the desire to stop relying on
init_static_data.
---
 configure|  4 +--
 libavcodec/libx264.c | 64 +++-
 2 files changed, 10 insertions(+), 58 deletions(-)

diff --git a/configure b/configure
index a393f6ea655..070ec7fe1da 100755
--- a/configure
+++ b/configure
@@ -7000,9 +7000,7 @@ enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
 enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder 
"libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
 enabled libx264   && require_pkg_config libx264 x264 "stdint.h x264.h" 
x264_encoder_encode &&
- require_cpp_condition libx264 x264.h "X264_BUILD 
>= 122" && {
- [ "$toolchain" != "msvc" ] ||
- require_cpp_condition libx264 x264.h "X264_BUILD 
>= 158"; } &&
+ require_cpp_condition libx264 x264.h "X264_BUILD 
>= 160" &&
  check_cpp_condition libx264_hdr10 x264.h 
"X264_BUILD >= 163" &&
  check_cpp_condition libx262 x264.h "X264_MPEG2"
 enabled libx265   && require_pkg_config libx265 x265 x265.h 
x265_api_get &&
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index eadb20d2b39..404ad6d9939 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -270,11 +270,9 @@ static void reconfig_encoder(AVCodecContext *ctx, const 
AVFrame *frame)
 case AV_STEREO3D_FRAMESEQUENCE:
 fpa_type = 5;
 break;
-#if X264_BUILD >= 145
 case AV_STEREO3D_2D:
 fpa_type = 6;
 break;
-#endif
 default:
 fpa_type = -1;
 break;
@@ -394,14 +392,14 @@ static int setup_mb_info(AVCodecContext *ctx, 
x264_picture_t *pic,
 return 0;
 }
 
-static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic, int bit_depth,
+static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic,
  const AVFrame *frame, const uint8_t *data, size_t size)
 {
 X264Context *x4 = ctx->priv_data;
 
 int mbx = (frame->width + MB_SIZE - 1) / MB_SIZE;
 int mby = (frame->height + MB_SIZE - 1) / MB_SIZE;
-int qp_range = 51 + 6 * (bit_depth - 8);
+int qp_range = 51 + 6 * (x4->params.i_bitdepth - 8);
 int nb_rois;
 const AVRegionOfInterest *roi;
 uint32_t roi_size;
@@ -476,7 +474,7 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame 
*frame,
 x264_sei_t *sei = >extra_sei;
 unsigned int sei_data_size = 0;
 int64_t wallclock = 0;
-int bit_depth, ret;
+int ret;
 AVFrameSideData *sd;
 AVFrameSideData *mbinfo_sd;
 
@@ -486,12 +484,7 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame 
*frame,
 
 x264_picture_init(pic);
 pic->img.i_csp   = x4->params.i_csp;
-#if X264_BUILD >= 153
-bit_depth = x4->params.i_bitdepth;
-#else
-bit_depth = x264_bit_depth;
-#endif
-if (bit_depth > 8)
+if (x4->params.i_bitdepth > 8)
 pic->img.i_csp |= X264_CSP_HIGH_DEPTH;
 pic->img.i_plane = av_pix_fmt_count_planes(ctx->pix_fmt);
 
@@ -564,7 +557,7 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame 
*frame,
 
 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_REGIONS_OF_INTEREST);
 if (sd) {
-ret = setup_roi(ctx, pic, bit_depth, frame, sd->data, sd->size);
+ret = setup_roi(ctx, pic, frame, sd->data, sd->size);
 if (ret < 0)
 goto fail;
 }
@@ -1109,9 +1102,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
 x4->params.p_log_private= avctx;
 x4->params.i_log_level  = X264_LOG_DEBUG;
 x4->params.i_csp= convert_pix_fmt(avctx->pix_fmt);
-#if X264_BUILD >= 153
 x4->params.i_bitdepth   = 
av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
-#endif
 
 PARSE_X264_OPT("weightp", wpredp);
 
@@ -1180,11 +1171,10 @@ static av_cold int X264_init(AVCodecContext *avctx)
 else if (x4->params.i_level_idc > 0) {
 int i;
 int mbn = AV_CEIL_RSHIFT(avctx->width, 4) * 
AV_CEIL_RSHIFT(avctx->height, 4);
-int scale = X264_BUILD < 129 ? 384 : 1;
 
 for (i = 0; iparams.i_level_idc)
-x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / 
mbn / scale, 1, x4->params.i_frame_reference);
+x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / 
mbn, 1, x4->params.i_frame_reference);
 }
 
 if (avctx->trellis >= 0)
@@ -1228,12 +1218,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
 x4->params.b_vfr_input = 0;
 }
 if (x4->avcintra_class >= 0)
-#if 

[FFmpeg-devel] [PATCH 10/31] fftools/ffmpeg_filter: move the MJPEG format selection hack to muxer setup

2024-04-05 Thread Anton Khirnov
That, if anywhere, is a more appropriate place for it.
---
 fftools/ffmpeg.h  |  2 ++
 fftools/ffmpeg_filter.c   | 29 +++--
 fftools/ffmpeg_mux_init.c | 24 
 3 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 56c2fedcc4..d0e896dbe7 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -270,6 +270,8 @@ enum OFilterFlags {
 typedef struct OutputFilterOptions {
 // Codec used for encoding, may be NULL
 const AVCodec  *enc;
+// Overrides encoder pixel formats when set.
+const enum AVPixelFormat *pix_fmts;
 
 int64_t ts_offset;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 0b78898af0..5661dc960a 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -788,34 +788,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofp->height = ost->enc_ctx->height;
 if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
 ofp->format = ost->enc_ctx->pix_fmt;
-} else if (opts->enc) {
+} else if (opts->pix_fmts)
+ofp->formats = opts->pix_fmts;
+else if (opts->enc)
 ofp->formats = opts->enc->pix_fmts;
 
-// MJPEG encoder exports a full list of supported pixel formats,
-// but the full-range ones are experimental-only.
-// Restrict the auto-conversion list unless -strict experimental
-// has been specified.
-if (!strcmp(opts->enc->name, "mjpeg")) {
-// FIXME: YUV420P etc. are actually supported with full color 
range,
-// yet the latter information isn't available here.
-static const enum AVPixelFormat mjpeg_formats[] =
-{ AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, 
AV_PIX_FMT_YUVJ444P,
-  AV_PIX_FMT_NONE };
-
-const AVDictionaryEntry *strict = 
av_dict_get(ost->encoder_opts, "strict", NULL, 0);
-int strict_val = ost->enc_ctx->strict_std_compliance;
-
-if (strict) {
-const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, 
NULL, 0, 0);
-av_assert0(o);
-av_opt_eval_int(ost->enc_ctx, o, strict->value, 
_val);
-}
-
-if (strict_val > FF_COMPLIANCE_UNOFFICIAL)
-ofp->formats = mjpeg_formats;
-}
-}
-
 fgp->disable_conversions |= !!(ofp->flags & 
OFILTER_FLAG_DISABLE_CONVERT);
 
 ofp->fps.last_frame = av_frame_alloc();
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 28090423c6..04642f5c8b 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1384,6 +1384,30 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt,
 };
 
+// MJPEG encoder exports a full list of supported pixel formats,
+// but the full-range ones are experimental-only.
+// Restrict the auto-conversion list unless -strict experimental
+// has been specified.
+if (!strcmp(enc->name, "mjpeg")) {
+// FIXME: YUV420P etc. are actually supported with full color 
range,
+// yet the latter information isn't available here.
+static const enum AVPixelFormat mjpeg_formats[] =
+{ AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, 
AV_PIX_FMT_YUVJ444P,
+  AV_PIX_FMT_NONE };
+
+const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, 
"strict", NULL, 0);
+int strict_val = ost->enc_ctx->strict_std_compliance;
+
+if (strict) {
+const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, 
NULL, 0, 0);
+av_assert0(o);
+av_opt_eval_int(ost->enc_ctx, o, strict->value, _val);
+}
+
+if (strict_val > FF_COMPLIANCE_UNOFFICIAL)
+opts.pix_fmts = mjpeg_formats;
+}
+
 if (ofilter) {
 ost->filter   = ofilter;
 ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, );
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 18/31] fftools/ffmpeg_filter: drop an unnecessary use of OutputStream

2024-04-05 Thread Anton Khirnov
OutputFilter.type contains the same information.
---
 fftools/ffmpeg_filter.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 840502bd62..d2fd26af7e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -2325,7 +2325,6 @@ static int fg_output_step(OutputFilterPriv *ofp, 
FilterGraphThread *fgt,
   AVFrame *frame)
 {
 FilterGraphPriv*fgp = fgp_from_fg(ofp->ofilter.graph);
-OutputStream   *ost = ofp->ofilter.ost;
 AVFilterContext *filter = ofp->filter;
 FrameData *fd;
 int ret;
@@ -2379,7 +2378,7 @@ static int fg_output_step(OutputFilterPriv *ofp, 
FilterGraphThread *fgt,
 if (!fgp->is_meta)
 fd->bits_per_raw_sample = 0;
 
-if (ost->type == AVMEDIA_TYPE_VIDEO) {
+if (ofp->ofilter.type == AVMEDIA_TYPE_VIDEO) {
 if (!frame->duration) {
 AVRational fr = av_buffersink_get_frame_rate(filter);
 if (fr.num > 0 && fr.den > 0)
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 19/31] fftools/ffmpeg_filter: pass sws/swr opts through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Do not read them from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  |  7 +--
 fftools/ffmpeg_filter.c   | 27 ++-
 fftools/ffmpeg_mux.c  |  3 ---
 fftools/ffmpeg_mux_init.c | 11 ---
 4 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 786f925bc6..c61a670103 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -265,6 +265,8 @@ typedef struct InputFilterOptions {
 
 enum OFilterFlags {
 OFILTER_FLAG_DISABLE_CONVERT= (1 << 0),
+// produce 24-bit audio
+OFILTER_FLAG_AUDIO_24BIT= (1 << 1),
 };
 
 typedef struct OutputFilterOptions {
@@ -283,6 +285,9 @@ typedef struct OutputFilterOptions {
  */
 AVRational  output_tb;
 
+AVDictionary   *sws_opts;
+AVDictionary   *swr_opts;
+
 // A combination of OFilterFlags.
 unsignedflags;
 
@@ -574,8 +579,6 @@ typedef struct OutputStream {
 OutputFilter *filter;
 
 AVDictionary *encoder_opts;
-AVDictionary *sws_dict;
-AVDictionary *swr_opts;
 char *apad;
 
 char *attachment_filename;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index d2fd26af7e..8aa4053716 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -210,6 +210,9 @@ typedef struct OutputFilterPriv {
 
 AVRational  sample_aspect_ratio;
 
+AVDictionary   *sws_opts;
+AVDictionary   *swr_opts;
+
 // those are only set if no format is specified and the encoder gives us 
multiple options
 // They point directly to the relevant lists of the encoder.
 const int  *formats;
@@ -813,6 +816,17 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 if (!ofp->name)
 return AVERROR(EINVAL);
 
+ret = av_dict_copy(>sws_opts, opts->sws_opts, 0);
+if (ret < 0)
+return ret;
+
+ret = av_dict_copy(>swr_opts, opts->swr_opts, 0);
+if (ret < 0)
+return ret;
+
+if (opts->flags & OFILTER_FLAG_AUDIO_24BIT)
+av_dict_set(>swr_opts, "output_sample_bits", "24", 0);
+
 if (fgp->is_simple) {
 // for simple filtergraph there is just one output,
 // so use only graph-level information for logging
@@ -945,6 +959,8 @@ void fg_free(FilterGraph **pfg)
 OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
 
 av_frame_free(>fps.last_frame);
+av_dict_free(>sws_opts);
+av_dict_free(>swr_opts);
 
 av_freep(>linklabel);
 av_freep(>name);
@@ -1358,7 +1374,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 snprintf(args, sizeof(args), "%d:%d",
  ofp->width, ofp->height);
 
-while ((e = av_dict_iterate(ost->sws_dict, e))) {
+while ((e = av_dict_iterate(ofp->sws_opts, e))) {
 av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
 }
 
@@ -1725,6 +1741,7 @@ static int configure_filtergraph(FilterGraph *fg, 
FilterGraphThread *fgt)
 return AVERROR(ENOMEM);
 
 if (simple) {
+OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[0]);
 OutputStream *ost = fg->outputs[0]->ost;
 
 if (filter_nbthreads) {
@@ -1738,17 +1755,17 @@ static int configure_filtergraph(FilterGraph *fg, 
FilterGraphThread *fgt)
 av_opt_set(fgt->graph, "threads", e->value, 0);
 }
 
-if (av_dict_count(ost->sws_dict)) {
-ret = av_dict_get_string(ost->sws_dict,
+if (av_dict_count(ofp->sws_opts)) {
+ret = av_dict_get_string(ofp->sws_opts,
  >graph->scale_sws_opts,
  '=', ':');
 if (ret < 0)
 goto fail;
 }
 
-if (av_dict_count(ost->swr_opts)) {
+if (av_dict_count(ofp->swr_opts)) {
 char *args;
-ret = av_dict_get_string(ost->swr_opts, , '=', ':');
+ret = av_dict_get_string(ofp->swr_opts, , '=', ':');
 if (ret < 0)
 goto fail;
 av_opt_set(fgt->graph, "aresample_swr_opts", args, 0);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 253c2e58d4..557f08b3a5 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -819,9 +819,6 @@ static void ost_free(OutputStream **post)
 
 av_freep(>attachment_filename);
 
-av_dict_free(>sws_dict);
-av_dict_free(>swr_opts);
-
 if (ost->enc_ctx)
 av_freep(>enc_ctx->stats_in);
 avcodec_free_context(>enc_ctx);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 219be5f965..8f4b73f8a7 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1356,12 +1356,6 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)

[FFmpeg-devel] [PATCH 08/31] fftools/ffmpeg: warn about ignored -enc_time_base for subtitles earlier

2024-04-05 Thread Anton Khirnov
Can do it as soon as that option is parsed, no need to postpone it until
opening the encoder.
---
 fftools/ffmpeg_enc.c  | 3 ---
 fftools/ffmpeg_mux_init.c | 6 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index d1d1526830..618ba193ff 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -280,9 +280,6 @@ int enc_open(void *opaque, const AVFrame *frame)
 break;
 }
 case AVMEDIA_TYPE_SUBTITLE:
-if (ost->enc_timebase.num)
-av_log(ost, AV_LOG_WARNING,
-   "-enc_time_base not supported for subtitles, ignoring\n");
 enc_ctx->time_base = AV_TIME_BASE_Q;
 
 if (!enc_ctx->width) {
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index d79ae1f491..8b03d3b108 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1233,8 +1233,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 }
 
 MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
-if (enc_time_base) {
+if (enc_time_base && type == AVMEDIA_TYPE_SUBTITLE)
+av_log(ost, AV_LOG_WARNING,
+   "-enc_time_base not supported for subtitles, ignoring\n");
+else if (enc_time_base) {
 AVRational q;
+
 if (!strcmp(enc_time_base, "demux")) {
 q = (AVRational){ ENC_TIME_BASE_DEMUX, 0 };
 } else if (!strcmp(enc_time_base, "filter")) {
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 09/31] fftools/ffmpeg_filter: pass enc_timebase through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Reduces the need to access OutputStream, which will allow decoupling
filtering from encoding in future commits.
---
 fftools/ffmpeg.h  | 7 +--
 fftools/ffmpeg_filter.c   | 2 +-
 fftools/ffmpeg_mux_init.c | 4 +++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 300ad8a987..56c2fedcc4 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -273,6 +273,11 @@ typedef struct OutputFilterOptions {
 
 int64_t ts_offset;
 
+/* Desired output timebase.
+ * Numerator can be one of EncTimeBase values, or 0 when no preference.
+ */
+AVRational  output_tb;
+
 // A combination of OFilterFlags.
 unsignedflags;
 } OutputFilterOptions;
@@ -529,8 +534,6 @@ typedef struct OutputStream {
 
 AVStream *st;/* stream in the output file */
 
-AVRational enc_timebase;
-
 Encoder *enc;
 AVCodecContext *enc_ctx;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 5f2dbc387e..0b78898af0 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -780,7 +780,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 
 ofp->flags= opts->flags;
 ofp->ts_offset= opts->ts_offset;
-ofp->enc_timebase = ost->enc_timebase;
+ofp->enc_timebase = opts->output_tb;
 
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 8b03d3b108..28090423c6 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1042,6 +1042,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 const AVCodec *enc;
 AVStream *st;
 int ret = 0, keep_pix_fmt = 0;
+AVRational enc_tb = { 0, 0 };
 const char *bsfs = NULL, *time_base = NULL;
 char *filters = NULL, *next, *codec_tag = NULL;
 double qscale = -1;
@@ -1260,7 +1261,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 #endif
 }
 
-ost->enc_timebase = q;
+enc_tb = q;
 }
 } else {
 ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st,
@@ -1377,6 +1378,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
 OutputFilterOptions opts = {
 .enc = enc,
+.output_tb = enc_tb,
 .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
  0 : mux->of.start_time,
 .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt,
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_filter: stop accessing encoder AVCodecContext

2024-04-05 Thread Dennis Mungai
On Fri, 5 Apr 2024, 19:14 Anton Khirnov,  wrote:

> Pass all the necessary value through OutputFilterOptions.
>
> Will allow decoupling filtering from encoding in future commits.
> ---
>  fftools/ffmpeg.h  |  7 +++
>  fftools/ffmpeg_filter.c   | 22 +++---
>  fftools/ffmpeg_mux_init.c |  6 ++
>  3 files changed, 24 insertions(+), 11 deletions(-)
>
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index d0e896dbe7..598ca2fa96 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -282,6 +282,13 @@ typedef struct OutputFilterOptions {
>
>  // A combination of OFilterFlags.
>  unsignedflags;
> +
> +int format;
> +int width;
> +int height;
> +
> +int sample_rate;
> +AVChannelLayout ch_layout;
>  } OutputFilterOptions;
>
>  typedef struct InputFilter {
> diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
> index 5661dc960a..3c25d2ed65 100644
> --- a/fftools/ffmpeg_filter.c
> +++ b/fftools/ffmpeg_filter.c
> @@ -782,12 +782,12 @@ int ofilter_bind_ost(OutputFilter *ofilter,
> OutputStream *ost,
>  ofp->ts_offset= opts->ts_offset;
>  ofp->enc_timebase = opts->output_tb;
>
> -switch (ost->enc_ctx->codec_type) {
> +switch (ofilter->type) {
>  case AVMEDIA_TYPE_VIDEO:
> -ofp->width  = ost->enc_ctx->width;
> -ofp->height = ost->enc_ctx->height;
> -if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
> -ofp->format = ost->enc_ctx->pix_fmt;
> +ofp->width  = opts->width;
> +ofp->height = opts->height;
> +if (opts->format != AV_PIX_FMT_NONE) {
> +ofp->format = opts->format;
>  } else if (opts->pix_fmts)
>  ofp->formats = opts->pix_fmts;
>  else if (opts->enc)
> @@ -812,19 +812,19 @@ int ofilter_bind_ost(OutputFilter *ofilter,
> OutputStream *ost,
>
>  break;
>  case AVMEDIA_TYPE_AUDIO:
> -if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
> -ofp->format = ost->enc_ctx->sample_fmt;
> +if (opts->format != AV_SAMPLE_FMT_NONE) {
> +ofp->format = opts->format;
>  } else if (opts->enc) {
>  ofp->formats = opts->enc->sample_fmts;
>  }
> -if (ost->enc_ctx->sample_rate) {
> -ofp->sample_rate = ost->enc_ctx->sample_rate;
> +if (opts->sample_rate) {
> +ofp->sample_rate = opts->sample_rate;
>  } else if (opts->enc) {
>  ofp->sample_rates = opts->enc->supported_samplerates;
>  }
> -if (ost->enc_ctx->ch_layout.nb_channels) {
> +if (opts->ch_layout.nb_channels) {
>  int ret = set_channel_layout(ofp, opts->enc ?
> opts->enc->ch_layouts : NULL,
> - >enc_ctx->ch_layout);
> + >ch_layout);
>  if (ret < 0)
>  return ret;
>  } else if (opts->enc) {
> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
> index 04642f5c8b..b031cc59d2 100644
> --- a/fftools/ffmpeg_mux_init.c
> +++ b/fftools/ffmpeg_mux_init.c
> @@ -1378,6 +1378,12 @@ static int ost_add(Muxer *mux, const OptionsContext
> *o, enum AVMediaType type,
>  (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
>  OutputFilterOptions opts = {
>  .enc = enc,
> +.format  = (type == AVMEDIA_TYPE_VIDEO) ?
> +   ost->enc_ctx->pix_fmt :
> ost->enc_ctx->sample_fmt,
> +.width   = ost->enc_ctx->width,
> +.height  = ost->enc_ctx->height,
> +.sample_rate = ost->enc_ctx->sample_rate,
> +.ch_layout   = ost->enc_ctx->ch_layout,
>  .output_tb = enc_tb,
>  .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
>   0 : mux->of.start_time,
> --
> 2.43.0
>


Does this imply that down the line, with this and additional patchsets,
that FFmpeg can handle tasks such as stream copy and filtering in the same
invocation?

>
___
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 07/31] fftools/ffmpeg_filter: pass keep_pix_fmt through OutputFilterOptions

2024-04-05 Thread Anton Khirnov
Reduces the need to access OutputStream, which will allow decoupling
filtering from encoding in future commits.
---
 fftools/ffmpeg.h  | 9 +++--
 fftools/ffmpeg_filter.c   | 8 +---
 fftools/ffmpeg_mux_init.c | 9 +
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7288a48aa1..300ad8a987 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -263,11 +263,18 @@ typedef struct InputFilterOptions {
 AVFrame*fallback;
 } InputFilterOptions;
 
+enum OFilterFlags {
+OFILTER_FLAG_DISABLE_CONVERT= (1 << 0),
+};
+
 typedef struct OutputFilterOptions {
 // Codec used for encoding, may be NULL
 const AVCodec  *enc;
 
 int64_t ts_offset;
+
+// A combination of OFilterFlags.
+unsignedflags;
 } OutputFilterOptions;
 
 typedef struct InputFilter {
@@ -556,8 +563,6 @@ typedef struct OutputStream {
 
 char *attachment_filename;
 
-int keep_pix_fmt;
-
 /* stats */
 // number of packets send to the muxer
 atomic_uint_least64_t packets_written;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 8b05262622..5f2dbc387e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -214,6 +214,8 @@ typedef struct OutputFilterPriv {
 int64_t ts_offset;
 int64_t next_pts;
 FPSConvContext  fps;
+
+unsignedflags;
 } OutputFilterPriv;
 
 static OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter)
@@ -355,11 +357,10 @@ static int choose_pix_fmts(OutputFilter *ofilter, 
AVBPrint *bprint,
const char **dst)
 {
 OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
-OutputStream *ost = ofilter->ost;
 
 *dst = NULL;
 
-if (ost->keep_pix_fmt || ofp->format != AV_PIX_FMT_NONE) {
+if (ofp->flags & OFILTER_FLAG_DISABLE_CONVERT || ofp->format != 
AV_PIX_FMT_NONE) {
 *dst = ofp->format == AV_PIX_FMT_NONE ? NULL :
av_get_pix_fmt_name(ofp->format);
 } else if (ofp->formats) {
@@ -777,6 +778,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofilter->ost = ost;
 av_freep(>linklabel);
 
+ofp->flags= opts->flags;
 ofp->ts_offset= opts->ts_offset;
 ofp->enc_timebase = ost->enc_timebase;
 
@@ -814,7 +816,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 }
 }
 
-fgp->disable_conversions |= ost->keep_pix_fmt;
+fgp->disable_conversions |= !!(ofp->flags & 
OFILTER_FLAG_DISABLE_CONVERT);
 
 ofp->fps.last_frame = av_frame_alloc();
 if (!ofp->fps.last_frame)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 83eab4276e..d79ae1f491 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -580,7 +580,7 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, 
const char *name)
 }
 
 static int new_stream_video(Muxer *mux, const OptionsContext *o,
-OutputStream *ost)
+OutputStream *ost, int *keep_pix_fmt)
 {
 AVFormatContext *oc = mux->fc;
 AVStream *st;
@@ -638,7 +638,7 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
 
 MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
 if (frame_pix_fmt && *frame_pix_fmt == '+') {
-ost->keep_pix_fmt = 1;
+*keep_pix_fmt = 1;
 if (!*++frame_pix_fmt)
 frame_pix_fmt = NULL;
 }
@@ -1041,7 +1041,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 OutputStream *ost;
 const AVCodec *enc;
 AVStream *st;
-int ret = 0;
+int ret = 0, keep_pix_fmt = 0;
 const char *bsfs = NULL, *time_base = NULL;
 char *filters = NULL, *next, *codec_tag = NULL;
 double qscale = -1;
@@ -1356,7 +1356,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
  ms->copy_initial_nonkeyframes, oc, st);
 
 switch (type) {
-case AVMEDIA_TYPE_VIDEO:  ret = new_stream_video (mux, o, ost); 
break;
+case AVMEDIA_TYPE_VIDEO:  ret = new_stream_video (mux, o, ost, 
_pix_fmt); break;
 case AVMEDIA_TYPE_AUDIO:  ret = new_stream_audio (mux, o, ost); 
break;
 case AVMEDIA_TYPE_SUBTITLE:   ret = new_stream_subtitle  (mux, o, ost); 
break;
 }
@@ -1375,6 +1375,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 .enc = enc,
 .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
  0 : mux->of.start_time,
+.flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt,
 };
 
 if (ofilter) {
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org

[FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_filter: stop accessing encoder AVCodecContext

2024-04-05 Thread Anton Khirnov
Pass all the necessary value through OutputFilterOptions.

Will allow decoupling filtering from encoding in future commits.
---
 fftools/ffmpeg.h  |  7 +++
 fftools/ffmpeg_filter.c   | 22 +++---
 fftools/ffmpeg_mux_init.c |  6 ++
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d0e896dbe7..598ca2fa96 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -282,6 +282,13 @@ typedef struct OutputFilterOptions {
 
 // A combination of OFilterFlags.
 unsignedflags;
+
+int format;
+int width;
+int height;
+
+int sample_rate;
+AVChannelLayout ch_layout;
 } OutputFilterOptions;
 
 typedef struct InputFilter {
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 5661dc960a..3c25d2ed65 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -782,12 +782,12 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofp->ts_offset= opts->ts_offset;
 ofp->enc_timebase = opts->output_tb;
 
-switch (ost->enc_ctx->codec_type) {
+switch (ofilter->type) {
 case AVMEDIA_TYPE_VIDEO:
-ofp->width  = ost->enc_ctx->width;
-ofp->height = ost->enc_ctx->height;
-if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
-ofp->format = ost->enc_ctx->pix_fmt;
+ofp->width  = opts->width;
+ofp->height = opts->height;
+if (opts->format != AV_PIX_FMT_NONE) {
+ofp->format = opts->format;
 } else if (opts->pix_fmts)
 ofp->formats = opts->pix_fmts;
 else if (opts->enc)
@@ -812,19 +812,19 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 
 break;
 case AVMEDIA_TYPE_AUDIO:
-if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
-ofp->format = ost->enc_ctx->sample_fmt;
+if (opts->format != AV_SAMPLE_FMT_NONE) {
+ofp->format = opts->format;
 } else if (opts->enc) {
 ofp->formats = opts->enc->sample_fmts;
 }
-if (ost->enc_ctx->sample_rate) {
-ofp->sample_rate = ost->enc_ctx->sample_rate;
+if (opts->sample_rate) {
+ofp->sample_rate = opts->sample_rate;
 } else if (opts->enc) {
 ofp->sample_rates = opts->enc->supported_samplerates;
 }
-if (ost->enc_ctx->ch_layout.nb_channels) {
+if (opts->ch_layout.nb_channels) {
 int ret = set_channel_layout(ofp, opts->enc ? 
opts->enc->ch_layouts : NULL,
- >enc_ctx->ch_layout);
+ >ch_layout);
 if (ret < 0)
 return ret;
 } else if (opts->enc) {
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 04642f5c8b..b031cc59d2 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1378,6 +1378,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
 OutputFilterOptions opts = {
 .enc = enc,
+.format  = (type == AVMEDIA_TYPE_VIDEO) ?
+   ost->enc_ctx->pix_fmt : ost->enc_ctx->sample_fmt,
+.width   = ost->enc_ctx->width,
+.height  = ost->enc_ctx->height,
+.sample_rate = ost->enc_ctx->sample_rate,
+.ch_layout   = ost->enc_ctx->ch_layout,
 .output_tb = enc_tb,
 .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
  0 : mux->of.start_time,
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 03/31] fftools/ffmpeg_filter: do not pass OutputStream to set_channel_layout()

2024-04-05 Thread Anton Khirnov
It only needs a list of allowed layouts and the requested layout.
---
 fftools/ffmpeg_filter.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 2308abf82a..ba6c6c7673 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -722,42 +722,42 @@ static int ifilter_bind_dec(InputFilterPriv *ifp, Decoder 
*dec)
 return 0;
 }
 
-static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
+static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout 
*layouts_allowed,
+  const AVChannelLayout *layout_requested)
 {
-const AVCodec *c = ost->enc_ctx->codec;
 int i, err;
 
-if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
+if (layout_requested->order != AV_CHANNEL_ORDER_UNSPEC) {
 /* Pass the layout through for all orders but UNSPEC */
-err = av_channel_layout_copy(>ch_layout, >enc_ctx->ch_layout);
+err = av_channel_layout_copy(>ch_layout, layout_requested);
 if (err < 0)
 return err;
 return 0;
 }
 
 /* Requested layout is of order UNSPEC */
-if (!c->ch_layouts) {
+if (!layouts_allowed) {
 /* Use the default native layout for the requested amount of channels 
when the
encoder doesn't have a list of supported layouts */
-av_channel_layout_default(>ch_layout, 
ost->enc_ctx->ch_layout.nb_channels);
+av_channel_layout_default(>ch_layout, 
layout_requested->nb_channels);
 return 0;
 }
 /* Encoder has a list of supported layouts. Pick the first layout in it 
with the
same amount of channels as the requested layout */
-for (i = 0; c->ch_layouts[i].nb_channels; i++) {
-if (c->ch_layouts[i].nb_channels == 
ost->enc_ctx->ch_layout.nb_channels)
+for (i = 0; layouts_allowed[i].nb_channels; i++) {
+if (layouts_allowed[i].nb_channels == layout_requested->nb_channels)
 break;
 }
-if (c->ch_layouts[i].nb_channels) {
+if (layouts_allowed[i].nb_channels) {
 /* Use it if one is found */
-err = av_channel_layout_copy(>ch_layout, >ch_layouts[i]);
+err = av_channel_layout_copy(>ch_layout, _allowed[i]);
 if (err < 0)
 return err;
 return 0;
 }
 /* If no layout for the amount of channels requested was found, use the 
default
native layout for it. */
-av_channel_layout_default(>ch_layout, 
ost->enc_ctx->ch_layout.nb_channels);
+av_channel_layout_default(>ch_layout, layout_requested->nb_channels);
 
 return 0;
 }
@@ -844,7 +844,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 ofp->sample_rates = c->supported_samplerates;
 }
 if (ost->enc_ctx->ch_layout.nb_channels) {
-int ret = set_channel_layout(ofp, ost);
+int ret = set_channel_layout(ofp, c->ch_layouts, 
>enc_ctx->ch_layout);
 if (ret < 0)
 return ret;
 } else if (c->ch_layouts) {
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 05/31] fftools/ffmpeg_filter: check that filter type matches output stream type

2024-04-05 Thread Anton Khirnov
For simple filtergraphs. For complex filtergraphs they always match.
---
 fftools/ffmpeg_filter.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 0d359303f7..a59c61b312 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -773,6 +773,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 int ret;
 
 av_assert0(!ofilter->ost);
+av_assert0(ofilter->type == ost->type);
 
 ofilter->ost = ost;
 av_freep(>linklabel);
@@ -1106,6 +1107,13 @@ int init_simple_filtergraph(InputStream *ist, 
OutputStream *ost,
graph_desc, fg->nb_inputs, fg->nb_outputs);
 return AVERROR(EINVAL);
 }
+if (fg->outputs[0]->type != ost->type) {
+av_log(fg, AV_LOG_ERROR, "Filtergraph has a %s output, cannot connect "
+   "it to %s output stream\n",
+   av_get_media_type_string(fg->outputs[0]->type),
+   av_get_media_type_string(ost->type));
+return AVERROR(EINVAL);
+}
 
 ost->filter = fg->outputs[0];
 
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 02/31] lavfi/avfilter: add an "auto" constant to the threads option

2024-04-05 Thread Anton Khirnov
Analogous to the same constant in avfiltergraph and avcodec.
Cf. f599ae88c25.
---
 libavfilter/avfilter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7f94e71fbc..049e4f62ca 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -652,7 +652,8 @@ static const AVOption avfilter_options[] = {
 { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE 
}, .flags = FLAGS, .unit = "thread_type" },
 { "enable", "set enable expression", OFFSET(enable_str), 
AV_OPT_TYPE_STRING, {.str=NULL}, .flags = TFLAGS },
 { "threads", "Allowed number of threads", OFFSET(nb_threads), 
AV_OPT_TYPE_INT,
-{ .i64 = 0 }, 0, INT_MAX, FLAGS },
+{ .i64 = 0 }, 0, INT_MAX, FLAGS, .unit = "threads" },
+{"auto", "autodetect a suitable number of threads to use", 0, 
AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = FLAGS, .unit = "threads"},
 { "extra_hw_frames", "Number of extra hardware frames to allocate for the 
user",
 OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
FLAGS },
 { NULL },
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 01/31] lavfi/vf_scale: fix AVOption flags for "size"/"s"

2024-04-05 Thread Anton Khirnov
---
 libavfilter/vf_scale.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index fc0e3802db..1c07daeddf 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -998,8 +998,8 @@ static const AVOption scale_options[] = {
 { "height","Output video height", OFFSET(h_expr),
AV_OPT_TYPE_STRING,.flags = TFLAGS },
 { "flags", "Flags to pass to libswscale", OFFSET(flags_str), 
AV_OPT_TYPE_STRING, { .str = "" }, .flags = FLAGS },
 { "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_BOOL, {.i64 
= 0 }, -1, 1, FLAGS },
-{ "size",   "set video size",  OFFSET(size_str), 
AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
-{ "s",  "set video size",  OFFSET(size_str), 
AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
+{ "size",   "set video size",  OFFSET(size_str), 
AV_OPT_TYPE_STRING, {.str = NULL}, 0, .flags = FLAGS },
+{ "s",  "set video size",  OFFSET(size_str), 
AV_OPT_TYPE_STRING, {.str = NULL}, 0, .flags = FLAGS },
 {  "in_color_matrix", "set input YCbCr type",   OFFSET(in_color_matrix),  
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AVCOL_SPC_NB-1, .flags = FLAGS, .unit = 
"color" },
 { "out_color_matrix", "set output YCbCr type",  OFFSET(out_color_matrix), 
AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, AVCOL_SPC_NB-1, .flags = 
FLAGS, .unit = "color"},
 { "auto",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 },
 0, 0, FLAGS, .unit = "color" },
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 30/31] fftools/ffmpeg_filter: implement filtergraph chaining

2024-04-05 Thread Anton Khirnov
This allows one complex filtergraph's output to be sent as input to
another one, which is useful in certain situations (one is described in
the docs).

Chaining filtergraphs was already effectively possible by using a
wrapped_avframe encoder connected to a loopback decoder, but it is ugly,
non-obvious and inefficient.
---
 Changelog   |  1 +
 doc/ffmpeg.texi | 58 ---
 fftools/ffmpeg_filter.c | 89 +++--
 3 files changed, 140 insertions(+), 8 deletions(-)

diff --git a/Changelog b/Changelog
index 18e83b99a1..b7a1af4083 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
 version :
 - Raw Captions with Time (RCWT) closed caption demuxer
 - LC3/LC3plus decoding/encoding using external library liblc3
+- ffmpeg CLI filtergraph chaining
 
 
 version 7.0:
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 801c083705..9bd548ce4e 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -2145,14 +2145,62 @@ type -- see the @option{-filter} options. 
@var{filtergraph} is a description of
 the filtergraph, as described in the ``Filtergraph syntax'' section of the
 ffmpeg-filters manual.
 
-Input link labels must refer to either input streams or loopback decoders. For
-input streams, use the @code{[file_index:stream_specifier]} syntax (i.e. the
-same as @option{-map} uses). If @var{stream_specifier} matches multiple 
streams,
-the first one will be used.
+Inputs to a complex filtergraph may come from different source types,
+distinguished by the format of the corresponding link label:
+@itemize
+@item
+To connect an input stream, use @code{[file_index:stream_specifier]} (i.e. the
+same syntax as @option{-map}). If @var{stream_specifier} matches multiple
+streams, the first one will be used.
 
-For decoders, the link label must be [dec:@var{dec_idx}], where @var{dec_idx} 
is
+@item
+To connect a loopback decoder use [dec:@var{dec_idx}], where @var{dec_idx} is
 the index of the loopback decoder to be connected to given input.
 
+@item
+To connect an output from another complex filtergraph, use its link label. E.g
+the following example:
+
+@example
+ffmpeg -i input.mkv \
+  -filter_complex 
'[0:v]scale=size=hd1080,split=outputs=2[for_enc][orig_scaled]' \
+  -c:v libx264 -map '[for_enc]' output.mkv \
+  -dec 0:0 \
+  -filter_complex '[dec:0][orig_scaled]hstack[stacked]' \
+  -map '[stacked]' -c:v ffv1 comparison.mkv
+@end example
+
+reads an input video and
+@itemize
+@item
+(line 2) uses a complex filtergraph with one input and two outputs
+to scale the video to 1920x1080 and duplicate the result to both
+outputs;
+
+@item
+(line 3) encodes one scaled output with @code{libx264} and writes the result to
+@file{output.mkv};
+
+@item
+(line 4) decodes this encoded stream with a loopback decoder;
+
+@item
+(line 5) places the output of the loopback decoder (i.e. the
+@code{libx264}-encoded video) side by side with the scaled original input;
+
+@item
+(line 6) combined video is then losslessly encoded and written into
+@file{comparison.mkv}.
+
+@end itemize
+
+Note that the two filtergraphs cannot be combined into one, because then there
+would be a cycle in the transcoding pipeline (filtergraph output goes to
+encoding, from there to decoding, then back to the same graph), and such cycles
+are not allowed.
+
+@end itemize
+
 An unlabeled input will be connected to the first unused input stream of the
 matching type.
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 1e14962f41..f108f8daf9 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -902,6 +902,63 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 return 0;
 }
 
+static int ofilter_bind_ifilter(OutputFilter *ofilter, InputFilterPriv *ifp,
+const OutputFilterOptions *opts)
+{
+OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
+
+av_assert0(!ofilter->bound);
+av_assert0(ofilter->type == ifp->type);
+
+ofilter->bound = 1;
+av_freep(>linklabel);
+
+ofp->name = av_strdup(opts->name);
+if (!ofp->name)
+return AVERROR(EINVAL);
+
+av_strlcatf(ofp->log_name, sizeof(ofp->log_name), "->%s", ofp->name);
+
+return 0;
+}
+
+static int ifilter_bind_fg(InputFilterPriv *ifp, FilterGraph *fg_src, int 
out_idx)
+{
+FilterGraphPriv  *fgp = fgp_from_fg(ifp->ifilter.graph);
+OutputFilter *ofilter_src = fg_src->outputs[out_idx];
+OutputFilterOptions opts;
+char name[32];
+int ret;
+
+av_assert0(!ifp->bound);
+ifp->bound = 1;
+
+if (ifp->type != ofilter_src->type) {
+av_log(fgp, AV_LOG_ERROR, "Tried to connect %s output to %s input\n",
+   av_get_media_type_string(ofilter_src->type),
+   av_get_media_type_string(ifp->type));
+return AVERROR(EINVAL);
+}
+
+ifp->type_src = ifp->type;
+
+memset(, 0, sizeof(opts));
+
+snprintf(name, sizeof(name), 

Re: [FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_filter: stop accessing encoder AVCodecContext

2024-04-05 Thread Gyan Doshi




On 2024-04-05 10:20 pm, Dennis Mungai wrote:


Does this imply that down the line, with this and additional patchsets,
that FFmpeg can handle tasks such as stream copy and filtering in the same
invocation?


What do you mean? If you map a stream twice, you already can do that now.

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] [PATCH] avcodec/libaomenc: bump the minimum required version to 2.0.0

2024-04-05 Thread Anton Khirnov
Quoting James Almer (2024-04-05 19:16:21)
> v2.0.0 is already four years old and available on stable distro releases.
> With this we stop setting codec capabilities during static data 
> initialization.

Sounds reasonable to me.

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

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


[FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_mux_init: switch to avcodec_get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

---
 fftools/ffmpeg_mux_init.c | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index d3d7d022ff6..508c4f7a697 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -511,13 +511,19 @@ static int fmt_in_list(const int *formats, int format)
 }
 
 static enum AVPixelFormat
-choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
+choose_pixel_fmt(const AVCodecContext *avctx, enum AVPixelFormat target)
 {
-const enum AVPixelFormat *p = codec->pix_fmts;
+const enum AVPixelFormat *p;
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
 //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel 
format without alpha is implemented
 int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
 enum AVPixelFormat best= AV_PIX_FMT_NONE;
+int ret;
+
+ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT,
+   0, (const void **) );
+if (ret < 0)
+return AV_PIX_FMT_NONE;
 
 for (; *p != AV_PIX_FMT_NONE; p++) {
 best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
@@ -529,7 +535,7 @@ choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat 
target)
 av_log(NULL, AV_LOG_WARNING,
"Incompatible pixel format '%s' for codec '%s', 
auto-selecting format '%s'\n",
av_get_pix_fmt_name(target),
-   codec->name,
+   avctx->codec->name,
av_get_pix_fmt_name(best));
 return best;
 }
@@ -538,8 +544,9 @@ choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat 
target)
 
 static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
 {
-const enum AVPixelFormat *fmts = ost->enc_ctx->codec->pix_fmts;
+const enum AVPixelFormat *fmts;// = ost->enc_ctx->codec->pix_fmts;
 enum AVPixelFormat fmt;
+int ret;
 
 fmt = av_get_pix_fmt(name);
 if (fmt == AV_PIX_FMT_NONE) {
@@ -547,6 +554,11 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, 
const char *name)
 return AV_PIX_FMT_NONE;
 }
 
+ret = avcodec_get_supported_config(ost->enc_ctx, NULL, 
AV_CODEC_CONFIG_PIX_FORMAT,
+   0, (const void **) fmts);
+if (ret < 0)
+return AV_PIX_FMT_NONE;
+
 /* when the user specified-format is an alias for an endianness-specific
  * one (e.g. rgb48 -> rgb48be/le), it gets translated into the native
  * endianness by av_get_pix_fmt();
@@ -574,7 +586,7 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, 
const char *name)
 }
 
 if (fmts && !fmt_in_list(fmts, fmt))
-fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt);
+fmt = choose_pixel_fmt(ost->enc_ctx, fmt);
 
 return fmt;
 }
-- 
2.44.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 11/11] fftools/ffmpeg_filter: switch to avcodec_get_supported_config()

2024-04-05 Thread Niklas Haas
From: Niklas Haas 

I preserved the no-op condition on `!ch_layouts`, even though I suspect
it's not actually needed.
---
 fftools/ffmpeg_filter.c | 59 -
 1 file changed, 46 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ac04841a16c..e617b9da289 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -724,7 +724,7 @@ static int ifilter_bind_dec(InputFilterPriv *ifp, Decoder 
*dec)
 
 static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
 {
-const AVCodec *c = ost->enc_ctx->codec;
+const AVChannelLayout *ch_layouts;
 int i, err;
 
 if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
@@ -735,8 +735,14 @@ static int set_channel_layout(OutputFilterPriv *f, 
OutputStream *ost)
 return 0;
 }
 
+err = avcodec_get_supported_config(ost->enc_ctx, NULL,
+   AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
+   (const void **) _layouts);
+if (err < 0)
+return err;
+
 /* Requested layout is of order UNSPEC */
-if (!c->ch_layouts) {
+if (!ch_layouts) {
 /* Use the default native layout for the requested amount of channels 
when the
encoder doesn't have a list of supported layouts */
 av_channel_layout_default(>ch_layout, 
ost->enc_ctx->ch_layout.nb_channels);
@@ -744,13 +750,13 @@ static int set_channel_layout(OutputFilterPriv *f, 
OutputStream *ost)
 }
 /* Encoder has a list of supported layouts. Pick the first layout in it 
with the
same amount of channels as the requested layout */
-for (i = 0; c->ch_layouts[i].nb_channels; i++) {
-if (c->ch_layouts[i].nb_channels == 
ost->enc_ctx->ch_layout.nb_channels)
+for (i = 0; ch_layouts[i].nb_channels; i++) {
+if (ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels)
 break;
 }
-if (c->ch_layouts[i].nb_channels) {
+if (ch_layouts[i].nb_channels) {
 /* Use it if one is found */
-err = av_channel_layout_copy(>ch_layout, >ch_layouts[i]);
+err = av_channel_layout_copy(>ch_layout, _layouts[i]);
 if (err < 0)
 return err;
 return 0;
@@ -787,7 +793,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
 ofp->format = ost->enc_ctx->pix_fmt;
 } else {
-ofp->formats = c->pix_fmts;
+ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+   AV_CODEC_CONFIG_PIX_FORMAT, 0,
+   (const void **) >formats);
+if (ret < 0)
+return ret;
 
 // MJPEG encoder exports a full list of supported pixel formats,
 // but the full-range ones are experimental-only.
@@ -822,8 +832,16 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 
 ofp->fps.framerate   = ost->frame_rate;
 ofp->fps.framerate_max   = ost->max_frame_rate;
-ofp->fps.framerate_supported = ost->force_fps ?
-   NULL : c->supported_framerates;
+
+if (ost->force_fps) {
+ofp->fps.framerate_supported = NULL;
+} else {
+ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+   AV_CODEC_CONFIG_FRAME_RATE, 0,
+   (const void **) 
>fps.framerate_supported);
+if (ret < 0)
+return ret;
+}
 
 // reduce frame rate for mpeg4 to be within the spec limits
 if (c->id == AV_CODEC_ID_MPEG4)
@@ -836,19 +854,34 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost,
 if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
 ofp->format = ost->enc_ctx->sample_fmt;
 } else {
-ofp->formats = c->sample_fmts;
+ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+   AV_CODEC_CONFIG_SAMPLE_FORMAT, 
0,
+   (const void **) >formats);
+if (ret < 0)
+return ret;
 }
 if (ost->enc_ctx->sample_rate) {
 ofp->sample_rate = ost->enc_ctx->sample_rate;
 } else {
-ofp->sample_rates = c->supported_samplerates;
+ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+   AV_CODEC_CONFIG_SAMPLE_RATE, 0,
+   (const void **) 
>sample_rates);
+if (ret < 0)
+return ret;
 }
 if (ost->enc_ctx->ch_layout.nb_channels) {
 int ret = set_channel_layout(ofp, ost);
 if (ret < 0)
 

Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()

2024-04-05 Thread Niklas Haas
On Fri, 05 Apr 2024 20:57:11 +0200 Niklas Haas  wrote:
> From: Niklas Haas 
> In addition to the already covered lists, add two new entries for color
> space and color range, mirroring the newly added negotiable fields in
> libavfilter.

If this passes review, I will submit a second series implementing these
new fields for relevant codecs.
___
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/6] avcodec/huffyuvdec: Don't zero unnecessarily

2024-04-05 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> A decoder's private data has already been zeroed (apart from options)
> before init is called.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/huffyuvdec.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
> index 3bed27be21..29e5419d91 100644
> --- a/libavcodec/huffyuvdec.c
> +++ b/libavcodec/huffyuvdec.c
> @@ -346,7 +346,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
>  ff_bswapdsp_init(>bdsp);
>  ff_huffyuvdsp_init(>hdsp, avctx->pix_fmt);
>  ff_llviddsp_init(>llviddsp);
> -memset(s->vlc, 0, 4 * sizeof(VLC));
>  
>  s->interlaced = avctx->height > 288;
>  s->bgr32  = 1;

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/dv: Don't pretend initializing work chunks can fail

2024-04-05 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/dv.c  | 4 +---
>  libavcodec/dv_internal.h | 2 +-
>  libavcodec/dvdec.c   | 6 +-
>  libavcodec/dvenc.c   | 6 +-
>  4 files changed, 4 insertions(+), 14 deletions(-)
> 
> diff --git a/libavcodec/dv.c b/libavcodec/dv.c
> index eb49978ad8..194d982562 100644
> --- a/libavcodec/dv.c
> +++ b/libavcodec/dv.c
> @@ -166,7 +166,7 @@ static inline void dv_calc_mb_coordinates(const 
> AVDVProfile *d, int chan,
>  }
>  }
>  
> -int ff_dv_init_dynamic_tables(DVwork_chunk *work_chunks, const AVDVProfile 
> *d)
> +void ff_dv_init_dynamic_tables(DVwork_chunk *work_chunks, const AVDVProfile 
> *d)
>  {
>  int j, i, c, s, p;
>  
> @@ -185,6 +185,4 @@ int ff_dv_init_dynamic_tables(DVwork_chunk *work_chunks, 
> const AVDVProfile *d)
>  }
>  }
>  }
> -
> -return 0;
>  }
> diff --git a/libavcodec/dv_internal.h b/libavcodec/dv_internal.h
> index 4b4151c88d..05e26a8138 100644
> --- a/libavcodec/dv_internal.h
> +++ b/libavcodec/dv_internal.h
> @@ -32,7 +32,7 @@ typedef struct DVwork_chunk {
>  uint16_t mb_coordinates[5];
>  } DVwork_chunk;
>  
> -int ff_dv_init_dynamic_tables(DVwork_chunk *work_chunks, const AVDVProfile 
> *d);
> +void ff_dv_init_dynamic_tables(DVwork_chunk *work_chunks, const AVDVProfile 
> *d);
>  
>  static inline int dv_work_pool_size(const AVDVProfile *d)
>  {
> diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
> index a06e4807e7..9e8d40187d 100644
> --- a/libavcodec/dvdec.c
> +++ b/libavcodec/dvdec.c
> @@ -637,11 +637,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx, 
> AVFrame *frame,
>  }
>  
>  if (sys != s->sys) {
> -ret = ff_dv_init_dynamic_tables(s->work_chunks, sys);
> -if (ret < 0) {
> -av_log(avctx, AV_LOG_ERROR, "Error initializing the work 
> tables.\n");
> -return ret;
> -}
> +ff_dv_init_dynamic_tables(s->work_chunks, sys);
>  dv_init_weight_tables(s, sys);
>  s->sys = sys;
>  }
> diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
> index ce21247081..3afeedbb87 100644
> --- a/libavcodec/dvenc.c
> +++ b/libavcodec/dvenc.c
> @@ -93,11 +93,7 @@ static av_cold int dvvideo_encode_init(AVCodecContext 
> *avctx)
>  return AVERROR(EINVAL);
>  }
>  
> -ret = ff_dv_init_dynamic_tables(s->work_chunks, s->sys);
> -if (ret < 0) {
> -av_log(avctx, AV_LOG_ERROR, "Error initializing work tables.\n");
> -return ret;
> -}
> +ff_dv_init_dynamic_tables(s->work_chunks, s->sys);
>  
>  memset(,0, sizeof(fdsp));
>  memset(,0, sizeof(mecc));

Will apply 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/libdav1d: Don't cast const away unnecessarily

2024-04-05 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Possible since c89f6ae6899e0f3ffb4f51da1f1776ab16f5b3a0.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/libdav1d.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
> index f022a4ad05..93c77ed9c6 100644
> --- a/libavcodec/libdav1d.c
> +++ b/libavcodec/libdav1d.c
> @@ -385,7 +385,7 @@ static int libdav1d_receive_frame(AVCodecContext *c, 
> AVFrame *frame)
>  {
>  Libdav1dContext *dav1d = c->priv_data;
>  Dav1dPicture pic = { 0 }, *p = 
> -AVPacket *pkt;
> +const AVPacket *pkt;
>  #if FF_DAV1D_VERSION_AT_LEAST(5,1)
>  enum Dav1dEventFlags event_flags = 0;
>  #endif
> @@ -439,7 +439,7 @@ static int libdav1d_receive_frame(AVCodecContext *c, 
> AVFrame *frame)
>INT_MAX);
>  ff_set_sar(c, frame->sample_aspect_ratio);
>  
> -pkt = (AVPacket *)p->m.user_data.data;
> +pkt = (const AVPacket *)p->m.user_data.data;
>  
>  // match timestamps and packet size
>  res = ff_decode_frame_props_from_pkt(c, frame, pkt);

Will apply tonight 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 v1 7/7] lavc/vaapi_dec: Add VVC decoder

2024-04-05 Thread Nuo Mi
>
> > > --- a/libavcodec/vaapi_decode.c
> > > +++ b/libavcodec/vaapi_decode.c
> > > @@ -455,6 +455,9 @@ static const struct {
> > >  MAP(AV1, AV1_MAIN,AV1Profile0),
> > >  MAP(AV1, AV1_HIGH,AV1Profile1),
> > >  #endif
> > > +#if VA_CHECK_VERSION(1, 22, 0)
> > > +MAP(H266,VVC_MAIN_10, VVCMain10),
> > > +#endif
> > >
> > >  #undef MAP
> > >  };
> > > @@ -627,6 +630,10 @@ static int
> > > vaapi_decode_make_config(AVCodecContext *avctx,
> > >  case AV_CODEC_ID_VP8:
> > >  frames->initial_pool_size += 3;
> > >  break;
> > > +case AV_CODEC_ID_H266:
> > > +// Add additional 16 for maximum 16 frames delay in
> > > vvc native decode.
> > > +frames->initial_pool_size += 32;
> >
> > One frame of 8k YUV444, 10 bits, is about 200MB. Thirty-two frames
> > amount to approximately 6GB.Can we dynamically allocate the buffer
> > pool?
>
> It's processing in other thread:
> https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=11316
>
> >
> > The software decoder requires a delay of 16 frames to ensure full
> > utilization of CPUs. In the future, we may consider increasing this
> > to 32 or even 64 frames.
> > However, for hardware decoding, given that all processing occurs on
> > the GPU, we do not require any delay.
>
> The delay can avoid sync hardware task immediately once it is
> submitted, which can avoid hardware switch tasks frequently and drop
> performance. If the number will increase, I'd prefer to set it as an
> option and diff the default value for hardware with software.

Why does VVC require such a large frame pool while other hardware codecs do
not?
What makes VVC so special?"
___
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".