Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avfilter/vf_cropdetect: add ability to change limit/reset at runtime
Date: Wed, 28 Dec 2022 08:51:02 -0300
Message-ID: <d2d915a2-b4a0-357d-b96e-b06530536413@gmail.com> (raw)
In-Reply-To: <d2878f95-1e74-ef3a-aa27-1177923452aa@gmail.com>

On 12/28/2022 8:02 AM, Jeffrey CHAPUIS wrote:
> Updated working patch with ff_filter_process_command and no memory leaks.
> 
> Signed-off-by: Ashyni <jeffrey.c@tuta.io>
> ---
>   doc/filters.texi                           | 13 +++++
>   libavfilter/vf_cropdetect.c                | 15 ++++--
>   tests/ref/fate/filter-metadata-cropdetect  | 60 +++++++++++-----------
>   tests/ref/fate/filter-metadata-cropdetect1 | 14 ++---
>   tests/ref/fate/filter-metadata-cropdetect2 | 14 ++---
>   5 files changed, 67 insertions(+), 49 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 9b866de5a..212d83e7b 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -10552,6 +10552,19 @@ ffmpeg -flags2 +export_mvs -i file.mp4 -vf 
> cropdetect=mode=mvedges,metadata=mode
>   @end example
>   @end itemize
>   +@subsection Commands
> +
> +This filter supports the following commands:
> +@table @option
> +@item limit
> +@item reset, reset_count
> +
> +The command accepts the same syntax of the corresponding option.
> +
> +If the specified expression is not valid, it is kept at its current
> +value.
> +@end table
> +
>   @anchor{cue}
>   @section cue
>   diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
> index 7e985fb27..ec2535387 100644
> --- a/libavfilter/vf_cropdetect.c
> +++ b/libavfilter/vf_cropdetect.c
> @@ -422,12 +422,15 @@ static int filter_frame(AVFilterLink *inlink, 
> AVFrame *frame)
>           SET_META("lavfi.cropdetect.h",  h);
>           SET_META("lavfi.cropdetect.x",  x);
>           SET_META("lavfi.cropdetect.y",  y);
> +        SET_META("lavfi.cropdetect.pts", frame->pts);
> +        SET_META("lavfi.cropdetect.limit", limit);
> +        SET_META("lavfi.cropdetect.reset", s->reset_count);
>            av_log(ctx, AV_LOG_INFO,
> -               "x1:%d x2:%d y1:%d y2:%d w:%d h:%d x:%d y:%d 
> pts:%"PRId64" t:%f crop=%d:%d:%d:%d\n",
> +               "x1:%d x2:%d y1:%d y2:%d w:%d h:%d x:%d y:%d 
> pts:%"PRId64" t:%f limit:%d crop=%d:%d:%d:%d\n",
>                  s->x1, s->x2, s->y1, s->y2, w, h, x, y, frame->pts,
>                  frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * 
> av_q2d(inlink->time_base),
> -               w, h, x, y);
> +               limit, w, h, x, y);
>       }
>        return ff_filter_frame(inlink->dst->outputs[0], frame);
> @@ -435,13 +438,14 @@ static int filter_frame(AVFilterLink *inlink, 
> AVFrame *frame)
>    #define OFFSET(x) offsetof(CropDetectContext, x)
>   #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> +#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | 
> AV_OPT_FLAG_RUNTIME_PARAM
>    static const AVOption cropdetect_options[] = {
> -    { "limit", "Threshold below which the pixel is considered black", 
> OFFSET(limit),       AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, 
> FLAGS },
> +    { "limit", "Threshold below which the pixel is considered black", 
> OFFSET(limit),       AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, 
> TFLAGS },
>       { "round", "Value by which the width/height should be divisible", 
> OFFSET(round),       AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, FLAGS },
> -    { "reset", "Recalculate the crop area after this many frames",    
> OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 },  0, INT_MAX, FLAGS },
> +    { "reset", "Recalculate the crop area after this many frames",    
> OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 },  0, INT_MAX, TFLAGS },
>       { "skip",  "Number of initial frames to skip",                    
> OFFSET(skip),        AV_OPT_TYPE_INT, { .i64 = 2 },  0, INT_MAX, FLAGS },
> -    { "reset_count", "Recalculate the crop area after this many 
> frames",OFFSET(reset_count),AV_OPT_TYPE_INT,{ .i64 = 0 },  0, INT_MAX, 
> FLAGS },
> +    { "reset_count", "Recalculate the crop area after this many 
> frames",OFFSET(reset_count),AV_OPT_TYPE_INT,{ .i64 = 0 },  0, INT_MAX, 
> TFLAGS },
>       { "max_outliers", "Threshold count of outliers",                  
> OFFSET(max_outliers),AV_OPT_TYPE_INT, { .i64 = 0 },  0, INT_MAX, FLAGS },
>       { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, 
> {.i64=MODE_BLACK}, 0, MODE_NB-1, FLAGS, "mode" },
>           { "black",    "detect black pixels surrounding the video",     
> 0, AV_OPT_TYPE_CONST, {.i64=MODE_BLACK},    INT_MIN, INT_MAX, FLAGS, 
> "mode" },
> @@ -481,4 +485,5 @@ const AVFilter ff_vf_cropdetect = {
>       FILTER_OUTPUTS(avfilter_vf_cropdetect_outputs),
>       FILTER_PIXFMTS_ARRAY(pix_fmts),
>       .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | 
> AVFILTER_FLAG_METADATA_ONLY,
> +    .process_command = ff_filter_process_command,

You need a custom function that will keep old values around and realloc 
the buffers for bboxes using the new reset_count value passed as a 
runtime command, but one that will not call config_input() like you did 
the first time as that one does a lot more than what you need.

It should also call init() to reset frame_nb, a value you of course also 
need to preserve for the fallback scenario, and allocate the new buffers 
but only replace them in the filter context if all four allocations 
succeeded, as doing av_realloc() could potentially not let you fallback 
to continue the process with the old values if required.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

  parent reply	other threads:[~2022-12-28 11:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-28 11:02 Jeffrey CHAPUIS
2022-12-28 11:21 ` Marton Balint
2022-12-28 11:51 ` James Almer [this message]
2022-12-28 15:37   ` Jeffrey CHAPUIS
  -- strict thread matches above, loose matches on Subject: below --
2023-01-10 13:15 Jeffrey CHAPUIS
2023-01-10 15:45 ` Paul B Mahol
2023-01-11 11:42   ` Jeffrey Chapuis
2023-01-11 17:46     ` Jeffrey Chapuis
2023-01-12 15:53       ` Jeffrey Chapuis
2023-01-17 11:46         ` Jeffrey Chapuis
2023-01-17 11:52           ` Paul B Mahol
2023-01-17 12:27             ` Jeffrey Chapuis
2023-01-17 12:34               ` Paul B Mahol
2023-01-17 13:31                 ` Jeffrey Chapuis
2023-01-17 13:45                   ` Paul B Mahol
2023-01-17 14:24                     ` Jeffrey Chapuis
2023-01-17 14:29                       ` Paul B Mahol
2023-01-17 15:19                         ` Jeffrey Chapuis
2023-01-17 16:23                           ` Paul B Mahol
2023-01-17 18:00                             ` Jeffrey Chapuis
2023-01-17 18:11                               ` Paul B Mahol
2023-01-17 22:07                                 ` Jeffrey Chapuis
2023-01-19 12:11                                 ` Jeffrey Chapuis
2023-01-19 13:50                                 ` Jeffrey Chapuis
2022-12-27 12:33 Jeffrey CHAPUIS
2022-12-27 11:46 Jeffrey CHAPUIS
2022-12-27 12:34 ` James Almer
2022-12-27 12:57   ` Jeffrey CHAPUIS

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d2d915a2-b4a0-357d-b96e-b06530536413@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git