FORUMS: list search recent posts

Square & non-square pixels and scaling to 1920 x 1080

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Mark Buchheim (mark@buchheim.com)
Square & non-square pixels and scaling to 1920 x 1080
on Jan 22, 2015 at 2:45:40 am

We would like to concoct an FFMPEG syntax to detect whether a source video has square pixels (1.0) or non-square pixels (typically 1.333 for us) and define the output size accordingly. It should multiple the width in pixels with the PIXEL ASPECT RATIO (what we will call PLAYBACK WIDTH) to make decisions off of.


******IF THE SOURCE HAS SQUARE PIXELS******
then scale the source video to either 1080 pixels in height or 1920 pixels in width (while keeping the aspect ratio) as long as the width never exceeds 1920 pixels and the height never exceeds 1080 pixels. Also, in the event that the output video is not exactly 1920 x 1080 pixels, then padding will be added to either the top and bottom or left and right areas of the video region to achieve a perfect 1920 x 1080 resolution.

For example, these all will result in 1920 x 1080 output videos:

* Source = 1280 x 720, then scale to 1920 x 1080 with no black padding

* Source = 640 x 480, then scale to 1440 x 1080 with an additional 240 pixels of black padding added to left and right

* Source = 1280 x 534, then scale to 1920 x 802 (or 802 when rounded up) with an additional 139 pixels of black padding added to the top and bottom

* Source = 640 x 640, then scale to 1080 x 1080 with an additional 420 pixels of black padding added to the top and bottom

I was actually able to create an FFMPEG syntax that did this (it's all in the video filter portion); however, it didn't address the NON-SQUARE PIXEL source videos.

-vf "yadif=0:-1:0, scale=iw*min(1920/iw\,1080/ih):ih*min(1920/iw\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\,1080/ih))/2:(1080-ih*min(1920/iw\,1080/ih))/2" -ac 2 -ar 48000 -b:a 1500k -intra_matrix 8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79 -inter_matrix 16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44 -g 15 -bf 2 -top 1 -r 29.97 -b:v 25000k -minrate 25000k -maxrate 25000k -bufsize 25000k -vtag hdv2 -y


******IF THE SOURCE HAS NON-SQUARE PIXELS (typically 1.333 for us)******
then scale the source video in the same manner as the SQUARE PIXEL examples above; however, it will have to detect the PLAYBACK WIDTH by multiplying the width in pixels with the PIXEL ASPECT RATIO.

For example, this will result in an 1920 x 1080 output video:

* Source = 1440 x 1080, multiple 1440 x 1.333 to determine the PLAYBACK WIDTH (which equals 1920 when rounded up) then scale to 1920 x 1080 with no black padding.


I KNOW THERE ARE MANY OTHER INCONSISTENCIES that might not work with a planket calculation like what I am proposing...but we only have a finite variety of video resolutions and pixel aspect ratios to deal with...and if we can create a syntax that handles just these...we will be 100% covered.


Return to posts index

stephen dixon
Re: Square & non-square pixels and scaling to 1920 x 1080
on Jan 22, 2015 at 9:05:19 am

If I was you I'd use ffprobe to find the dimensions and then use shell scripting - in the shell of yourchoice to make the decisions about output and filters before you get to ffmpeg. What you're doing should probably work eventually, but it looks like you're making it harder for yourself.

Stephen Dixon
Editor, Animator, Motionographer
Museum Victoria


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]