Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#2014 closed defect (invalid)

Crop and Scale are location sensitive, fails if scale comes before crop

Reported by: ramitbhalla Owned by:
Priority: normal Component: avfilter
Version: unspecified Keywords: crop scale
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

Summary of the bug: If crop comes before scale in the video filters list it fails (when the crop width/height is > scale width/height)

How to reproduce:
DOES NOT WORK:

ffmpeg -async 1 -threads 0 -y -i "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\My Name Is Earl_WMORDT_2012_03_28_15_28_00.ts" -ss 3 -vf yadif=0:-1,hqdn3d,scale=720:trunc(720/dar/2)*2,crop=1920:1072:0:4 -vcodec libx264 -b 1800000 -subq 6 -x264opts direct=auto:level=4.1:partitions=p8x8,b8x8,i4x4:no-weightb=0:psnr=0:ssim=0:subme=7:ref=3:b-pyramid=none:no-mixed-refs=0:trellis=1:threads=auto -acodec libvo_aacenc -ab 192k -ac 2 "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\My Name Is Earl_WMORDT_2012_03_28_15_28_00.mp4"
--> ffmpeg version N-46726-g2f74f8d Copyright (c) 2000-2012 the FFmpeg developers
-->   built on Nov 13 2012 19:29:51 with gcc 4.7.2 (GCC)
-->   configuration: --enable-gpl --enable-version3 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
-->   libavutil      52.  6.100 / 52.  6.100
-->   libavcodec     54. 71.100 / 54. 71.100
-->   libavformat    54. 36.100 / 54. 36.100
-->   libavdevice    54.  3.100 / 54.  3.100
-->   libavfilter     3. 23.100 /  3. 23.100
-->   libswscale      2.  1.102 /  2.  1.102
-->   libswresample   0. 16.100 /  0. 16.100
-->   libpostproc    52.  1.100 / 52.  1.100
--> [mpegts @ 02e6dca0] max_analyze_duration 5000000 reached at 5024000
--> Input #0, mpegts, from 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\My Name Is Earl_WMORDT_2012_03_28_15_28_00.ts':
-->   Duration: 00:00:31.37, start: 1.400000, bitrate: 11422 kb/s
--> Video duration=31.37
-->   Program 1 
-->     Metadata:
-->       service_name    : WMORDT (WMOR-DT)
-->       service_provider: WMORDT
-->     Stream #0:0[0x100]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, s16, 384 kb/s
-->     Stream #0:1[0x101]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 59.94 tbr, 90k tbn, 59.94 tbc
--> Please use -b:a or -b:v, -b is ambiguous
--> [Parsed_crop_3 @ 02f49c60] Invalid too big or non positive size for width '1920' or height '1072'
--> [Parsed_scale_2 @ 02ebaa80] Failed to configure input pad on Parsed_crop_3
--> Error opening filters!

WORKS:

ffmpeg -async 1 -threads 0 -y -i "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\My Name Is Earl_WMORDT_2012_03_28_15_28_00.ts" -ss 3 -vf yadif=0:-1,hqdn3d,crop=1920:1072:0:4,scale=720:trunc(720/dar/2)*2 -vcodec libx264 -b 1800000 -subq 6 -x264opts direct=auto:level=4.1:partitions=p8x8,b8x8,i4x4:no-weightb=0:psnr=0:ssim=0:subme=7:ref=3:b-pyramid=none:no-mixed-refs=0:trellis=1:threads=auto -acodec libvo_aacenc -ab 192k -ac 2 "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\My Name Is Earl_WMORDT_2012_03_28_15_28_00.mp4"
--> ffmpeg version N-46726-g2f74f8d Copyright (c) 2000-2012 the FFmpeg developers
-->   built on Nov 13 2012 19:29:51 with gcc 4.7.2 (GCC)
-->   configuration: --enable-gpl --enable-version3 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
-->   libavutil      52.  6.100 / 52.  6.100
-->   libavcodec     54. 71.100 / 54. 71.100
-->   libavformat    54. 36.100 / 54. 36.100
-->   libavdevice    54.  3.100 / 54.  3.100
-->   libavfilter     3. 23.100 /  3. 23.100
-->   libswscale      2.  1.102 /  2.  1.102
-->   libswresample   0. 16.100 /  0. 16.100
-->   libpostproc    52.  1.100 / 52.  1.100
--> [mpegts @ 02d5dca0] max_analyze_duration 5000000 reached at 5024000
--> Input #0, mpegts, from 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\My Name Is Earl_WMORDT_2012_03_28_15_28_00.ts':
-->   Duration: 00:00:31.37, start: 1.400000, bitrate: 11422 kb/s
--> Video duration=31.37
-->   Program 1 
-->     Metadata:
-->       service_name    : WMORDT (WMOR-DT)
-->       service_provider: WMORDT
-->     Stream #0:0[0x100]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, s16, 384 kb/s
-->     Stream #0:1[0x101]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 59.94 tbr, 90k tbn, 59.94 tbc
--> Please use -b:a or -b:v, -b is ambiguous
--> -async is forwarded to lavfi similarly to -af aresample=min_comp=0.001:min_hard_comp=0.100000.
--> [libx264 @ 03610700] using SAR=1/1
--> [libx264 @ 03610700] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
--> [libx264 @ 03610700] profile High, level 4.1
--> [libx264 @ 03610700] 264 - core 128 r2216 198a7ea - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x111 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=0 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=1800 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
--> Output #0, mp4, to 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\My Name Is Earl_WMORDT_2012_03_28_15_28_00.mp4':
-->   Metadata:
-->     encoder         : Lavf54.36.100
-->     Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 720x402 [SAR 1:1 DAR 120:67], q=-1--1, 1800 kb/s, 30k tbn, 29.97 tbc
-->     Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, s16, 192 kb/s
--> Stream mapping:
-->   Stream #0:1 -> #0:0 (mpeg2video -> libx264)
-->   Stream #0:0 -> #0:1 (ac3 -> libvo_aacenc)
--> Press [q] to stop, [?] for help
--> frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s    
--> frame=    9 fps=9.0 q=0.0 size=       0kB time=00:00:00.31 bitrate=   1.2kbits/s dup=2 drop=0    
--> frame=   30 fps= 20 q=0.0 size=       0kB time=00:00:01.02 bitrate=   0.4kbits/s dup=6 drop=0    
--> frame=   51 fps= 25 q=26.0 size=      30kB time=00:00:01.72 bitrate= 144.0kbits/s dup=10 drop=0    
--> frame=   71 fps= 28 q=19.0 size=     108kB time=00:00:02.40 bitrate= 366.7kbits/s dup=14 drop=0    
--> frame=   90 fps= 29 q=18.0 size=     256kB time=00:00:03.00 bitrate= 697.7kbits/s dup=18 drop=0    
--> frame=  106 fps= 30 q=18.0 size=     379kB time=00:00:03.55 bitrate= 872.5kbits/s dup=18 drop=0    
--> frame=  122 fps= 30 q=17.0 size=     652kB time=00:00:04.09 bitrate=1305.6kbits/s dup=21 drop=0    
--> frame=  141 fps= 31 q=20.0 size=     770kB time=00:00:04.71 bitrate=1338.8kbits/s dup=25 drop=0    
--> frame=  157 fps= 31 q=20.0 size=     939kB time=00:00:05.28 bitrate=1454.4kbits/s dup=28 drop=0    
--> frame=  176 fps= 31 q=20.0 size=    1059kB time=00:00:05.92 bitrate=1463.9kbits/s dup=32 drop=0    
--> frame=  195 fps= 32 q=20.0 size=    1191kB time=00:00:06.56 bitrate=1486.4kbits/s dup=36 drop=0    
--> frame=  212 fps= 32 q=19.0 size=    1332kB time=00:00:07.10 bitrate=1536.8kbits/s dup=39 drop=0    
--> frame=  229 fps= 32 q=20.0 size=    1523kB time=00:00:07.65 bitrate=1629.8kbits/s dup=43 drop=0    
--> frame=  245 fps= 32 q=21.0 size=    1688kB time=00:00:08.18 bitrate=1689.2kbits/s dup=46 drop=0    
--> frame=  260 fps= 31 q=21.0 size=    1836kB time=00:00:08.70 bitrate=1729.2kbits/s dup=49 drop=0    
--> frame=  275 fps= 31 q=22.0 size=    1993kB time=00:00:09.19 bitrate=1776.8kbits/s dup=52 drop=0    
--> frame=  291 fps= 31 q=22.0 size=    2137kB time=00:00:09.76 bitrate=1792.8kbits/s dup=55 drop=0    
--> frame=  307 fps= 31 q=22.0 size=    2291kB time=00:00:10.27 bitrate=1826.3kbits/s dup=58 drop=0    
--> frame=  324 fps= 31 q=22.0 size=    2441kB time=00:00:10.81 bitrate=1849.5kbits/s dup=62 drop=0    
--> frame=  340 fps= 31 q=22.0 size=    2575kB time=00:00:11.43 bitrate=1845.3kbits/s dup=65 drop=0    
--> frame=  357 fps= 31 q=22.0 size=    2695kB time=00:00:12.00 bitrate=1838.5kbits/s dup=68 drop=0    
--> frame=  375 fps= 31 q=22.0 size=    2803kB time=00:00:12.54 bitrate=1831.1kbits/s dup=72 drop=0    
--> frame=  390 fps= 31 q=22.0 size=    2925kB time=00:00:13.03 bitrate=1839.0kbits/s dup=75 drop=0    
--> frame=  406 fps= 31 q=22.0 size=    3068kB time=00:00:13.56 bitrate=1852.8kbits/s dup=78 drop=0    
--> frame=  422 fps= 31 q=22.0 size=    3193kB time=00:00:14.11 bitrate=1852.8kbits/s dup=81 drop=0    
--> frame=  440 fps= 31 q=22.0 size=    3314kB time=00:00:14.69 bitrate=1847.6kbits/s dup=85 drop=0    
--> frame=  457 fps= 31 q=22.0 size=    3435kB time=00:00:15.29 bitrate=1840.3kbits/s dup=88 drop=0    
--> frame=  474 fps= 32 q=22.0 size=    3541kB time=00:00:15.84 bitrate=1830.8kbits/s dup=92 drop=0    
--> frame=  490 fps= 32 q=21.0 size=    3655kB time=00:00:16.35 bitrate=1830.1kbits/s dup=95 drop=0    
--> frame=  506 fps= 32 q=21.0 size=    3765kB time=00:00:16.93 bitrate=1821.2kbits/s dup=98 drop=0    
--> frame=  521 fps= 31 q=21.0 size=    3868kB time=00:00:17.40 bitrate=1820.5kbits/s dup=101 drop=0    
--> frame=  537 fps= 31 q=21.0 size=    3979kB time=00:00:17.95 bitrate=1814.9kbits/s dup=104 drop=0    
--> frame=  554 fps= 32 q=21.0 size=    4106kB time=00:00:18.49 bitrate=1819.0kbits/s dup=108 drop=0    
--> frame=  572 fps= 32 q=21.0 size=    4247kB time=00:00:19.11 bitrate=1820.6kbits/s dup=111 drop=0    
--> frame=  587 fps= 32 q=21.0 size=    4372kB time=00:00:19.62 bitrate=1825.4kbits/s dup=114 drop=0    
--> frame=  605 fps= 32 q=21.0 size=    4506kB time=00:00:20.26 bitrate=1821.6kbits/s dup=118 drop=0    
--> frame=  624 fps= 32 q=21.0 size=    4625kB time=00:00:20.83 bitrate=1818.1kbits/s dup=122 drop=0    
--> frame=  641 fps= 32 q=21.0 size=    4741kB time=00:00:21.41 bitrate=1813.5kbits/s dup=125 drop=0    
--> frame=  657 fps= 32 q=20.0 size=    4864kB time=00:00:22.01 bitrate=1810.1kbits/s dup=128 drop=0    
--> frame=  674 fps= 32 q=21.0 size=    5056kB time=00:00:22.50 bitrate=1840.5kbits/s dup=132 drop=0    
--> frame=  690 fps= 32 q=21.0 size=    5182kB time=00:00:23.10 bitrate=1837.7kbits/s dup=135 drop=0    
--> frame=  707 fps= 32 q=21.0 size=    5283kB time=00:00:23.61 bitrate=1832.7kbits/s dup=138 drop=0    
--> frame=  726 fps= 32 q=20.0 size=    5380kB time=00:00:24.23 bitrate=1818.8kbits/s dup=142 drop=0    
--> frame=  744 fps= 32 q=20.0 size=    5462kB time=00:00:24.82 bitrate=1802.2kbits/s dup=146 drop=0    
--> frame=  764 fps= 32 q=19.0 size=    5568kB time=00:00:25.46 bitrate=1791.0kbits/s dup=150 drop=0    
--> frame=  781 fps= 32 q=20.0 size=    5729kB time=00:00:26.04 bitrate=1802.0kbits/s dup=153 drop=0    
--> frame=  796 fps= 32 q=20.0 size=    5860kB time=00:00:26.59 bitrate=1804.8kbits/s dup=156 drop=0    
--> frame=  812 fps= 32 q=20.0 size=    5997kB time=00:00:27.11 bitrate=1812.1kbits/s dup=159 drop=0    
--> frame=  826 fps= 32 q=20.0 size=    6104kB time=00:00:27.58 bitrate=1813.0kbits/s dup=162 drop=0    
--> frame=  845 fps= 32 q=20.0 size=    6247kB time=00:00:27.64 bitrate=1851.3kbits/s dup=166 drop=0    
--> frame=  851 fps= 31 q=-1.0 Lsize=    6611kB time=00:00:28.36 bitrate=1909.6kbits/s dup=167 drop=0    
--> video:5932kB audio:650kB subtitle:0 global headers:0kB muxing overhead 0.442103%
--> [libx264 @ 03610700] frame I:6     Avg QP:12.77  size: 54667
--> [libx264 @ 03610700] frame P:391   Avg QP:13.99  size: 11537
--> [libx264 @ 03610700] frame B:454   Avg QP:17.62  size:  2719
--> [libx264 @ 03610700] consecutive B-frames: 18.0% 25.9% 20.4% 35.7%
--> [libx264 @ 03610700] mb I  I16..4:  5.2% 63.7% 31.1%
--> [libx264 @ 03610700] mb P  I16..4:  2.1%  0.0%  4.9%  P16..4: 31.3% 22.2% 15.6%  0.0%  0.0%    skip:23.9%
--> [libx264 @ 03610700] mb B  I16..4:  6.5%  0.0%  1.5%  B16..8: 16.6%  9.5%  1.0%  direct: 8.3%  skip:56.5%  L0:28.3% L1:45.2% BI:26.5%
--> [libx264 @ 03610700] final ratefactor: 14.13
--> [libx264 @ 03610700] 8x8 transform intra:5.5% inter:45.9%
--> [libx264 @ 03610700] direct mvs  spatial:99.1% temporal:0.9%
--> [libx264 @ 03610700] coded y,uvDC,uvAC intra: 51.7% 85.9% 68.1% inter: 25.0% 25.8% 7.2%
--> [libx264 @ 03610700] i16 v,h,dc,p: 21% 43% 27% 10%
--> [libx264 @ 03610700] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 23% 22%  5%  6%  6%  6%  7%  7%
--> [libx264 @ 03610700] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 16% 15%  5%  7%  7%  6%  6%  4%
--> [libx264 @ 03610700] i8c dc,h,v,p: 42% 37% 15%  6%
--> [libx264 @ 03610700] Weighted P-Frames: Y:4.1% UV:1.3%
--> [libx264 @ 03610700] ref P L0: 73.3% 11.2% 10.4%  4.8%  0.3%
--> [libx264 @ 03610700] ref B L0: 88.1% 11.9%
--> [libx264 @ 03610700] kb/s:1711.12

Change History (10)

comment:1 Changed 4 years ago by cehoyos

Do you request that the crop filter does not fail if the crop values are larger than image width/height (but instead keeps the original frame size)? (I don't think this is what you ask for but I absolutely may miss something.)

Or do you request that it should not make a difference if a filter chain contains "crop,scale" or "scale,crop" (with the same parameters). This is how I read your post...

comment:2 follow-up: Changed 4 years ago by ramitbhalla

Both - it should not fail, just keep the scale size if the crop size > scale size.
And it shouldn't make a difference which order the parameters are placed.

comment:3 in reply to: ↑ 2 Changed 4 years ago by Cigaes

Replying to ramitbhalla:

Both - it should not fail, just keep the scale size if the crop size > scale size.

Silently ignoring an invalid parameter is almost never a good behaviour.

And it shouldn't make a difference which order the parameters are placed.

They are not parameters, they are filters, and the order is obviously relevant: removing 100 pixels from 1920 is clearly not the same thing than from 720: on the first it amounts to about 5% of the width, on the second almost 14%.

comment:4 follow-up: Changed 4 years ago by ramitbhalla

I agree, never said silently, throw a warning but don't fail the conversion.

Why would you crop after scaling? cropping is done before scaling to typically remove the black bars. Hence logically it the order shouldn't matter since crop should always happen before scale. the concept of cropping after scaling is baffling, why would you try to calculate post scaling crop?

PArdon my lingo, it's filters and not parameters.

Version 0, edited 4 years ago by ramitbhalla (next)

comment:5 in reply to: ↑ 4 ; follow-up: Changed 4 years ago by Cigaes

Replying to ramitbhalla:

I agree, never said silently, throw a warning but don't fail the conversion.

When something is wrong, a warning is not enough. If you want the conversion to succeed, provide it with correct parameters.

Why would you crop after scaling?

Because the arithmetic may be easier, depending on circumstances.

If you want your cropping to take effect before scaling, put the crop filter before the scale filter.

comment:6 in reply to: ↑ 5 Changed 4 years ago by saste

  • Analyzed by developer set
  • Component changed from undetermined to avfilter
  • Keywords crop scale added
  • Reproduced by developer set
  • Resolution set to invalid
  • Status changed from new to closed

Replying to Cigaes:

Replying to ramitbhalla:

I agree, never said silently, throw a warning but don't fail the conversion.

When something is wrong, a warning is not enough. If you want the conversion to succeed, provide it with correct parameters.

Why would you crop after scaling?

Because the arithmetic may be easier, depending on circumstances.

If you want your cropping to take effect before scaling, put the crop filter before the scale filter.

Filter specification is location-sensitive by design, the user should be aware that most filtering operations are not commutative, and thus should provide a meaningful filterchain.
Pretending "clever" guessworking from a program is a doomed idea.

Issuing a more helpful error message is another issue (which I'm going to fix), but is unrelated to the present ticket subject.

comment:7 follow-up: Changed 4 years ago by ramitbhalla

Okay point 1 taken:

Point 2:
Well "logically" it doesn't make sense to put crop after scaling so again, order should not
matter and definitely should not fail the conversion, you may throw a warning but when the reverse option is not a feasable option it should continue the conversion

comment:8 in reply to: ↑ 7 Changed 4 years ago by Cigaes

Replying to ramitbhalla:

Well "logically" it doesn't make sense to put crop after scaling

Yes it does.

comment:9 Changed 4 years ago by ramitbhalla

Really please explain so how - why would you want to crop after scaling?

comment:10 Changed 4 years ago by reimar

I'd really like to see how you would scale a video by a factor 3 and encode it at 320x240 resolution without cropping after scale.
That is a case that is completely impossible, but in general the border pixels will look different between both orders, and the one with crop first is only correct when croppping borders. When cropping content (e.g. to change aspect) cropping after scale will give more accurate results.

Note: See TracTickets for help on using tickets.