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

Hans Carlson forbyta at gmx.com
Mon Jan 27 04:20:27 EET 2020


On Sun, 26 Jan 2020, Carl Eugen Hoyos wrote:

> Am So., 26. Jan. 2020 um 23:38 Uhr schrieb Hans Carlson <forbyta at gmx.com>:
>
>> This is compressed horizontally (via ffplay) compared to original
>>
>>    $ ffmpeg -i TEMP-original.vob -codec:v mpeg2video -b:v 16384k -bufsize 4096k -maxrate 30000k -codec:a copy -vf crop=704:416:2:82,scale=720:-1,pad=720:480:0:27 -t 60 -f vob TEMP-crop-scale-pad.mpg
>
> You have to force an aspect ratio to get the output you want, use the 
> setsar / setdar filter.

I suspected it might have something to do with sar/dar and tried a variety 
of setsar and/or setdar filter combinations, but either they're in the 
wrong place in the filter sequence or I'm not using the correct options.

Here's a couple examples (I've tried many, many more)...

This one, using only setdar (16/9) at the end, causes the video to be 
stretched horizontally:

   $ ffmpeg -i TEMP-original.vob -codec:v mpeg2video -b:v 16384k -bufsize 4096k -maxrate 30000k -codec:a copy -vf crop=704:416:2:82,scale=720:-1,pad=720:480:0:27,setdar=dar=16/9 -t 60 -f vob TEMP-crop-scale-pad-setdar.mpg

Putting setsar (1/1) at the beginning and setdar (16/9) at the end is also 
stretched horizontally, actually, it looks exactly the same as without 
setsar.

   $ ffmpeg -i TEMP-original.vob -codec:v mpeg2video -b:v 16384k -bufsize 4096k -maxrate 30000k -codec:a copy -vf setsar=sar=1/1,crop=704:416:2:82,scale=720:-1,pad=720:480:0:27,setdar=dar=16/9 -t 60 -f vob TEMP-setsar-crop-scale-pad-setdar.mpg

I also tried setsar just before the pad filter, but it didn't make a 
difference.  And I tried different values for setsar (eg. sar=32/27, 
sar=16/15), but nothing I've tried has worked. And, I tried setsar without 
setdar, but couldn't find a sar value that worked.

Do I need to put setsar and/or setdar in a different position in the 
filter chain?

What value should I use for setsar?

Is 16/9 the correct value for setdar since that's what I want it to end up 
to be?

-----------------------------------------------------------------------------------------------------
Complete output for the 2 examples above
-----------------------------------------------------------------------------------------------------

   $ ffmpeg -i TEMP-original.vob -codec:v mpeg2video -b:v 16384k -bufsize 4096k -maxrate 30000k -codec:a copy -vf crop=704:416:2:82,scale=720:-1,pad=720:480:0:27,setdar=dar=16/9 -t 60 -f vob TEMP-crop-scale-pad-setdar.mpg
   ffmpeg version N-96491-g4b4bcb126c Copyright (c) 2000-2020 the FFmpeg developers
     built with gcc 9 (GCC)
     configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-static --disable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-libbluray --enable-libcdio
     libavutil      56. 38.100 / 56. 38.100
     libavcodec     58. 66.101 / 58. 66.101
     libavformat    58. 35.104 / 58. 35.104
     libavdevice    58.  9.103 / 58.  9.103
     libavfilter     7. 71.100 /  7. 71.100
     libswscale      5.  6.100 /  5.  6.100
     libswresample   3.  6.100 /  3.  6.100
     libpostproc    55.  6.100 / 55.  6.100
   Input #0, mpeg, from 'TEMP-original.vob':
     Duration: 01:24:52.03, start: 0.287267, bitrate: 5841 kb/s
       Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
       Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
   Stream mapping:
     Stream #0:0 -> #0:0 (mpeg2video (native) -> mpeg2video (native))
     Stream #0:1 -> #0:1 (copy)
   Press [q] to stop, [?] for help
   [swscaler @ 0x3cb8bc0] Warning: data is not aligned! This can lead to a speed loss
   Output #0, vob, to 'TEMP-crop-scale-pad-setdar.mpg':
     Metadata:
       encoder         : Lavf58.35.104
       Stream #0:0: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 32:27 DAR 16:9], q=2-31, 16384 kb/s, 25 fps, 90k tbn, 25 tbc
       Metadata:
         encoder         : Lavc58.66.101 mpeg2video
       Side data:
         cpb: bitrate max/min/avg: 30000000/0/16384000 buffer size: 4096000 vbv_delay: N/A
       Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
   [mpeg @ 0x3b603c0] New subtitle stream 0:2 at pos:6678542 and DTS:20.2873sbits/s speed=15.9x
   [mpeg @ 0x3b603c0] New subtitle stream 0:3 at pos:7571470 and DTS:22.5673s
   frame= 1500 fps=370 q=2.0 Lsize=   32856kB time=00:00:59.96 bitrate=4488.3kbits/s speed=14.8x
   video:30800kB audio:1641kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.280809%

   $ ffmpeg -hide_banner -i TEMP-crop-scale-pad-setdar.mpg
   Input #0, mpeg, from 'TEMP-crop-scale-pad-setdar.mpg':
     Duration: 00:01:00.00, start: 0.540000, bitrate: 4485 kb/s
       Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 720x480 [SAR 32:27 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
       Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
   At least one output file must be specified



   $ ffmpeg -i TEMP-original.vob -codec:v mpeg2video -b:v 16384k -bufsize 4096k -maxrate 30000k -codec:a copy -vf setsar=sar=1/1,crop=704:416:2:82,scale=720:-1,pad=720:480:0:27,setdar=dar=16/9 -t 60 -f vob TEMP-setsar-crop-scale-pad-setdar.mpg
   ffmpeg version N-96491-g4b4bcb126c Copyright (c) 2000-2020 the FFmpeg developers
     built with gcc 9 (GCC)
     configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-static --disable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-libbluray --enable-libcdio
     libavutil      56. 38.100 / 56. 38.100
     libavcodec     58. 66.101 / 58. 66.101
     libavformat    58. 35.104 / 58. 35.104
     libavdevice    58.  9.103 / 58.  9.103
     libavfilter     7. 71.100 /  7. 71.100
     libswscale      5.  6.100 /  5.  6.100
     libswresample   3.  6.100 /  3.  6.100
     libpostproc    55.  6.100 / 55.  6.100
   Input #0, mpeg, from 'TEMP-original.vob':
     Duration: 01:24:52.03, start: 0.287267, bitrate: 5841 kb/s
       Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
       Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
   Stream mapping:
     Stream #0:0 -> #0:0 (mpeg2video (native) -> mpeg2video (native))
     Stream #0:1 -> #0:1 (copy)
   Press [q] to stop, [?] for help
   [swscaler @ 0x3d3fbc0] Warning: data is not aligned! This can lead to a speed loss
   Output #0, vob, to 'TEMP-setsar-crop-scale-pad-setdar.mpg':
     Metadata:
       encoder         : Lavf58.35.104
       Stream #0:0: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 32:27 DAR 16:9], q=2-31, 16384 kb/s, 25 fps, 90k tbn, 25 tbc
       Metadata:
         encoder         : Lavc58.66.101 mpeg2video
       Side data:
         cpb: bitrate max/min/avg: 30000000/0/16384000 buffer size: 4096000 vbv_delay: N/A
       Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
   [mpeg @ 0x3be73c0] New subtitle stream 0:2 at pos:6678542 and DTS:20.2873sbits/s speed=  16x
   [mpeg @ 0x3be73c0] New subtitle stream 0:3 at pos:7571470 and DTS:22.5673s
   frame= 1500 fps=360 q=2.0 Lsize=   32856kB time=00:00:59.96 bitrate=4488.3kbits/s speed=14.4x
   video:30800kB audio:1641kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.280809%

   $ ffmpeg -hide_banner -i TEMP-setsar-crop-scale-pad-setdar.mpg
   Input #0, mpeg, from 'TEMP-setsar-crop-scale-pad-setdar.mpg':
     Duration: 00:01:00.00, start: 0.540000, bitrate: 4485 kb/s
       Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 720x480 [SAR 32:27 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
       Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
   At least one output file must be specified


More information about the ffmpeg-user mailing list