[gst-devel] fractions and aspect ratios

Thomas Vander Stichele thomas at apestaart.org
Tue Jul 13 12:41:06 CEST 2004


Hi,

one of the things I've been looking at is a decent way to handle aspect
ratios and implement it correctly.  I've attached two
patches-in-progress.

The first is a patch to core that, besides some cleanups, implements a
new GValue type, GstFraction, with some convenience functions and
testsuite apps.

The second is a patch to gst-plugins for elements like mpeg2dec,
videotestsrc, and the two x sinks, which should be enough to give you an
idea of what I'm trying to do.

With these patches, I have correctly scaled MPEG video when using
xvimagesink.

Also attached is a file with some notes and examples on why this needs
to be implemented.

Some things that could be up for discussion:

- theoradec should also set pixel-aspect-ratio; should be an easy fix

- for AVI, iirc the pixel aspect ratio is not described in the format;
typically it is guessed given a list of "known" input and output sizes

- videoscale should handle pixel aspect ratio conversions; David was
going to think about how this would be handled nicely

- I've added code to the X sinks to calculate the display pixel aspect
ratio through some X calls; I haven't hooked it up yet to the object's
property since I first want to check some X servers that do not have 1/1
PAR.  It seems that some X servers return wrong values.  The property
can be forced however through an object property, if you want to
experiment/debug

- David is convinced that GstFraction is overkill, and floats are
enough.  My argument is that going to a float loses the information of
which two integers you came from, making it impossible to figure out
what the intended target video size was supposed to be since you cannot
figure out anymore what possible WxH combinations are correct scaled
values of input WxH (ie, you cannot determine anymore which W-H values
are integer results of scaling)

In any case, I think (David ?) we both agree that using pixel_width and
pixel_height separately is a bad idea.  There's also no way to specify
ranges this way.

- I also looked at creating a GST_TYPE_RANGE that would be implemented
with a GArray with three members (lower, upper, increment).  A lot of
code would be the same as for the LIST type, and we could convert over
the GST_TYPE_INT_RANGE and GST_TYPE_DOUBLE_RANGE to it.  What do you
think ?

- A possible candidate for conversion to GstFraction would be framerate;
e.g. for MPEG using floats/doubles has forced the use of some hacks,
I've been told.

- Having an increment value in RANGE types would also be nice for
framerate for webcams or width/height for encoders.  For webcams,
allowed framerates are a multiple of 15/16, and for encoders, typically
multiples of 8 or 16 only are allowed.  In the case of webcams, being
able to specify 75/16 instead of 4.6875 seems like a plus to me.


Thomas 

Dave/Dina : future TV today ! - http://www.davedina.org/
<-*- thomas (dot) apestaart (dot) org -*->
cos when i needed someone
you left me floored
the feeling is gone
i can't let go
you know that i'd change if i had the love it takes
<-*- thomas (at) apestaart (dot) org -*->
URGent, best radio on the net - 24/7 ! - http://urgent.fm/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: core.patch
Type: text/x-patch
Size: 31690 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20040713/beed68a5/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plugins.patch
Type: text/x-patch
Size: 22334 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20040713/beed68a5/attachment-0001.bin>
-------------- next part --------------
1) playing DVD on 4:3 screen

PAL DVD:
 - video size in pixels: 720x576
 - intended physical aspect ratio: 4/3
 - pixel aspect ratio: 16/15

normal 4:3 computer screen:
  - screen size in pixels: 1024x768
  - physical aspect ratio: 4/3
  - pixel aspect ratio: 1/1

  -> scale to video size 720 . 16 / 576 . 15 =  11520 / 8640 = 144 / 108
     = 4 / 3

2) playing PAL DVD on PAL TV

PAL DVD:
 - video size in pixels: 720x576
 - pixel aspect ratio: 16/15

 => intended display aspect ratio: 4/3

   w/h = DAR/PAR (with w and h of pixel video size)

DirectFB PAL TV output:
  - screen size in pixels: 720x576
  - pixel aspect ratio: 16/15

  => display aspect ratio: 4/3

  (v = video, source material - d = display)
  DARv = DARd <=> wv / hv * PARv = wd / hd * PARd
              <=> wd / hd = wv / hv * (PARv / PARd)


4) playing an NTSC vob on PAL TV

NTSC VOB:
  - video size: 720x480
  - pixel aspect ratio: 8/9

  => intended DAR: DAR = 720/480 * 8/9 = 80 / 60 = 4 /3

  wd / hd = wv / hv * PARv / PARd
          = 720/480 * 8/9 / (16/15)
          = 720 * 8 * 15 / (480 * 9 * 16)
          = 120 * 1 * 5  / (80 * 3 * 2)
          = 15 / 12
          = 5 / 4

  --> 720 x ( 720 * 4 / 5) = 720 x 576



More information about the gstreamer-devel mailing list