Opened 15 months ago

Closed 2 weeks ago

Last modified 2 weeks ago

#9404 closed defect (invalid)

Cropdetect sometime returns wrong values

Reported by: rotacak Owned by:
Priority: normal Component: avfilter
Version: unspecified Keywords: cropdetect
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
When I will use cropdetect on specific video then returned values are wrong.

How to reproduce:
ffmpeg.exe -i game.mp4 -vf cropdetect=24:16:0 -c:a copy -f null -

ffmpeg version n4.4-80-gbf87bdd3f6-20210902 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10-win32 (GCC) 20210408
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libvmaf --enable-vulkan --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libglslang --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20210902
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'game.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2021-09-03T13:54:43.000000Z
  Duration: 00:00:18.60, start: 0.000000, bitrate: 1142 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x450 [SAR 1:1 DAR 16:9], 1141 kb/s, 10 fps, 10 tbr, 20k tbn, 20 tbc (default)
    Metadata:
      creation_time   : 2021-09-03T13:54:43.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf58.76.100
  Stream #0:0(eng): Video: wrapped_avframe, yuv420p(progressive), 800x450 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 10 fps, 10 tbn (default)
    Metadata:
      creation_time   : 2021-09-03T13:54:43.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 wrapped_avframe
[Parsed_cropdetect_0 @ 000001a46e76d4c0] x1:145 x2:652 y1:48 y2:374 w:496 h:320 x:152 y:52 pts:4000 t:0.200000 crop=496:320:152:52
[Parsed_cropdetect_0 @ 000001a46e76d4c0] x1:145 x2:652 y1:48 y2:374 w:496 h:320 x:152 y:52 pts:6000 t:0.300000 crop=496:320:152:52
...
[Parsed_cropdetect_0 @ 000001a46e76d4c0] x1:145 x2:652 y1:48 y2:374 w:496 h:320 x:152 y:52 pts:368000 t:18.400000 crop=496:320:152:52
[Parsed_cropdetect_0 @ 000001a46e76d4c0] x1:145 x2:652 y1:48 y2:374 w:496 h:320 x:152 y:52 pts:370000 t:18.500000 crop=496:320:152:52
frame=  186 fps=0.0 q=-0.0 Lsize=N/A time=00:00:18.60 bitrate=N/A speed= 127x
video:97kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Crop value is: 496:320:152:52. Then I will use it to create cropped video:

ffmpeg.exe -r 10 -i game.mp4 -vf crop=496:320:152:52 -c:v libx264 -b:v 400k final.mp4

ffmpeg version n4.4-80-gbf87bdd3f6-20210902 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10-win32 (GCC) 20210408
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libvmaf --enable-vulkan --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libglslang --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20210902
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'game.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2021-09-03T13:54:43.000000Z
  Duration: 00:00:18.60, start: 0.000000, bitrate: 1142 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x450 [SAR 1:1 DAR 16:9], 1141 kb/s, 10 fps, 10 tbr, 20k tbn, 20 tbc (default)
    Metadata:
      creation_time   : 2021-09-03T13:54:43.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 00000146513ae5c0] using SAR=1/1
[libx264 @ 00000146513ae5c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000146513ae5c0] profile High, level 2.1, 4:2:0, 8-bit
[libx264 @ 00000146513ae5c0] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=10 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=abr mbtree=1 bitrate=400 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'final.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf58.76.100
  Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 496x320 [SAR 1:1 DAR 31:20], q=2-31, 400 kb/s, 10 fps, 10240 tbn (default)
    Metadata:
      creation_time   : 2021-09-03T13:54:43.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/400000 buffer size: 0 vbv_delay: N/A
[mp4 @ 00000146512de000] Starting second pass: moving the moov atom to the beginning of the file
frame=  186 fps=0.0 q=-1.0 Lsize=     725kB time=00:00:18.30 bitrate= 324.4kbits/s speed=27.1x
video:722kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.412691%
[libx264 @ 00000146513ae5c0] frame I:1     Avg QP:22.40  size: 33739
[libx264 @ 00000146513ae5c0] frame P:62    Avg QP:20.55  size:  9928
[libx264 @ 00000146513ae5c0] frame B:123   Avg QP:26.42  size:   724
[libx264 @ 00000146513ae5c0] consecutive B-frames:  6.5% 12.9%  9.7% 71.0%
[libx264 @ 00000146513ae5c0] mb I  I16..4:  0.2%  0.3% 99.5%
[libx264 @ 00000146513ae5c0] mb P  I16..4:  0.4%  1.2%  2.0%  P16..4: 45.1%  7.1%  4.9%  0.0%  0.0%    skip:39.4%
[libx264 @ 00000146513ae5c0] mb B  I16..4:  0.0%  0.0%  0.1%  B16..8: 11.8%  1.2%  0.6%  direct: 0.5%  skip:85.7%  L0:40.4% L1:56.2% BI: 3.4%
[libx264 @ 00000146513ae5c0] final ratefactor: 19.62
[libx264 @ 00000146513ae5c0] 8x8 transform intra:22.9% inter:30.4%
[libx264 @ 00000146513ae5c0] direct mvs  spatial:96.7% temporal:3.3%
[libx264 @ 00000146513ae5c0] coded y,uvDC,uvAC intra: 77.8% 45.2% 43.2% inter: 9.5% 13.6% 10.7%
[libx264 @ 00000146513ae5c0] i16 v,h,dc,p: 75% 23%  2%  0%
[libx264 @ 00000146513ae5c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16%  6% 36%  4%  7%  2% 13%  4% 12%
[libx264 @ 00000146513ae5c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 22% 12%  4%  7%  5% 10%  7% 21%
[libx264 @ 00000146513ae5c0] i8c dc,h,v,p: 70% 11% 12%  7%
[libx264 @ 00000146513ae5c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000146513ae5c0] ref P L0: 73.2%  3.7% 11.7%  5.2%  4.2%  1.9%
[libx264 @ 00000146513ae5c0] ref B L0: 77.5% 10.0%  4.3%  8.1%
[libx264 @ 00000146513ae5c0] ref B L1: 97.8%  2.2%
[libx264 @ 00000146513ae5c0] kb/s:317.57

Result:
Final video is cropped also on top inside picture and that should not be.

Example small videos: https://www.mediafire.com/folder/gseavq0vx165x/ffmpeg

Change History (2)

comment:1 by Carl Eugen Hoyos, 2 weeks ago

Component: undeterminedavfilter
Keywords: cropdetect added
Resolution: invalid
Status: newclosed
Version: unspecified

in reply to:  1 comment:2 by rotacak, 2 weeks ago

Replying to Carl Eugen Hoyos:

See https://ffmpeg.org/ffmpeg-filters.html#cropdetect for the round parameter.

But why it will not leave some black borders to be divided by 16 instead of deleting part of the important image?
If I want to cut maximum of black borders but nothing from the image then it is not possible, right?

Note: See TracTickets for help on using tickets.