Results 1 to 2 of 2

Thread: offscreen rendering to mpeg video?

  1. #1

    offscreen rendering to mpeg video?

    Hello,

    I'm using mesa's offscreen rendering facility to render
    frames (and currently writing them out to disk as tga files). However, I would like to instead write them out
    to an mpeg video file. There are some mpeg libraries
    around (like libfame for instance), but I'm not sure how
    to convert my buffered rgba data to the yuv12 format
    it requires- maybe there is a better library to use? At
    this point I can dump all the tga's to disk and then use
    a batch mpeg creation utility to generate mpegs, but
    this method is unacceptably slow (with all the disk writes
    for image files, and then only starting to create the
    mpeg after all rendering and simulation calculations
    have completed...)

    Has anyone been succesful with something like this? I'm
    open to suggestions, please help!

    scott olsson

  2. #2

    Re: offscreen rendering to mpeg video?

    Well, since noone replied to my question, and
    I've since figured it out myself, I'll run
    down how I eventually did this (it's pretty
    nifty).

    For starters, I used Mesa's offscreen rendering facility (which is similarly supported, although using different function
    calls, in new versions of opengl). When you
    offscreen render, it renders to a buffer
    of WIDTH*HEIGHT*4 unsigned bytes (4 since
    I was in rgba mode) which are linear mapped
    to the pixels going bottom (left) to top.

    I used libfame to do the actual mpeg packing,
    which has a pretty simple interface (only 3
    function calls to learn), the problem with
    it though is that you have to first convert
    your rgba data to yuv12 format. This is
    where it gets a bit more interesting.

    yv12 stores pixel data in a luminance/chrominance color space, rather
    than rgb. (luminance meaning how bright
    something is, chrominance meaning it's
    color value). Since human vision is more
    perceptive to changes in luminance than
    to changes in chrominance, you can subsample
    the chrominance values. In particular, yv12
    samples only ever other pixel (in x) and
    ever other line (in y), so one would say
    that the chrominance is downsampled by
    2x2. The luminance is not subsampled.

    Okay, so what does that garbage mean? Well,
    you have to run through your image buffer
    (from offscreen rendering context) which
    is linear mapped in bottom-up fashion, and
    convert rgb's to yuv data (which is stored
    in top-down fashion)- yuv12 however, is not
    stored with luminance (Y) and chrominance
    (Cr, Cb) values interleaved. Instead, they
    are mapped in planes. SO, the first WIDTH*HEIGHT unsigned bytes of your yuv12 buffer will be all the luminance (Y) values
    that you calculate from your rgba data, then
    the next (WIDTH/2 * HEIGHT/2) will be
    chrominance (U) values, and then another
    (WIDTH/2 * HEIGHT/2) for chrominance (V)
    values. You can find the rgb to yuv
    conversion formulas on the web easily
    enough- but _remember_, you will need
    to add a factor of 255 into the conversion,
    since your opengl rgb values are clamped
    between 0 and 1.

    Hope this helps anyone else trying to do
    this- have fun!

    scott olsson

Similar Threads

  1. Offscreen rendering
    By enigmagame in forum OpenGL: Advanced Coding
    Replies: 33
    Last Post: 12-15-2009, 12:18 PM
  2. Structure for MPEG -1/MPEG-2/MPEG-2.5 layer 2
    By jerrymannil in forum OpenMAX
    Replies: 0
    Last Post: 10-25-2007, 11:35 PM
  3. offscreen rendering
    By hArdJoB in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 07-20-2005, 01:52 PM
  4. Pb with offscreen rendering
    By PierreOlivier in forum OpenGL: User Software
    Replies: 0
    Last Post: 08-03-2000, 01:13 AM
  5. Structure for MPEG -1/MPEG-2/MPEG-2.5 layer 2
    By jerrymannil in forum OpenMAX
    Replies: 0
    Last Post: 12-31-1969, 07:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean