World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Demuxing

Demuxers read a media file and split it into chunks of data (packets). A packet contains one or more encoded frames which belongs to a single elementary stream. In the lavf API this process is represented by the avformat_open_input() function for opening a file, av_read_frame() for reading a single packet and finally avformat_close_input(), which does the cleanup. Подробнее...

+ Граф связей класса Demuxing:

Классы

struct  AVInputFormat
 

Определения типов

typedef struct AVInputFormat AVInputFormat
 

Функции

ff_const59 AVInputFormatav_find_input_format (const char *short_name)
 
ff_const59 AVInputFormatav_probe_input_format (ff_const59 AVProbeData *pd, int is_opened)
 
ff_const59 AVInputFormatav_probe_input_format2 (ff_const59 AVProbeData *pd, int is_opened, int *score_max)
 
ff_const59 AVInputFormatav_probe_input_format3 (ff_const59 AVProbeData *pd, int is_opened, int *score_ret)
 
int av_probe_input_buffer2 (AVIOContext *pb, ff_const59 AVInputFormat **fmt, const char *url, void *logctx, unsigned int offset, unsigned int max_probe_size)
 
int av_probe_input_buffer (AVIOContext *pb, ff_const59 AVInputFormat **fmt, const char *url, void *logctx, unsigned int offset, unsigned int max_probe_size)
 
int avformat_open_input (AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
 
attribute_deprecated int av_demuxer_open (AVFormatContext *ic)
 
int avformat_find_stream_info (AVFormatContext *ic, AVDictionary **options)
 
AVProgramav_find_program_from_stream (AVFormatContext *ic, AVProgram *last, int s)
 
void av_program_add_stream_index (AVFormatContext *ac, int progid, unsigned int idx)
 
int av_find_best_stream (AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
 
int av_read_frame (AVFormatContext *s, AVPacket *pkt)
 
int av_seek_frame (AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
 
int avformat_seek_file (AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
 
int avformat_flush (AVFormatContext *s)
 
int av_read_play (AVFormatContext *s)
 
int av_read_pause (AVFormatContext *s)
 
void avformat_close_input (AVFormatContext **s)
 

Подробное описание

Demuxers read a media file and split it into chunks of data (packets). A packet contains one or more encoded frames which belongs to a single elementary stream. In the lavf API this process is represented by the avformat_open_input() function for opening a file, av_read_frame() for reading a single packet and finally avformat_close_input(), which does the cleanup.

Opening a media file

The minimum information required to open a file is its URL, which is passed to avformat_open_input(), as in the following code:

const char *url = "file:in.mp3";
int ret = avformat_open_input(&s, url, NULL, NULL);
if (ret < 0)
abort();

The above code attempts to allocate an AVFormatContext, open the specified file (autodetecting the format) and read the header, exporting the information stored there into s. Some formats do not have a header or do not store enough information there, so it is recommended that you call the avformat_find_stream_info() function which tries to read and decode a few frames to find missing information.

In some cases you might want to preallocate an AVFormatContext yourself with avformat_alloc_context() and do some tweaking on it before passing it to avformat_open_input(). One such case is when you want to use custom functions for reading input data instead of lavf internal I/O layer. To do that, create your own AVIOContext with avio_alloc_context(), passing your reading callbacks to it. Then set the pb field of your AVFormatContext to newly created AVIOContext.

Since the format of the opened file is in general not known until after avformat_open_input() has returned, it is not possible to set demuxer private options on a preallocated context. Instead, the options should be passed to avformat_open_input() wrapped in an AVDictionary:

AVDictionary *options = NULL;
av_dict_set(&options, "video_size", "640x480", 0);
av_dict_set(&options, "pixel_format", "rgb24", 0);
if (avformat_open_input(&s, url, NULL, &options) < 0)
abort();
av_dict_free(&options);

This code passes the private options 'video_size' and 'pixel_format' to the demuxer. They would be necessary for e.g. the rawvideo demuxer, since it cannot know how to interpret raw video data otherwise. If the format turns out to be something different than raw video, those options will not be recognized by the demuxer and therefore will not be applied. Such unrecognized options are then returned in the options dictionary (recognized options are consumed). The calling program can handle such unrecognized options as it wishes, e.g.

if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key);
abort();
}

After you have finished reading the file, you must close it with avformat_close_input(). It will free everything associated with the file.

Reading from an opened file

Reading data from an opened AVFormatContext is done by repeatedly calling av_read_frame() on it. Each call, if successful, will return an AVPacket containing encoded data for one AVStream, identified by AVPacket.stream_index. This packet may be passed straight into the libavcodec decoding functions avcodec_send_packet() or avcodec_decode_subtitle2() if the caller wishes to decode the data.

AVPacket.pts, AVPacket.dts and AVPacket.duration timing information will be set if known. They may also be unset (i.e. AV_NOPTS_VALUE for pts/dts, 0 for duration) if the stream does not provide them. The timing information will be in AVStream.time_base units, i.e. it has to be multiplied by the timebase to convert them to seconds.

If AVPacket.buf is set on the returned packet, then the packet is allocated dynamically and the user may keep it indefinitely. Otherwise, if AVPacket.buf is NULL, the packet data is backed by a static storage somewhere inside the demuxer and the packet is only valid until the next av_read_frame() call or closing the file. If the caller requires a longer lifetime, av_packet_make_refcounted() will ensure that the data is reference counted, copying the data if necessary. In both cases, the packet must be freed with av_packet_unref() when it is no longer needed.

Seeking

Типы

◆ AVInputFormat

Функции

◆ av_find_input_format()

ff_const59 AVInputFormat* av_find_input_format ( const char *  short_name)

◆ av_probe_input_format()

ff_const59 AVInputFormat* av_probe_input_format ( ff_const59 AVProbeData pd,
int  is_opened 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Guess the file format.

Аргументы
pddata to be probed
is_openedWhether the file is already opened; determines whether demuxers with or without AVFMT_NOFILE are probed.

◆ av_probe_input_format2()

ff_const59 AVInputFormat* av_probe_input_format2 ( ff_const59 AVProbeData pd,
int  is_opened,
int *  score_max 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Guess the file format.

Аргументы
pddata to be probed
is_openedWhether the file is already opened; determines whether demuxers with or without AVFMT_NOFILE are probed.
score_maxA probe score larger that this is required to accept a detection, the variable is set to the actual detection score afterwards. If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended to retry with a larger probe buffer.

◆ av_probe_input_format3()

ff_const59 AVInputFormat* av_probe_input_format3 ( ff_const59 AVProbeData pd,
int  is_opened,
int *  score_ret 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Guess the file format.

Аргументы
is_openedWhether the file is already opened; determines whether demuxers with or without AVFMT_NOFILE are probed.
score_retThe score of the best detection.

◆ av_probe_input_buffer2()

int av_probe_input_buffer2 ( AVIOContext pb,
ff_const59 AVInputFormat **  fmt,
const char *  url,
void logctx,
unsigned int  offset,
unsigned int  max_probe_size 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Probe a bytestream to determine the input format. Each time a probe returns with a score that is too low, the probe buffer size is increased and another attempt is made. When the maximum probe size is reached, the input format with the highest score is returned.

Аргументы
pbthe bytestream to probe
fmtthe input format is put here
urlthe url of the stream
logctxthe log context
offsetthe offset within the bytestream to probe from
max_probe_sizethe maximum probe buffer size (zero for default)
Возвращает
the score in case of success, a negative value corresponding to an the maximal score is AVPROBE_SCORE_MAX AVERROR code otherwise

◆ av_probe_input_buffer()

int av_probe_input_buffer ( AVIOContext pb,
ff_const59 AVInputFormat **  fmt,
const char *  url,
void logctx,
unsigned int  offset,
unsigned int  max_probe_size 
)

◆ avformat_open_input()

int avformat_open_input ( AVFormatContext **  ps,
const char *  url,
ff_const59 AVInputFormat fmt,
AVDictionary **  options 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Open an input stream and read the header. The codecs are not opened. The stream must be closed with avformat_close_input().

Аргументы
psPointer to user-supplied AVFormatContext (allocated by avformat_alloc_context). May be a pointer to NULL, in which case an AVFormatContext is allocated by this function and written into ps. Note that a user-supplied AVFormatContext will be freed on failure.
urlURL of the stream to open.
fmtIf non-NULL, this parameter forces a specific input format. Otherwise the format is autodetected.
optionsA dictionary filled with AVFormatContext and demuxer-private options. On return this parameter will be destroyed and replaced with a dict containing options that were not found. May be NULL.
Возвращает
0 on success, a negative AVERROR on failure.
Заметки
If you want to use custom IO, preallocate the format context and set its pb field.

Используется в Movie::Load(), AudioFileDataSource::Open() и AudioBufferDataSource::Open().

+ Граф вызова функции:

◆ av_demuxer_open()

◆ avformat_find_stream_info()

int avformat_find_stream_info ( AVFormatContext ic,
AVDictionary **  options 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Read packets of a media file to get stream information. This is useful for file formats with no headers such as MPEG. This function also computes the real framerate in case of MPEG-2 repeat frame mode. The logical file position is not changed by this function; examined packets may be buffered for later processing.

Аргументы
icmedia file handle
optionsIf non-NULL, an ic.nb_streams long array of pointers to dictionaries, where i-th member contains options for codec corresponding to i-th stream. On return each dictionary will be filled with options that were not found.
Возвращает
>=0 if OK, AVERROR_xxx on error
Заметки
this function isn't guaranteed to open all the codecs, so options being non-empty at return is a perfectly normal behavior.
Необходимо сделать:
Let the user decide somehow what information is needed so that we do not waste time getting stuff the user does not need.

Используется в Movie::Load() и AudioBaseDataSource::Open().

+ Граф вызова функции:

◆ av_find_program_from_stream()

AVProgram* av_find_program_from_stream ( AVFormatContext ic,
AVProgram last,
int  s 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Find the programs which belong to a given stream.

Аргументы
icmedia file handle
lastthe last found program, the search will start after this program, or from the beginning if it is NULL
sstream index
Возвращает
the next program which belongs to s, NULL if no program is found or the last program is not among the programs of ic.

◆ av_program_add_stream_index()

void av_program_add_stream_index ( AVFormatContext ac,
int  progid,
unsigned int  idx 
)

◆ av_find_best_stream()

int av_find_best_stream ( AVFormatContext ic,
enum AVMediaType  type,
int  wanted_stream_nb,
int  related_stream,
AVCodec **  decoder_ret,
int  flags 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Find the "best" stream in the file. The best stream is determined according to various heuristics as the most likely to be what the user expects. If the decoder parameter is non-NULL, av_find_best_stream will find the default decoder for the stream's codec; streams for which no decoder can be found are ignored.

Аргументы
icmedia file handle
typestream type: video, audio, subtitles, etc.
wanted_stream_nbuser-requested stream number, or -1 for automatic selection
related_streamtry to find a stream related (eg. in the same program) to this one, or -1 if none
decoder_retif non-NULL, returns the decoder for the selected stream
flagsflags; none are currently defined
Возвращает
the non-negative stream number in case of success, AVERROR_STREAM_NOT_FOUND if no stream with the requested type could be found, AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
Заметки
If av_find_best_stream returns successfully and decoder_ret is not NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.

Используется в AVStreamWrapper::open() и AudioBaseDataSource::Open().

+ Граф вызова функции:

◆ av_read_frame()

int av_read_frame ( AVFormatContext s,
AVPacket pkt 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Return the next frame of a stream. This function returns what is stored in the file, and does not validate that what is there are valid frames for the decoder. It will split what is stored in the file into frames and return one for each call. It will not omit invalid data between valid frames so as to give the decoder the maximum information possible for decoding.

If pkt->buf is NULL, then the packet is valid until the next av_read_frame() or until avformat_close_input(). Otherwise the packet is valid indefinitely. In both cases the packet must be freed with av_packet_unref when it is no longer needed. For video, the packet contains exactly one frame. For audio, it contains an integer number of frames if each frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames have a variable size (e.g. MPEG audio), then it contains one frame.

pkt->pts, pkt->dts and pkt->duration are always set to correct values in AVStream.time_base units (and guessed if the format cannot provide them). pkt->pts can be AV_NOPTS_VALUE if the video format has B-frames, so it is better to rely on pkt->dts if you do not decompress the payload.

Возвращает
0 if OK, < 0 on error or end of file

Используется в Movie::GetFrame() и AudioBaseDataSource::GetNextBuffer().

+ Граф вызова функции:

◆ av_seek_frame()

int av_seek_frame ( AVFormatContext s,
int  stream_index,
int64_t  timestamp,
int  flags 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Seek to the keyframe at timestamp. 'timestamp' in 'stream_index'.

Аргументы
smedia file handle
stream_indexIf stream_index is (-1), a default stream is selected, and timestamp is automatically converted from AV_TIME_BASE units to the stream specific time_base.
timestampTimestamp in AVStream.time_base units or, if no stream is specified, in AV_TIME_BASE units.
flagsflags which select direction and seeking mode
Возвращает
>= 0 on success

Используется в Movie::GetFrame().

+ Граф вызова функции:

◆ avformat_seek_file()

int avformat_seek_file ( AVFormatContext s,
int  stream_index,
int64_t  min_ts,
int64_t  ts,
int64_t  max_ts,
int  flags 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Seek to timestamp ts. Seeking will be done so that the point from which all active streams can be presented successfully will be closest to ts and within min/max_ts. Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.

If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and are the file position (this may not be supported by all demuxers). If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames in the stream with stream_index (this may not be supported by all demuxers). Otherwise all timestamps are in units of the stream selected by stream_index or if stream_index is -1, in AV_TIME_BASE units. If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as keyframes (this may not be supported by all demuxers). If flags contain AVSEEK_FLAG_BACKWARD, it is ignored.

Аргументы
smedia file handle
stream_indexindex of the stream which is used as time base reference
min_tssmallest acceptable timestamp
tstarget timestamp
max_tslargest acceptable timestamp
flagsflags
Возвращает
>=0 on success, error code otherwise
Заметки
This is part of the new seek API which is still under construction. Thus do not use this yet. It may change at any time, do not expect ABI compatibility yet!

◆ avformat_flush()

int avformat_flush ( AVFormatContext s)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Discard all internally buffered data. This can be useful when dealing with discontinuities in the byte stream. Generally works only with formats that can resync. This includes headerless formats like MPEG-TS/TS but should also work with NUT, Ogg and in a limited way AVI for example.

The set of streams, the detected duration, stream parameters and codecs do not change when calling this function. If you want a complete reset, it's better to open a new AVFormatContext.

This does not flush the AVIOContext (s->pb). If necessary, call avio_flush(s->pb) before calling this function.

Аргументы
smedia file handle
Возвращает
>=0 on success, error code otherwise

◆ av_read_play()

int av_read_play ( AVFormatContext s)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Start playing a network-based stream (e.g. RTSP stream) at the current position.

◆ av_read_pause()

int av_read_pause ( AVFormatContext s)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Pause a network-based stream (e.g. RTSP stream).

Use av_read_play() to resume it.

◆ avformat_close_input()

void avformat_close_input ( AVFormatContext **  s)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavformat/avformat.h>

Close an opened input AVFormatContext. Free it and all its contents and set *s to NULL.

Используется в AudioBaseDataSource::Close() и Movie::ReleaseAVCodec().

+ Граф вызова функции:
s
GLdouble s
Definition: SDL_opengl.h:2063
AVDictionaryEntry
Definition: dict.h:81
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
AVDictionaryEntry::key
char * key
Definition: dict.h:82
av_dict_free
void av_dict_free(AVDictionary **m)
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
AVFormatContext
Definition: avformat.h:1344
AVDictionary
struct AVDictionary AVDictionary
Definition: dict.h:86
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)