Aspect Ratios: DAR, SAR and Frame Size

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

Aspect Ratios: DAR, SAR and Frame Size

Adi Shavit
Hi,

  I have a video for which ffmpeg -i prints: Stream #0:0: Video: vp8,
yuv420p, 352x240, SAR 10:11 DAR 4:3, 15 fps, 15 tbr, 1k tbn, 1k tbc
(default)

As can be seen:

   - The reported frame size is 352x240. This is an aspect ratio (AR) of
   22:15
   - SAR = 10:11
   - DAR = 4:3

I have a few questions about these AR values:


   1. Obviously, the frame size is the decoded size of the frame.
   However, what do DAR and SAR mean in this context when they are both not
   1:1?
   2. How many pixels are *actually* stored in each frame before any
   stretching and/or padding occurs?
   3. Does ffmpeg only stretch or does it also pad the frame to fit the
   output?
   4. My usage does not care about the displayed video aspect-ratio, but I
   would *really *like to avoid any padding and also reduce any unnecessary
   processing (like stretching/scaling).
   Is it possible to tell ffmpeg to do decode the frames/pixels while
   keeping their internal AR and avoiding any padding and/or stretching?


Thank you and warm regards,
Adi
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Rio Kierkels
the DAR and SAR are applied on playback by the player you use. 352x240 are
the actual pixels stored in the file.
By default ffmpeg stretches you image to the dimensions you specify, no
padding or cropping is done.
To do that you can use the video filters pad and crop as per the
documentation.

Your final question is a bit vague. Maybe give your commandline you tried
and an example of the source and how you want it to look like.


On 13 January 2014 15:28, Adi Shavit <[hidden email]> wrote:

> Hi,
>
>   I have a video for which ffmpeg -i prints: Stream #0:0: Video: vp8,
> yuv420p, 352x240, SAR 10:11 DAR 4:3, 15 fps, 15 tbr, 1k tbn, 1k tbc
> (default)
>
> As can be seen:
>
>    - The reported frame size is 352x240. This is an aspect ratio (AR) of
>    22:15
>    - SAR = 10:11
>    - DAR = 4:3
>
> I have a few questions about these AR values:
>
>
>    1. Obviously, the frame size is the decoded size of the frame.
>    However, what do DAR and SAR mean in this context when they are both not
>    1:1?
>    2. How many pixels are *actually* stored in each frame before any
>    stretching and/or padding occurs?
>    3. Does ffmpeg only stretch or does it also pad the frame to fit the
>    output?
>    4. My usage does not care about the displayed video aspect-ratio, but I
>    would *really *like to avoid any padding and also reduce any unnecessary
>    processing (like stretching/scaling).
>    Is it possible to tell ffmpeg to do decode the frames/pixels while
>    keeping their internal AR and avoiding any padding and/or stretching?
>
>
> Thank you and warm regards,
> Adi
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>



--
42
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

James Darnley
In reply to this post by Adi Shavit
On 2014-01-13 15:28, Adi Shavit wrote:

> Hi,
>
>   I have a video for which ffmpeg -i prints: Stream #0:0: Video: vp8,
> yuv420p, 352x240, SAR 10:11 DAR 4:3, 15 fps, 15 tbr, 1k tbn, 1k tbc
> (default)
>
> As can be seen:
>
>    - The reported frame size is 352x240. This is an aspect ratio (AR) of
>    22:15
>    - SAR = 10:11
>    - DAR = 4:3
>
> I have a few questions about these AR values:
>
>
>    1. Obviously, the frame size is the decoded size of the frame.
>    However, what do DAR and SAR mean in this context when they are both not
>    1:1?
Display Aspect Ratio and Sample Aspect Ratio.  The latter is also known
as Pixel Aspect Ratio in some places.  This refers at the shape of the
pixels.

>    2. How many pixels are *actually* stored in each frame before any
>    stretching and/or padding occurs?

You answered that yourself.  The frame is 352 pixels wide and 240 pixels
high

>    3. Does ffmpeg only stretch or does it also pad the frame to fit the
>    output?

ffmpeg will not change the shape of the video unless you tell it to.
Then it does what you told it to.

>    4. My usage does not care about the displayed video aspect-ratio, but I
>    would *really *like to avoid any padding and also reduce any unnecessary
>    processing (like stretching/scaling).
>    Is it possible to tell ffmpeg to do decode the frames/pixels while
>    keeping their internal AR and avoiding any padding and/or stretching?

It does this.



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

signature.asc (697 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Adi Shavit
In reply to this post by Rio Kierkels
Hi Rio,

  Thanks for the prompt reply.

the DAR and SAR are applied on playback by the player you use. 352x240 are
> the actual pixels stored in the file.
>

This basically answers my last question.


> By default ffmpeg stretches you image to the dimensions you specify, no
> padding or cropping is done. <snip>




If I understand what you say, then if I didn't specify any special
dimensions, then ffmpeg will not do any stretching?

But, if DAR and SAR are applied only on playback (by any respectable
player), wouldn't they be applied by *ffmpeg itself *when encoding to a new
file format or, say, when saving frames as JPGs?

Thanks,
Adi
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Adi Shavit
In reply to this post by James Darnley
Boy! you guys are quick!
Thanks James, see my reply to Rio above.

 > As can be seen:

> >
> >    - The reported frame size is 352x240. This is an aspect ratio (AR) of
> >    22:15
> >    - SAR = 10:11
> >    - DAR = 4:3
> >
> > I have a few questions about these AR values:
> >
> >
> >    1. Obviously, the frame size is the decoded size of the frame.
> >    However, what do DAR and SAR mean in this context when they are both
> not
> >    1:1?
>
> Display Aspect Ratio and Sample Aspect Ratio.  The latter is also known
> as Pixel Aspect Ratio in some places.  This refers at the shape of the
> pixels.
>

I figured this out now:

Frame_AR x SAR == DAR   => (352/240)*(10/11) = 4/3 = 1.33333


Thanks,
Adi
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Rio Kierkels
In reply to this post by Adi Shavit
I think the ffmpeg command internally applies the SAR and DAR variables and
transforms the resolution until SAR is 1:1 and DAR matches the resolution
aspect ratio when it decodes the source footage. This way the math
internally is easier. On output it will recompute them according to your
given scale settings and other settings that could influence the aspect
ratios.
Still if you really want a good answer you should supply example input and
output files.

I have a small test dpx sequence that I often use. If you guy's like I can
put it on an ftp server somewhere.




On 13 January 2014 16:11, Adi Shavit <[hidden email]> wrote:

> Hi Rio,
>
>   Thanks for the prompt reply.
>
> the DAR and SAR are applied on playback by the player you use. 352x240 are
> > the actual pixels stored in the file.
> >
>
> This basically answers my last question.
>
>
> > By default ffmpeg stretches you image to the dimensions you specify, no
> > padding or cropping is done. <snip>
>
>
>
>
> If I understand what you say, then if I didn't specify any special
> dimensions, then ffmpeg will not do any stretching?
>
> But, if DAR and SAR are applied only on playback (by any respectable
> player), wouldn't they be applied by *ffmpeg itself *when encoding to a new
> file format or, say, when saving frames as JPGs?
>
> Thanks,
> Adi
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>



--
42
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Carl Eugen Hoyos
Rio Kierkels <riokierkels <at> gmail.com> writes:

> I think the ffmpeg command internally applies the SAR
> and DAR variables and transforms the resolution until
> SAR is 1:1 and DAR matches the resolution aspect
> ratio when it decodes the source footage.

I may misunderstand but this sounds (completely) wrong.

Please avoid top-posting here.

Carl Eugen

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Rio Kierkels
The way I think ffmpeg uses DAR and SAR on decode (and this is where I base
all my other code around ffmpeg on)
is that when you have a typical anamorphic DV source which is 720x576 on
disk but has a display aspect ratio of 16:9
it first unsqueezes the footage until the resolution reaches the DAR target
of 16:9. In this case that would be 1024x576.
Then it applies all it's magic to that frame size and on ouput if the
output display aspect ratio is equivalent of the current
frame aspect ratio it will set the DAR to 1. If it isn't it calculates what
the pixel aspect ratio has to be in order to let the
player know what transformation it has to use to get the original display
aspect ratio. I could be totally wrong here but
the code that I've written around it has not failed me yet.

And I'm sorry but I'm not sure I get the top-posting part. I just hit reply
in gmail...
This is the first mailing list I've ever participated in btw.


On 13 January 2014 16:58, Carl Eugen Hoyos <[hidden email]> wrote:

> Rio Kierkels <riokierkels <at> gmail.com> writes:
>
> > I think the ffmpeg command internally applies the SAR
> > and DAR variables and transforms the resolution until
> > SAR is 1:1 and DAR matches the resolution aspect
> > ratio when it decodes the source footage.
>
> I may misunderstand but this sounds (completely) wrong.
>
> Please avoid top-posting here.
>
> Carl Eugen
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>



--
42
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Adi Shavit
In reply to this post by Rio Kierkels
Thanks. I think I sort-of understand what didn't.
I don't really have any command line besides the -i option as I wrote in my
first post.
Thanks,
Adi

BTW, according to
this<http://ffmpeg.org/pipermail/ffmpeg-user/2014-January/thread.html#19357>
no
one was top-posting replies (except the first question post).


On Mon, Jan 13, 2014 at 5:21 PM, Rio Kierkels <[hidden email]> wrote:

> I think the ffmpeg command internally applies the SAR and DAR variables and
> transforms the resolution until SAR is 1:1 and DAR matches the resolution
> aspect ratio when it decodes the source footage. This way the math
> internally is easier. On output it will recompute them according to your
> given scale settings and other settings that could influence the aspect
> ratios.
> Still if you really want a good answer you should supply example input and
> output files.
>
> I have a small test dpx sequence that I often use. If you guy's like I can
> put it on an ftp server somewhere.
>
>
>
>
> On 13 January 2014 16:11, Adi Shavit <[hidden email]> wrote:
>
> > Hi Rio,
> >
> >   Thanks for the prompt reply.
> >
> > the DAR and SAR are applied on playback by the player you use. 352x240
> are
> > > the actual pixels stored in the file.
> > >
> >
> > This basically answers my last question.
> >
> >
> > > By default ffmpeg stretches you image to the dimensions you specify, no
> > > padding or cropping is done. <snip>
> >
> >
> >
> >
> > If I understand what you say, then if I didn't specify any special
> > dimensions, then ffmpeg will not do any stretching?
> >
> > But, if DAR and SAR are applied only on playback (by any respectable
> > player), wouldn't they be applied by *ffmpeg itself *when encoding to a
> new
> > file format or, say, when saving frames as JPGs?
> >
> > Thanks,
> > Adi
> > _______________________________________________
> > ffmpeg-user mailing list
> > [hidden email]
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> >
>
>
>
> --
> 42
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Ed Torbett
> BTW, according to
> this<http://ffmpeg.org/pipermail/ffmpeg-user/2014-
> January/thread.html#19357>
> no
> one was top-posting replies (except the first question post).
>

I think you may misunderstand the term 'top-posting', so I thought I'd clear this up before anyone gets annoyed. Top-posting doesn't refer to 'top-level' in terms of the tree shown in the mailing list archive (which would occur if you removed the 'RE:' tag, and would also annoy people on mailing lists), but to where your response appears relative to the message you're responding to.

For example, my response is below yours; this is bottom-posting. If I wrote my response above your original email, that would be top-posting.

Top-posting is generally frowned upon in mailing lists because other mailing list users (who are not yet participants in the discussion) will generally start reading at the top of the mail and therefore have no context for what they are reading until they reach the original post, somewhere after all the replies. This forces readers to have to jump back and forth in the mail and makes understanding of both the original mail and the response more difficult.

I am aware that many email clients default to top-posting - certainly mine (Outlook) does and it's not configurable. It's also a work computer, so I can't change client. Gmail and other clients do let you configure the position of the reply, but often it's easier to simply keep in your head that you're writing on the mailing list, and position your response accordingly.

For further information on this, I recommend Wikipedia's article on posting styles, or this article: http://www.idallen.com/topposting.html

Thanks,
Ed


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Rio Kierkels
On 13 January 2014 17:37, Ed Torbett <[hidden email]>wrote:

> > BTW, according to
> > this<http://ffmpeg.org/pipermail/ffmpeg-user/2014-
> > January/thread.html#19357>
> > no
> > one was top-posting replies (except the first question post).
> >
>
> I think you may misunderstand the term 'top-posting', so I thought I'd
> clear this up before anyone gets annoyed. Top-posting doesn't refer to
> 'top-level' in terms of the tree shown in the mailing list archive (which
> would occur if you removed the 'RE:' tag, and would also annoy people on
> mailing lists), but to where your response appears relative to the message
> you're responding to.
>
> For example, my response is below yours; this is bottom-posting. If I
> wrote my response above your original email, that would be top-posting.
>
> Top-posting is generally frowned upon in mailing lists because other
> mailing list users (who are not yet participants in the discussion) will
> generally start reading at the top of the mail and therefore have no
> context for what they are reading until they reach the original post,
> somewhere after all the replies. This forces readers to have to jump back
> and forth in the mail and makes understanding of both the original mail and
> the response more difficult.
>
> I am aware that many email clients default to top-posting - certainly mine
> (Outlook) does and it's not configurable. It's also a work computer, so I
> can't change client. Gmail and other clients do let you configure the
> position of the reply, but often it's easier to simply keep in your head
> that you're writing on the mailing list, and position your response
> accordingly.
>
> For further information on this, I recommend Wikipedia's article on
> posting styles, or this article: http://www.idallen.com/topposting.html
>
> Thanks,
> Ed
>
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>

Thanks Ed for clearing this up.
I hope this post is the way it's supposed to be done then.

--
42
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Carl Eugen Hoyos
In reply to this post by Rio Kierkels
Rio Kierkels <riokierkels <at> gmail.com> writes:

> The way I think ffmpeg uses DAR and SAR on decode (and
> this is where I base all my other code around ffmpeg on)
> is that when you have a typical anamorphic DV source
> which is 720x576 on disk but has a display aspect ratio
> of 16:9 it first unsqueezes the footage until the
> resolution reaches the DAR target of 16:9. In this case
> that would be 1024x576. Then it applies all it's magic
> to that frame size and on ouput if the output display
> aspect ratio is equivalent of the current frame aspect
> ratio it will set the DAR to 1.

To the best of my knowledge, this is not what FFmpeg does
by default.
On the contrary, it will be default not change the
resolution (which is 720x576 in your example).

Carl Eugen

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Aspect Ratios: DAR, SAR and Frame Size

Rio Kierkels
Yes that is what I mean to say. If you don't give it an output resolution
it will keep the input resolution.
But any geometry related operation is done on the aspect ratio corrected
frame.


On 15 January 2014 00:22, Carl Eugen Hoyos <[hidden email]> wrote:

> Rio Kierkels <riokierkels <at> gmail.com> writes:
>
> > The way I think ffmpeg uses DAR and SAR on decode (and
> > this is where I base all my other code around ffmpeg on)
> > is that when you have a typical anamorphic DV source
> > which is 720x576 on disk but has a display aspect ratio
> > of 16:9 it first unsqueezes the footage until the
> > resolution reaches the DAR target of 16:9. In this case
> > that would be 1024x576. Then it applies all it's magic
> > to that frame size and on ouput if the output display
> > aspect ratio is equivalent of the current frame aspect
> > ratio it will set the DAR to 1.
>
> To the best of my knowledge, this is not what FFmpeg does
> by default.
> On the contrary, it will be default not change the
> resolution (which is 720x576 in your example).
>
> Carl Eugen
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>



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