Opened 11 years ago

Closed 9 years ago

#3030 closed enhancement (fixed)

support ratio threshold in cropdetect

Reported by: dave rice Owned by:
Priority: wish Component: avfilter
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the enhancement request:

I'm using the cropdetect filter to crop video but I have some files to has little bits of caption data in an upper line of the video (example attached).

I propose a ratio_threshold option for cropdetect similar to that used in black detect, where the percentage of outlying pixels to trigger the filter could be controlled. In the attached video the output for the first few frames is crop=720:352:0:68 but then the appearance of a few pixels in frame 8 throw off the cropdetect output to crop=720:416:0:6. I propose a ratio-threshold option where a user could say that an adjustable number of should be ignored before adjusting the filter, so that the output could be consistently crop=720:352:0:68.

In this case another means to get that result is to ignore the luma which is what I'm doing at the moment, but that only works with some material.

How to reproduce:

ffmpeg -i cropdetect.mp4 -vf cropdetect -f null -
ffmpeg version 2.0 Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug 27 2013 09:24:56 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libass --enable-ffplay --enable-frei0r --enable-libcaca --enable-libopenjpeg --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1/include/openjpeg-1.5 '
  libavutil      52. 42.100 / 52. 42.100
  libavcodec     55. 29.100 / 55. 29.100
  libavformat    55. 14.102 / 55. 14.102
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 82.102 /  3. 82.102
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  5.100 /  2.  5.100
  libswresample   0. 17.103 /  0. 17.103
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cropdetect.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.14.102
  Duration: 00:00:01.07, start: 0.003979, bitrate: 2012 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x486, 1915 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 81 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.14.102
    Stream #0:0(eng): Video: rawvideo (I420 / 0x30323449), yuv420p, 720x486, q=2-31, 200 kb/s, 90k tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> rawvideo)
  Stream #0:1 -> #0:1 (aac -> pcm_s16le)
Press [q] to stop, [?] for help
[null @ 0x7faeb910c600] Encoder did not produce proper pts, making some up.
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:61 y2:424 w:720 h:352 x:0 y:68 pts:848 t:0.070737 crop=720:352:0:68
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:61 y2:424 w:720 h:352 x:0 y:68 pts:1248 t:0.104104 crop=720:352:0:68
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:61 y2:424 w:720 h:352 x:0 y:68 pts:1648 t:0.137471 crop=720:352:0:68
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:61 y2:424 w:720 h:352 x:0 y:68 pts:2048 t:0.170838 crop=720:352:0:68
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:61 y2:424 w:720 h:352 x:0 y:68 pts:2448 t:0.204204 crop=720:352:0:68
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:61 y2:424 w:720 h:352 x:0 y:68 pts:2848 t:0.237571 crop=720:352:0:68
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:61 y2:424 w:720 h:352 x:0 y:68 pts:3248 t:0.270938 crop=720:352:0:68
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:3648 t:0.304304 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:4048 t:0.337671 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:4448 t:0.371038 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:4848 t:0.404404 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:5248 t:0.437771 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:5648 t:0.471138 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:6048 t:0.504505 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:6448 t:0.537871 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:6848 t:0.571238 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:7248 t:0.604605 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:7648 t:0.637971 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:8048 t:0.671338 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:8448 t:0.704705 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:8848 t:0.738071 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:9248 t:0.771438 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:9648 t:0.804805 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:10048 t:0.838172 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:10448 t:0.871538 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:10848 t:0.904905 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:11248 t:0.938272 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:11648 t:0.971638 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:12048 t:1.005005 crop=720:416:0:6
[Parsed_cropdetect_0 @ 0x7faeb9800000] x1:0 x2:719 y1:1 y2:424 w:720 h:416 x:0 y:6 pts:12448 t:1.038372 crop=720:416:0:6
frame=   32 fps=0.0 q=0.0 Lsize=N/A time=00:00:01.06 bitrate=N/A    
video:3kB audio:192kB subtitle:0 global headers:0kB muxing overhead -100.011018%

Attachments (1)

cropdetect.mp4 (262.4 KB ) - added by dave rice 11 years ago.

Download all attachments as: .zip

Change History (5)

by dave rice, 11 years ago

Attachment: cropdetect.mp4 added

comment:1 by Elon Musk, 11 years ago

Status: newopen

And how do you ignore luma?

comment:2 by dave rice, 11 years ago

I added a lut=y=0 before the cropdetect in the filter chain, but I just realized that didn't work. Perhaps I could do a Y/U or Y/V swap so that cropdetect is looking at the color data instead.

comment:3 by Elon Musk, 11 years ago

What about using extractplanes=u to just use u plane?

comment:4 by Michael Niedermayer, 9 years ago

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.