diff mbox

[FFmpeg-devel,2/3] avfilter/vf_cropdetect: don't ignore frames, export crop parameters

Message ID 20171118003648.33514-3-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Karmani Nov. 18, 2017, 12:36 a.m. UTC
From: Aman Gupta <aman@tmm1.net>

---
 libavfilter/vf_cropdetect.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Nicolas George Nov. 19, 2017, 4:29 p.m. UTC | #1
Le septidi 27 brumaire, an CCXXVI, Aman Gupta a écrit :
> From: Aman Gupta <aman@tmm1.net>
> 
> ---
>  libavfilter/vf_cropdetect.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

I think the changes belong in different commits, since they both change
the behaviour of the filter in different ways.

I cannot comment on the frame_nb change.

Regarding the frame crop change, I am quite doubtful: filters currently
do not handle these fields at all, yet they are copied automatically in
many cases. I am rather against adding an isolated change like that,
unless there is a clear and obvious use case.

Regards,
diff mbox

Patch

diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index 7c7d0b953a..87ecb2a6ec 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -167,8 +167,8 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     int outliers, last_y;
     int limit = lrint(s->limit);
 
-    // ignore first 2 frames - they may be empty
-    if (++s->frame_nb > 0) {
+    if (1) {
+        s->frame_nb++;
         metadata = &frame->metadata;
 
         // Reset the crop area every reset_count frames, if reset_count is > 0
@@ -230,6 +230,11 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         SET_META("lavfi.cropdetect.x",  x);
         SET_META("lavfi.cropdetect.y",  y);
 
+        frame->crop_top = y;
+        frame->crop_left = x;
+        frame->crop_right = frame->width - w - x;
+        frame->crop_bottom = frame->height - h - y;
+
         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",
                s->x1, s->x2, s->y1, s->y2, w, h, x, y, frame->pts,