Crop, Scale, Pad without distortion

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Crop, Scale, Pad without distortion

Hans Carlson-2
Why does padding (after crop/scale) seem to compress this video
horizontally?

   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

The actual video part (not including black bars) is (704:416:2:82)
according to cropdetect.

I'd like to end up with a video that's cropped to 704:416:2:82, scaled to
720x-1, padded to 720x480 with black bars only on the top/bottom, and a
DAR of 16:9 instead of 4:3. Not necessarily in that order... I'm not sure
of the "correct" filter order.

If all I do is crop the video to 704:416:2:82 it looks fine compared to
the original (complete output below):

   $ ffmpeg -i TEMP-original.vob -codec:v mpeg2video -b:v 16384k -bufsize 4096k -maxrate 30000k -codec:a copy -vf crop=704:416:2:82 -t 60 -f vob TEMP-crop.mpg

If I crop and scale to 720x-1 it still looks fine (complete output below):

   $ 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 -t 60 -f vob TEMP-crop-scale.mpg

BUT, if I try to crop, scale and pad the top/bottom to 720x480, then the
video is compressed horizontally (complete output below):

   $ 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

FYI. The crop/scale ends up as 720x425, so to get to 720x480 I pad top
with 27 (480-425/2 = 27.5).

Why does padding cause the video to be compressed horizontally and more
importantly, how can I convert the original to 720x480 with bars only on
the top/bottom, DAR of 16/9, WITHOUT distorting the video?


-------------------------------------------------------------------------------
Complete output for all 3 example commands
-------------------------------------------------------------------------------

Crop to "cropdetect" size (704:416:2:82)
This looks fine (via ffplay) compared to original - it is not distorted

   $ ffmpeg -i TEMP-original.vob -codec:v mpeg2video -b:v 16384k -bufsize 4096k -maxrate 30000k -codec:a copy -vf crop=704:416:2:82 -t 60 -f vob TEMP-crop.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
   Output #0, vob, to 'TEMP-crop.mpg':
     Metadata:
       encoder         : Lavf58.35.104
       Stream #0:0: Video: mpeg2video (Main), yuv420p, 704x416 [SAR 16:15 DAR 352:195], 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 @ 0x21833c0] New subtitle stream 0:2 at pos:6678542 and DTS:20.2873sbits/s speed=20.8x
   [mpeg @ 0x21833c0] New subtitle stream 0:3 at pos:7571470 and DTS:22.5673s
   frame= 1500 fps=489 q=2.0 Lsize=   34656kB time=00:00:59.96 bitrate=4734.2kbits/s speed=19.6x
   video:32580kB audio:1641kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.272054%

   $ ffmpeg -hide_banner -i TEMP-crop.mpg
   Input #0, mpeg, from 'TEMP-crop.mpg':
     Duration: 00:01:00.00, start: 0.540000, bitrate: 4731 kb/s
       Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 704x416 [SAR 104:99 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


Crop to "cropdetect" size (704:416:2:82) and scale to 720x-1 (ends up as 720x425)
This still looks fine (via ffplay) compared to original - it is not distorted

   $ 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 -t 60 -f vob TEMP-crop-scale.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 @ 0x3ad3bc0] Warning: data is not aligned! This can lead to a speed loss
   Output #0, vob, to 'TEMP-crop-scale.mpg':
     Metadata:
       encoder         : Lavf58.35.104
       Stream #0:0: Video: mpeg2video (Main), yuv420p, 720x425 [SAR 374:351 DAR 352:195], 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 @ 0x397b3c0] New subtitle stream 0:2 at pos:6678542 and DTS:20.2873sbits/s speed=16.3x
   [mpeg @ 0x397b3c0] New subtitle stream 0:3 at pos:7571470 and DTS:22.5673s
   frame= 1500 fps=376 q=2.0 Lsize=   32602kB time=00:00:59.96 bitrate=4453.6kbits/s speed=  15x
   video:30550kB audio:1641kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.278884%

   $ ffmpeg -hide_banner -i TEMP-crop-scale.mpg
   Input #0, mpeg, from 'TEMP-crop-scale.mpg':
     Duration: 00:01:00.00, start: 0.540000, bitrate: 4451 kb/s
       Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 720x425 [SAR 85:81 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


Crop to "cropdetect" size (704:416:2:82), scale to 720x-1 and pad top/bottom to 720x480
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
   ffmpeg version N-96491-g4b4bcb126c Copyright (c) 2000-2020 the FFmpeg developers
     built with gcc 9 (GCC)
     configuration: --prefix=/usr/local/ffmpeg-master-20200125 --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 @ 0x254fbc0] Warning: data is not aligned! This can lead to a speed loss
   Output #0, vob, to 'TEMP-crop-scale-pad.mpg':
     Metadata:
       encoder         : Lavf58.35.104
       Stream #0:0: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 374:351 DAR 187:117], 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 @ 0x23f73c0] New subtitle stream 0:2 at pos:6678542 and DTS:20.2873sbits/s speed=16.3x
   [mpeg @ 0x23f73c0] New subtitle stream 0:3 at pos:7571470 and DTS:22.5673s
   frame= 1500 fps=369 q=2.0 Lsize=   32856kB time=00:00:59.96 bitrate=4488.3kbits/s speed=14.7x
   video:30800kB audio:1641kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.280809%

   $ ffmpeg -hide_banner -i TEMP-crop-scale-pad.mpg
   Input #0, mpeg, from 'TEMP-crop-scale-pad.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 1:1 DAR 3:2], 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-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Carl Eugen Hoyos-2
Am So., 26. Jan. 2020 um 23:38 Uhr schrieb Hans Carlson <[hidden email]>:

>    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
>
> The actual video part (not including black bars) is (704:416:2:82)
> according to cropdetect.
>
> I'd like to end up with a video that's cropped to 704:416:2:82, scaled to
> 720x-1, padded to 720x480 with black bars only on the top/bottom, and a
> DAR of 16:9 instead of 4:3. Not necessarily in that order... I'm not sure
> of the "correct" filter order.

The order as written by you is correct (any other order can lead to worse
output).

[...]

> 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.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Hans Carlson-2
On Sun, 26 Jan 2020, Carl Eugen Hoyos wrote:

> Am So., 26. Jan. 2020 um 23:38 Uhr schrieb Hans Carlson <[hidden email]>:
>
>> 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
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Carl Eugen Hoyos-2
Am Mo., 27. Jan. 2020 um 03:27 Uhr schrieb Hans Carlson <[hidden email]>:

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

Apparently not but it is what you told us you'd like.
(I did not calculate myself)

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Hans Carlson-2
On Mon, 27 Jan 2020, Carl Eugen Hoyos wrote:

> Am Mo., 27. Jan. 2020 um 03:27 Uhr schrieb Hans Carlson <[hidden email]>:
>
>> Is 16/9 the correct value for setdar since that's what I want it to end
>> up to be?
>
> Apparently not but it is what you told us you'd like. (I did not
> calculate myself)

OK... perhaps I don't know WHAT dar I want.  I plan to concat this video
to some others (using concat protocol or demuxer) and the other videos
have a DAR of 16:9, eg:

   Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x480 [SAR 32:27 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc

So, based on that, I assumed it would be a good idea to match the aspect
ration (720x480) and the DAR.

If the DAR value doesn't matter when concat'ing multiple files, then I just
want the video to LOOK correct.

How do I calculate the correct dar (and/or sar) values to use?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Carl Eugen Hoyos-2
Am Mo., 27. Jan. 2020 um 04:28 Uhr schrieb Hans Carlson <[hidden email]>:

>
> On Mon, 27 Jan 2020, Carl Eugen Hoyos wrote:
>
> > Am Mo., 27. Jan. 2020 um 03:27 Uhr schrieb Hans Carlson <[hidden email]>:
> >
> >> Is 16/9 the correct value for setdar since that's what I want it to end
> >> up to be?
> >
> > Apparently not but it is what you told us you'd like. (I did not
> > calculate myself)
>
> OK... perhaps I don't know WHAT dar I want.  I plan to concat this video
> to some others (using concat protocol or demuxer) and the other videos
> have a DAR of 16:9, eg:
>
>    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x480 [SAR 32:27 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
>
> 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 ?

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

FFmpeg-users mailing list
In reply to this post by Hans Carlson-2
On Sun, Jan 26, 2020 at 7:28 PM Hans Carlson <[hidden email]> wrote:

> On Mon, 27 Jan 2020, Carl Eugen Hoyos wrote:
>
> > Am Mo., 27. Jan. 2020 um 03:27 Uhr schrieb Hans Carlson <[hidden email]
> >:
> >
> >> Is 16/9 the correct value for setdar since that's what I want it to end
> >> up to be?
> >
> > Apparently not but it is what you told us you'd like. (I did not
> > calculate myself)
>
> OK... perhaps I don't know WHAT dar I want.  I plan to concat this video
> to some others (using concat protocol or demuxer) and the other videos
> have a DAR of 16:9, eg:
>
>    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first),
> 720x480 [SAR 32:27 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k
> tbn, 59.94 tbc
>
> So, based on that, I assumed it would be a good idea to match the aspect
> ration (720x480) and the DAR.
>
> If the DAR value doesn't matter when concat'ing multiple files, then I
> just
> want the video to LOOK correct.
>
> How do I calculate the correct dar (and/or sar) values to use?
> _______________________________________________
>
>
Your larger issues are all coming from the anamorphic aspects of PAL and
NTSC. They are not "right" to begin with, but will play back at the correct
resolution using DAR. You need to take the original PAL 720x576 4:3, trim
it  to 704x416, then resize it to 720x480 with 16/9 DAR. Then you can
combine the two with the 16/9 DAR and they will play back correctly. (This
is highly over-simplified without doing the math).

This, of course does not address the framerates. Either the 25fps PAL or
the 29.97fps NTSC will need to be converted to the other.


--

*William Caulfield *| *ContentBridge Systems*
Product Manager, Digital Media & Systems | www.contentbridge.tv
4712 Admiralty Way #533 | Marina Del Rey, CA 90292
*T* 310.405.6178 | *C* 310.405.6178 x7704 | *E*
[hidden email] <[hidden email]>

A GoDigital Media Group Company

*2014 Winner** - Digital Innovation Award - Entertainment Merchants
Association*
*2016 Winner** - Stratus Award "Cloud Computing" - Business Intelligence
Group*

You are important to us. World class customer service is our goal. If you
do not hear back from me in a timely manner it is likely that I'm
unavailable. In such an event please contact [hidden email]
*and* call 310.405.6178 and
enter option 2 for help and support.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Carl Eugen Hoyos-2
Am Mo., 27. Jan. 2020 um 23:03 Uhr schrieb William Caulfield via
ffmpeg-user <[hidden email]>:

>
> On Sun, Jan 26, 2020 at 7:28 PM Hans Carlson <[hidden email]> wrote:
>
> > On Mon, 27 Jan 2020, Carl Eugen Hoyos wrote:
> >
> > > Am Mo., 27. Jan. 2020 um 03:27 Uhr schrieb Hans Carlson <[hidden email]
> > >:
> > >
> > >> Is 16/9 the correct value for setdar since that's what I want it to end
> > >> up to be?
> > >
> > > Apparently not but it is what you told us you'd like. (I did not
> > > calculate myself)
> >
> > OK... perhaps I don't know WHAT dar I want.  I plan to concat this video
> > to some others (using concat protocol or demuxer) and the other videos
> > have a DAR of 16:9, eg:
> >
> >    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first),
> > 720x480 [SAR 32:27 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k
> > tbn, 59.94 tbc
> >
> > So, based on that, I assumed it would be a good idea to match the aspect
> > ration (720x480) and the DAR.
> >
> > If the DAR value doesn't matter when concat'ing multiple files, then I
> > just
> > want the video to LOOK correct.
> >
> > How do I calculate the correct dar (and/or sar) values to use?
> > _______________________________________________
> >
> >
> Your larger issues are all coming from the anamorphic aspects of PAL and
> NTSC. They are not "right" to begin with, but will play back at the correct
> resolution using DAR. You need to take the original PAL 720x576 4:3, trim
> it  to 704x416, then resize it to 720x480 with 16/9 DAR. Then you can
> combine the two with the 16/9 DAR and they will play back correctly. (This
> is highly over-simplified without doing the math).

Hans wants to crop black bars so above will not (completely) work for him...

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Devin Heitmueller
On Mon, Jan 27, 2020, 5:05 PM Carl Eugen Hoyos <[hidden email]> wrote:

>
> Hans wants to crop black bars so above will not (completely) work for
> him...
>
> Carl Eugen
>

FWIW, I've done a bunch of aspect ratio conversion based on AFD (including
cropping out letterbox/pillarbars and dealing with nonsquare pixels), and
I've had the best success with crop->pad->scale.  There is also at least
one bug in the scale filter where it doesn't properly handle upstream
filters changing the properties of the the scaler input link, which causes
incorrect scaling.

I've got a tree which addresses those issues.  Let me know if you want a
link.

Almost all of those issues come down to sar/dar problems, so you should
turn up the logging and look at the sar for each link in the filter graph
to debug.

Devin

>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Hans Carlson-2
In reply to this post by Carl Eugen Hoyos-2
On Mon, 27 Jan 2020, Carl Eugen Hoyos wrote:

> Am Mo., 27. Jan. 2020 um 04:28 Uhr schrieb Hans Carlson <[hidden email]>:
>>
>> 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.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Hans Carlson-2
In reply to this post by Devin Heitmueller
On Mon, 27 Jan 2020, Devin Heitmueller wrote:

> FWIW, I've done a bunch of aspect ratio conversion based on AFD (including
> cropping out letterbox/pillarbars and dealing with nonsquare pixels), and
> I've had the best success with crop->pad->scale.  There is also at least
> one bug in the scale filter where it doesn't properly handle upstream
> filters changing the properties of the the scaler input link, which causes
> incorrect scaling.
>
> I've got a tree which addresses those issues.  Let me know if you want a
> link.

I would a love a link.  Any good examples might help me understand better.
Thanks.

> Almost all of those issues come down to sar/dar problems, so you should
> turn up the logging and look at the sar for each link in the filter graph
> to debug.

Yes, I'm sure that's my problem... I just don't have a good enough
understand to figure out what sar/dar need to be and where/how they
should be used.  Any help is appreciated.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Crop, Scale, Pad without distortion

Gyan Doshi-2
In reply to this post by Devin Heitmueller


On 28-01-2020 04:44 am, Devin Heitmueller wrote:

> On Mon, Jan 27, 2020, 5:05 PM Carl Eugen Hoyos <[hidden email]> wrote:
>
>> Hans wants to crop black bars so above will not (completely) work for
>> him...
>>
>> Carl Eugen
>>
> FWIW, I've done a bunch of aspect ratio conversion based on AFD (including
> cropping out letterbox/pillarbars and dealing with nonsquare pixels), and
> I've had the best success with crop->pad->scale.  There is also at least
> one bug in the scale filter where it doesn't properly handle upstream
> filters changing the properties of the the scaler input link, which causes
> incorrect scaling.

Is this with a recent build (> 15 Jan 2020)?

Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".