This module calls the libtheora C library to generate video ogg files from YCbCr images. As explained on http://theora.org/doc/libtheora-1.0/group__encfuncs.html, the basic steps for creating a video are the following :
- create in an
Info
record - call
encodeAlloc
on it - call
flushHeader
until it returnsNothing
- For each uncompressed frame, submit it with
encodeIn
, then retrieve potential packets withencodeOut
- data Info = Info {
- frameWidth :: Int32
- frameHeight :: Int32
- picWidth :: Int32
- picHeight :: Int32
- picX :: Int32
- picY :: Int32
- colorSpace :: ColorSpace
- pixelFmt :: PixelFmt
- targetBitRate :: CInt
- quality :: CInt
- keyframeGranuleShift :: CInt
- data Comment = Comment {}
- data PixelFmt
- data ColorSpace
- = Unspecified
- | ItuRec470M
- | ItuRec470BG
- encodeAlloc :: Info -> IO (Maybe EncCtx)
- flushHeader :: EncCtx -> Comment -> IO [OggPacket]
- data ImgPlane
- data YCbCrBuffer = YCbCr {}
- newYCbCr :: Int -> Int -> PixelFmt -> IO YCbCrBuffer
- encodeIn :: EncCtx -> YCbCrBuffer -> IO ()
- encodeOut :: EncCtx -> Bool -> IO [OggPacket]
- data OggPacket
- newOggStreamState :: Int -> IO OggStreamState
- data OggPage
- streamPacketIn :: OggStreamState -> OggPacket -> IO ()
- streamPageOut :: OggStreamState -> IO (Maybe OggPage)
- streamFlush :: OggStreamState -> IO (Maybe OggPage)
Theora structures and function
Info | |
|
Theora supports 4 different pixel formats, listed in http://theora.org/doc/Theora.pdf. YCbCr chroma frames (Cb and Cr) may be resized for compression (see http://en.wikipedia.org/Ycbcr). The resulting pixel formats are as follows :
data ColorSpace Source
Unspecified | |
ItuRec470M | A color space designed for NTSC content |
ItuRec470BG | A color space designed for PAL/SECAM content |
encodeAlloc :: Info -> IO (Maybe EncCtx)Source
Makes an encoder (EncCtx
) instance out of an Info
record
flushHeader :: EncCtx -> Comment -> IO [OggPacket]Source
Returns the last header packets. This function should be called before encoding actual video.
data YCbCrBuffer Source
YCbCrBuffer
is the type of raw YCbCr frames
encodeIn :: EncCtx -> YCbCrBuffer -> IO ()Source
Submits a frame for encoding
Ogg-related functions
newOggStreamState :: Int -> IO OggStreamStateSource
Initializes an Ogg container stream
streamPacketIn :: OggStreamState -> OggPacket -> IO ()Source
Submits an encoded packet into the streams
streamPageOut :: OggStreamState -> IO (Maybe OggPage)Source
Get an outputable Ogg page
streamFlush :: OggStreamState -> IO (Maybe OggPage)Source
Retrieve the last pages of the stream