What does the avformat_open_input() do?
16,915
Solution 1
The main things that gets done in file_open are
- Allocate memory for AVFormatContext.
- Read the probe_size about of data from the file (input url)
- Tries to guess the input file format, codec parameter for the input file. This is done by calling read_probe function pointer for each of the demuxer
- Allocate the codec context, demuxed context, I/O context.
Solution 2
You can look it up in FFmpeg's libavformat\utils.c
what is really taking place there:
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
{
AVFormatContext *s = *ps;
int ret = 0;
AVDictionary *tmp = NULL;
ID3v2ExtraMeta *id3v2_extra_meta = NULL;
if (!s && !(s = avformat_alloc_context()))
return AVERROR(ENOMEM);
// on and on

Comments
-
progammer 10 months
I am following this code to work with FFmpeg library in C. FFmpeg library has very little documentation and it is difficult to understand what each function exactly does.
I understand the code (what is being done). But I am lacking clarity. Can anyone help me out please?
Q1) A **struct AVFrameContext **** and filename (the minimum non-NULL parameters required) are passed to the function avformat_open_input(). As the name suggests, the input file is 'opened'. How ?
-
progammer over 10 yearsThanks for the answer .. :)
-
progammer over 10 yearsI read in this link that - "The function allocates an AVFormatContext, opens the specified file (autodetecting the format) and reads the header, exporting the information stored there into the pointer that we passed". What is header in a file ? Is it the first few bytes of the file ? Is the size of header fixed ? Is the information about probe_size in the header ?
-
progammer over 10 yearsThanks for your answer . Can you elaborate it a little ? :)
-
rajneesh over 10 yearsheader is the muxed file header e.g flv header, mp4 header, avi header. The information in header is specific to file format. The probe size is a command line parameter of ffmpeg "-probesize". This is the amount of data used by ffmpeg to autodetect the file format and other information (codec,width,height ....)
-
progammer over 10 yearsprobe_size means the amount of data that the function decides to 'read' from the opened file inorder to detect some important stuff , right ? Is it fixed ?
-
rajneesh over 10 yearsyour interpretation is correct.it has a default value, you can pass "-probesize" commandline parameter to change it.
-
progammer over 10 yearsThanks for the help .. :) The information you provided sure cleared few doubts :)