Ticket #1218: GStreamer.hs

File GStreamer.hs, 1.0 kB (added by guest, 3 years ago)

Sample Haskell program

Line 
1import Data.Ratio ( Ratio, (%) )
2import Data.Bits  ( (.|.), shiftL )
3import Data.Char  ( ord )
4import Data.Word  ( Word32 )
5import qualified Media.Streaming.GStreamer as Gst
6
7type FourCC   = Word32
8type Fraction = Ratio Int
9
10makeFourCC :: (Char, Char, Char, Char) -> FourCC
11makeFourCC (a,b,c,d) = a' .|. b' .|. c' .|. d'
12  where
13    a', b', c', d' :: Word32
14    a' = ord' a
15    b' = ord' b `shiftL` 8
16    c' = ord' c `shiftL` 16
17    d' = ord' d `shiftL` 24
18
19    ord' = fromIntegral . ord
20
21filename :: FilePath
22filename = "uvc_640x480.yuy2"
23
24buildStructure :: Gst.Structure
25buildStructure = fst . Gst.structureCreate "video/x-raw-rgb" $ do
26    Gst.structureSetFourCCM "format" (makeFourCC ('Y', 'U', 'Y', '2'))
27    Gst.structureSetFractionM "framerate" (10 % 1)
28    Gst.structureSetIntM "width" 640
29    Gst.structureSetIntM "height" 480
30
31
32buildCaps :: Gst.Caps
33buildCaps = fst . Gst.capsCreate $ Gst.capsAppendStructure buildStructure
34
35main :: IO ()
36main = do
37    Gst.init
38    putStrLn $ Gst.structureToString buildStructure
39    putStrLn $ Gst.capsToString buildCaps