Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Codec.EBML
Description
This module is intended to be imported qualified:
import qualified Codec.EBML as EBML
Decode a webm file with:
EBML.decodeWebMFile "path/file.webm"
Split a webm stream segments with:
let streamReader = EBML.newStreamReader buf <- acquire data EBML.feedReader buf streamReader
References:
- EBML specification introduction: https://matroska-org.github.io/libebml/specs.html
- Document layout: https://www.matroska.org/technical/diagram.html
- The matroska schema: https://github.com/ietf-wg-cellar/matroska-specification/blob/master/ebml_matroska.xml
- The matroska schema doc: https://www.matroska.org/technical/elements.html
- The webm guidelines: https://www.webmproject.org/docs/container/
- The MSE byte stream format spec: https://w3c.github.io/media-source/index.html#byte-stream-format-specs
- The MSE byte stream format for webm: https://w3c.github.io/mse-byte-stream-format-webm/
Synopsis
- decodeWebM :: ByteString -> Either Text WebMDocument
- data WebMDocument = WebMDocument {
- timestampScale :: Word64
- clusters :: [WebMCluster]
- data WebMCluster = WebMCluster {
- timestamp :: Word64
- content :: [EBMLElement]
- decodeEBMLDocument :: [EBMLSchema] -> ByteString -> Either Text EBMLDocument
- webmSchemas :: [EBMLSchema]
- data StreamReader
- newStreamReader :: StreamReader
- data StreamFrame = StreamFrame {}
- feedReader :: ByteString -> StreamReader -> Either Text (Maybe StreamFrame, StreamReader)
- newtype EBMLDocument = EBMLDocument [EBMLElement]
- data EBMLElement = EBMLElement {}
- data EBMLValue
- data EBMLElementHeader = EBMLElementHeader {}
- newtype EBMLID = EBMLID Word32
- data EBMLSchema = EBMLSchema {
- name :: Text
- eid :: EBMLID
- decode :: EBMLSchemas -> EBMLElementHeader -> Get EBMLValue
- decodeEBMLFile :: [EBMLSchema] -> FilePath -> IO (Either Text EBMLDocument)
- decodeWebMFile :: FilePath -> IO (Either Text WebMDocument)
- prettyEBMLDocument :: [EBMLSchema] -> EBMLDocument -> Text
- data EBMLSchemas
- compileSchemas :: [EBMLSchema] -> EBMLSchemas
- getDocument :: EBMLSchemas -> Get EBMLDocument
- getElementHeader :: Get EBMLElementHeader
- getElementID :: Get EBMLID
- getDataSize :: Get Word64
- getElement :: EBMLSchemas -> Get EBMLElement
WebM decoder
decodeWebM :: ByteString -> Either Text WebMDocument Source #
Lazy decode a WebMDocument
.
data WebMDocument Source #
A WebM document.
Constructors
WebMDocument | |
Fields
|
data WebMCluster Source #
A WebM cluster, e.g. a media segment.
Constructors
WebMCluster | |
Fields
|
Raw EBML decoder
decodeEBMLDocument :: [EBMLSchema] -> ByteString -> Either Text EBMLDocument Source #
Lazy decode a EBMLDocument
.
webmSchemas :: [EBMLSchema] Source #
The webm document schemas.
EBML stream reader
data StreamReader Source #
Create a stream reader with newStreamReader
, and decode media segments with feedReader
.
newStreamReader :: StreamReader Source #
Initialize a stream reader.
data StreamFrame Source #
A valid frame that can be served.
Constructors
StreamFrame | |
Fields
|
feedReader :: ByteString -> StreamReader -> Either Text (Maybe StreamFrame, StreamReader) Source #
Feed data into a stream reader. Returns either an error, or maybe a new StreamFrame
and an updated StreamReader.
EBML data types
newtype EBMLDocument Source #
EBML document structure, including the Header and Body Root.
Constructors
EBMLDocument [EBMLElement] |
data EBMLElement Source #
EBML element.
Constructors
EBMLElement | |
Fields |
Instances
Show EBMLElement Source # | |
Defined in Codec.EBML.Element Methods showsPrec :: Int -> EBMLElement -> ShowS # show :: EBMLElement -> String # showList :: [EBMLElement] -> ShowS # | |
Eq EBMLElement Source # | |
Defined in Codec.EBML.Element |
EBML element value.
Constructors
EBMLRoot [EBMLElement] | |
EBMLSignedInteger Int64 | |
EBMLUnsignedInteger Word64 | |
EBMLFloat Double | |
EBMLText Text | |
EBMLDate Text | |
EBMLBinary ByteString |
data EBMLElementHeader Source #
EBML element header.
Constructors
EBMLElementHeader | |
Instances
Show EBMLElementHeader Source # | |
Defined in Codec.EBML.Element Methods showsPrec :: Int -> EBMLElementHeader -> ShowS # show :: EBMLElementHeader -> String # showList :: [EBMLElementHeader] -> ShowS # | |
Eq EBMLElementHeader Source # | |
Defined in Codec.EBML.Element Methods (==) :: EBMLElementHeader -> EBMLElementHeader -> Bool # (/=) :: EBMLElementHeader -> EBMLElementHeader -> Bool # |
EBML element id.
EBML schema data types
data EBMLSchema Source #
EBML schema definition.
Note that this is missing:
- min/max occurrence constraint.
- default value.
- element path.
Constructors
EBMLSchema | |
Fields
|
Helpers
decodeEBMLFile :: [EBMLSchema] -> FilePath -> IO (Either Text EBMLDocument) Source #
Decode a raw EBML file.
decodeWebMFile :: FilePath -> IO (Either Text WebMDocument) Source #
Decode a webm file.
prettyEBMLDocument :: [EBMLSchema] -> EBMLDocument -> Text Source #
Pretty-print a EBMLDocument
.
Low-level API, mostly for testing
data EBMLSchemas Source #
compileSchemas :: [EBMLSchema] -> EBMLSchemas Source #
Combine a list of schema for decoder.
getDocument :: EBMLSchemas -> Get EBMLDocument Source #
getElementID :: Get EBMLID Source #
getDataSize :: Get Word64 Source #
getElement :: EBMLSchemas -> Get EBMLElement Source #