[FFmpeg-user] Crop, Scale, Pad without distortion

Hans Carlson forbyta at gmx.com
Tue Jan 28 06:25:34 EET 2020


On Mon, 27 Jan 2020, Carl Eugen Hoyos wrote:

> Am Mo., 27. Jan. 2020 um 04:28 Uhr schrieb Hans Carlson <forbyta at gmx.com>:
>>
>> So, based on that, I assumed it would be a good idea to match the aspect
>> ration (720x480) and the DAR.
>
> Does it help if you scale=-1:480 ?

Doesn't seem to... assuming I'm doing it correctly.  Since I want black 
bars on the top and bottom it seems odd (to ME that is) to have the width 
based on the height.  But I did try. Below are several variations using 
scale=-1:480.

I realize I'm most likely not using sar and/or dar correctly.  Either I'm 
not using the filters in the right place or I'm not using the right values 
for sar/dar or I need to use sar/dar in my H/W/x/y calculations.  But 
since I'm not sure what the correct order and/or values should be, I'm 
just throwing darts.

So I tried the following variations and none worked... meaning the video 
still looks compressed or stretched compared to the original:

All tests with setdar at the end are stretched horizontally. All other 
tests are compressed horizontally.

FYI. I used the following calculations for the crop/pad filters:

    original frame size: 720x576, SAR=16:15, DAR=4:3
    cropdetect video size: 704:416:2:82
    desired frame size:  720x480, SAR=?????,  DAR=16:9???

    720/480 = 1.5
    pad/crop: H = 704/1.5 = 469.333 => 470
    pad:      y = (470 - 416) / 2 = 27
    crop:     y = (576 - 470) / 2 = 53

Crop to video size, pad to the PRE-scale height and scale to -1x480:

   crop=704:416:2:82,pad=704:470:0:27,scale=-1:480
   setsar=sar=1/1,crop=704:416:2:82,pad=704:470:0:27,scale=-1:480
   crop=704:416:2:82,pad=704:470:0:27,scale=-1:480,setdar=dar=16/9
   setsar=sar=1/1,crop=704:416:2:82,pad=704:470:0:27,scale=-1:480,setdar=dar=16/9

Crop to PRE-scale height and scale to -1x480

   crop=704:470:2:53,scale=-1:480
   setsar=sar=1/1,crop=704:470:2:53,scale=-1:480
   crop=704:470:2:53,scale=-1:480,setdar=dar=16/9
   setsar=sar=1/1,crop=704:470:2:53,scale=-1:480,setdar=dar=16/9

Crop to PRE-scale height and do NOT scale

   crop=704:470:2:53
   setsar=sar=1/1,crop=704:470:2:53
   crop=704:470:2:53,setdar=dar=16/9
   setsar=sar=1/1,crop=704:470:2:53,setdar=dar=16/9


PS. Just to make sure my TESTING is adequate, here's what I'm doing to 
compare whatever test I'm doing against the original.  Please let me know 
if this is NOT a good way to verify the resulting video.

   1. Start an ffplay window with the original video... skip a bit ahead 
and then pause the video.

      ffplay -i TEMP-original.vob

   2. encode a test video using whatever filter I'm testing:

      ffmpeg -i TEMP-original.vob ... -vf ... -f vob TEMP-XXX.mpg

   3. Start a 2nd ffplay window with the video to be tested... skip to the 
same point as the original video and pause.

     ffplay -i TEMP-XXX.mpg

   4. Compare the 2.  Usually, it's quite obvious the test video is 
compressed or stretched, but if not, I'll move the test video over top the 
original video and try to square them up to see if they're the same.



More information about the ffmpeg-user mailing list