调用av_open_input_file
(
&
pFormatCtx
,
is
-
>
filename
,
NULL
,
0
,
NULL
)
函数打开输入的文件
.
1
.
分析一下函数原型
:
int
av_open_input_file
(
AVFormatContext
*
*
ic_ptr
,
// 输出参数: 格式上下文
const
char
*
filename
,
// 文件名
AVInputFormat
*
fmt
,
// 输入的格式, 为NULL, 即未知
int
buf_size
,
// 缓冲的大小, 为0
AVFormatParameters
*
ap
)
;
// 格式的参数, 为NULL
2
.
初始化探测数据
:
AVProbeData probe_data
,
*
pd
=
&
probe_data
;
pd
-
>
filename
=
""
;
if
(
filename
)
pd
-
>
filename
=
filename
;
pd
-
>
buf
=
NULL
;
pd
-
>
buf_size
=
0
;
3
.
探测输入的格式
:
if
(
!
fmt
)
{
// fmt == NULL, 成立
fmt
=
av_probe_input_format
(
pd
,
0
)
;
}
进入av_probe_input_format函数
:
AVInputFormat
*
av_probe_input_format
(
AVProbeData
*
pd
,
int
is_opened
)
{
int
score
=
0
;
return
av_probe_input_format2
(
pd
,
is_opened
,
&
score
)
;
}
进入av_probe_input_format2函数
:
AVInputFormat
*
av_probe_input_format2
(
AVProbeData
*
pd
,
int
is_opened
,
int
*
score_max
)
{
AVInputFormat
*
fmt1
,
*
fmt
;
int
score
;
fmt
=
NULL
;
for
(
fmt1
=
first_iformat
;
fmt1
!
=
NULL
;
fmt1
=
fmt1
-
>
next
)
{
if
(
!
is_opened
=
=
!
(
fmt1
-
>
flags
&
AVFMT_NOFILE
)
)
// is_opened == 0, fmt1->flags 没有设置 AVFMT_NOFILE 标志时成立
continue
;
/* 省略部分代码 */
}
见libavformat
/
raw
.
c文件
:
AVInputFormat h264_demuxer
=
{
"h264"
,
NULL_IF_CONFIG_SMALL
(
"raw H.264 video format"
)
,
0
,
h264_probe
,
video_read_header
,
ff_raw_read_partial_packet
,
.
flags
=
AVFMT_GENERIC_INDEX
,
.
extensions
=
"h26l,h264,264"
,
//FIXME remove after writing mpeg4_probe
.
value
=
CODEC_ID_H264
,
}
;
由于 h264_demuxer
.
flags
=
=
AVFMT_GENERIC_INDEX
,
所以上面成立
,
continue
,
返回的 AVInputFormat 指针为
NULL, 探测不成功
.