[FFmpeg-user] Automatically scaling videos and adding padding
littlebat
dashing.meng at gmail.com
Mon Jun 13 03:27:20 CEST 2011
On Sun, 12 Jun 2011 20:20:51 +0200
Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
> On date Sunday 2011-06-12 13:53:28 +0200, Francesco Turco encoded:
> > Hello,
> >
> > I need to convert some random videos to MPEG files with a 720x576
> > resolution in order for my TV decoder to play them. That is, I
> > usually need to scale movies and add padding because source files
> > are almost never 720x576 already. For now, I use the following
> > command:
> >
> > ffmpeg -i input.avi -b 1536k -ab 192k -vf
> > scale='gte(iw/ih\,720/576)*720+lt(iw/ih\,720/576)*((576*iw)/ih):lte
> > (iw/ih\,720/576)*576+gt(iw/ih\,720/576)*((720*ih)/iw)',pad='720:576:
> > (720-gte(iw/ih\,720/576)*720-lt(iw/ih\,720/576)*((576*iw)/ih))/2:
> > (576-lte(iw/ih\,720/576)*576-gt(iw/ih\,720/576)*
> > ((720*ih)/iw))/2:black' -acodec mp2 -vcodec mpeg2video -f mpeg -r
> > 25 -ar 48k output.mpeg
> >
> > As you can see, the main problem is the -vf option, which is by far
> > too complex. In plain English, it does the following things:
> >
> > - It automatically scales the source video in order for it to be put
> > inside a 720x576 rectangle without altering its original aspect
> > ratio (at this point the video is less than or equal to 720 pixels
> > in width and less than or equal to 576 pixels in height)
> > - It automatically adds padding around the scaled video, either at
> > top/bottom or at left/right, because the output file should be
> > 720x576 exactly
> >
> > The basic idea is that iw/ih is the aspect ratio of the source file,
> > which is compared to 720/576, the desired aspect ratio. There are
> > three possibilities: iw/ih is less than, equal to or greater than
> > 720/576. Each case is treated separately, both when scaling the
> > video and when adding padding.
> >
> > My question is: there is some other way to accomplish this? A better
> > formula perhaps?
>
> gte(iw/ih\,720/576)*720+lt(iw/ih\,720/576)*((576*iw)/ih)
>
> iw/ih = a
> gte(a\,720/576)*720+lt(a\,720/576)*(576*a)
>
> this could be better expressed as:
> if(gte(a,720/576)\, 720\, 576*a)
>
> unfortunately we don't support if(cond,expr1,expr2), patches are
> welcome ;-).
Why don't calculate with other tool? "bash" or "bc"? Ffmpeg is a video
processing tool, calculating shouldn't its main function, I think.
>From my personal opinion, ffmpeg should be an all purpose video tool, it
should can decode every video format and encode as much format as it
can. I don't think ffmpeg has reached this level, for example, ffmpeg
can not decode video format as much as mencoder can, but, I heard
mencoder seem has stoped its development. isn't it?
--littlebat
More information about the ffmpeg-user
mailing list