* Open an input stream and read the header. The codecs are not opened.
 * The stream must be closed with av_close_input_file().
 * @param ps Pointer 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.
 * @param filename Name of the stream to open.
 * @param fmt If non-NULL, this parameter forces a specific input format.
 *            Otherwise the format is autodetected.
 * @param options  A 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.
 * @return 0 on success, a negative AVERROR on failure.
 * @note If you want to use custom IO, preallocate the format context and set its pb field.
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);



int main() {
    // 这种写法是错误的
    // AVFormatContext *formatContext; 
    // 以下两种写法都可以
    // AVFormatContext *formatContext = NULL;
    AVFormatContext *formatContext = avformat_alloc_context();

    AVFormatContext *formatContext; 
    avformat_open_input(&formatContext, "foo.mp3", NULL, NULL);
    return 0;

Published: July 07 2013