ffmpeg-light-0.3.1: Minimal bindings to the FFmpeg library.

Safe HaskellNone

Codec.FFmpeg

Contents

Description

Interface to initialize FFmpeg, decode video files, encode video files, and convert decoded image frames to JuicyPixels images.

Synopsis

Initialization

initFFmpeg :: IO ()Source

Initialize FFmpeg by registering all known codecs. This must be called before using other FFmpeg functions.

Decoding

frameReader :: (MonadIO m, Error e, MonadError e m) => FilePath -> m (IO (Maybe AVFrame), IO ())Source

Read RGB frames from a video stream.

frameReaderT :: (Functor m, MonadIO m, Error e, MonadError e m) => FilePath -> m (MaybeT IO AVFrame, IO ())Source

Read RGB frames with the result in the MaybeT transformer.

 frameReaderT = fmap (first MaybeT) . frameReader

frameReaderTime :: (MonadIO m, Error e, MonadError e m) => FilePath -> m (IO (Maybe (AVFrame, Double)), IO ())Source

Read time stamped RGB frames from a video stream. Time is given in seconds from the start of the stream.

frameReaderTimeT :: (Functor m, MonadIO m, Error e, MonadError e m) => FilePath -> m (MaybeT IO (AVFrame, Double), IO ())Source

Read time stamped RGB frames with the result in the MaybeT transformer.

 frameReaderT = fmap (first MaybeT) . frameReader

Encoding

data EncodingParams Source

Minimal parameters describing the desired video output.

Constructors

EncodingParams 

Fields

epWidth :: CInt
 
epHeight :: CInt
 
epFps :: Int
 
epCodec :: Maybe AVCodecID

If Nothing, then the codec is inferred from the output file name. If Just, then this codec is manually chosen.

epPreset :: String
 

defaultParams :: CInt -> CInt -> EncodingParamsSource

Use default parameters for a video of the given width and height. The output format is determined by the output file name.

frameWriter :: EncodingParams -> FilePath -> IO (Maybe (Vector CUChar) -> IO ())Source

Open a target file for writing a video stream. The function returned may be used to write RGB images of the resolution given by the provided EncodingParams. The function will convert the supplied RGB frame to YUV (specifically, yuv420p) before encoding the image to the video stream. If this function is applied to Nothing, then the output stream is closed. Note that Nothing must be provided to properly terminate video encoding.

JuicyPixels interop

toJuicyT :: AVFrame -> MaybeT IO DynamicImageSource

Convert an AVFrame to a DynamicImage with the result in the MaybeT transformer.

 toJuicyT = MaybeT . toJuicy

saveJuicy :: FilePath -> AVFrame -> IO ()Source

Save an AVFrame to a PNG file on disk assuming the frame could be converted to a DynamicImage using toJuicy.

Types and Enums