To open a file and prepare it for decoding, the general procedure is
- (Optionally) call avbin_have_feature() to check which features are available. This is only needed if your application may be deployed in environments with older versions of AVbin than you are developing to.
- Initialize AVbin by calling avbin_init_options()
- Open a sound or video file using avbin_open_filename()
- Retrieve details of the file using avbin_file_info(). The resulting _AVbinFileInfo structure includes details such as:
- Start time and duration
- Number of audio and video streams
- Metadata such as title, artist, etc.
- Examine details of each stream using avbin_stream_info(), passing in each stream index as an integer from 0 to n_streams. For video streams, the _AVbinStreamInfo structure includes
- Video width and height, in pixels
- Pixel aspect ratio, expressed as a fraction For audio streams, the structure includes
- Sample rate, in Hz
- Bits per sample
- Channels (monoaural, stereo, or multichannel surround)
- For each stream you intend to decode, call avbin_open_stream().
When all information has been determined and the streams are open, you can proceed to read and decode the file:
- Call avbin_read() to read a packet of data from the file.
- Examine the resulting _AVbinPacket structure for the stream_index, which indicates how the packet should be decoded. If the stream is not one that you have opened, you can discard the packet and continue with step 1 again.
- To decode an audio packet, repeatedly pass the data within the packet to avbin_decode_audio(), until there is no data left to consume or an error is returned.
- To decode a video packet, pass the data within the packet to avbin_decode_video(), which will decode a single image in RGB format.
- Synchronise audio and video data by observing the _AVbinPacket::timestamp member.
When decoding is complete, call avbin_close_stream() on each stream and avbin_close_file() on the open file.