@@ -46,9 +46,79 @@ DOCKER_REGISTRY=ghcr.io/mutablelogic make docker
4646
4747## Examples
4848
49- ## Media Transcoding
49+ There are a variety of types of object needed as part of media processing.
50+ All examples require a ` Manager ` to be created, which is used to enumerate all supported formats
51+ and open media files and byte streams.
52+
53+ * ` Manager ` is the main entry point for the package. It is used to open media files and byte streams,
54+ and enumerate supported formats, codecs, pixel formats, etc.
55+ * ` Media ` is a hardware device, file or byte stream. It contains metadata, artwork, and streams.
56+ * ` Decoder ` is used to demultiplex media streams. Create a decoder and enumerate the streams which
57+ you'd like to demultiplex. Provide the audio and video parameters if you want to resample or
58+ reformat the streams.
59+ * ` Encoder ` is used to multiplex media streams. Create an encoder and send the output of the
60+ decoder to reencode the streams.
61+
62+ ### Demultiplexing
63+
64+ ``` go
65+ import (
66+ media " github.com/mutablelogic/go-media"
67+ )
68+
69+ func main () {
70+ manager := media.NewManager ()
71+
72+ // Open a media file for reading. The format of the file is guessed.
73+ // Alteratively, you can pass a format as the second argument. Further optional
74+ // arguments can be used to set the format options.
75+ file , err := manager.Open (os.Args [1 ], nil )
76+ if err != nil {
77+ log.Fatal (err)
78+ }
79+ defer file.Close ()
80+
81+ // Choose which streams to demultiplex - pass the stream parameters
82+ // to the decoder. If you don't want to resample or reformat the streams,
83+ // then you can pass nil as the function and all streams will be demultiplexed.
84+ decoder , err := file.Decoder (func (stream media.Stream ) (media.Parameters , error ) {
85+ return stream.Parameters (), nil
86+ }
87+ if err != nil {
88+ log.Fatal (err)
89+ }
90+
91+ // Demuliplex the stream and receive the packets. If you don't want to
92+ // process the packets yourself, then you can pass nil as the function
93+ if err := decoder.Demux (context.Background (), func (_ media.Packet ) error {
94+ // Each packet is specific to a stream. It can be processed here
95+ // to receive audio or video frames, then resize or resample them,
96+ // for example. Alternatively, you can pass the packet to an encoder
97+ // to remultiplex the streams without processing them.
98+ return nil
99+ }); err != nil {
100+ log.Fatal (err)
101+ })
102+ }
103+ ```
104+
105+ ### Decoding
106+
107+ TODO
108+
109+ ### Encoding
110+
111+ TODO
50112
51- ## Audio Fingerprinting
113+ ### Multiplexing
114+
115+ TODO
116+
117+ ### Retrieving Metadata and Artwork from a media file
118+
119+ TODO
120+
121+ ### Audio Fingerprinting
52122
53123You can programmatically fingerprint audio files, compare fingerprints and identify music using the following packages:
54124
@@ -73,5 +143,4 @@ repository for more information:
73143
74144## References
75145
76- * https://ffmpeg.org/doxygen/6.1/index.html
77-
146+ * https://ffmpeg.org/doxygen/6.1/index.html
0 commit comments