Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
e253a9e2
F
Ffmpeg
项目概览
小白菜888
/
Ffmpeg
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Ffmpeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e253a9e2
编写于
3月 13, 2014
作者:
L
Luca Barbato
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avformat: Move av_probe_input* to format.c
上级
942269fd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
138 addition
and
136 deletion
+138
-136
libavformat/format.c
libavformat/format.c
+138
-1
libavformat/utils.c
libavformat/utils.c
+0
-135
未找到文件。
libavformat/format.c
浏览文件 @
e253a9e2
...
...
@@ -19,9 +19,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/avstring.h"
#include "avio_internal.h"
#include "avformat.h"
#include "id3v2.h"
#include "internal.h"
#include "libavutil/avstring.h"
/**
* @file
...
...
@@ -181,3 +184,137 @@ AVInputFormat *av_find_input_format(const char *short_name)
return
fmt
;
return
NULL
;
}
AVInputFormat
*
av_probe_input_format2
(
AVProbeData
*
pd
,
int
is_opened
,
int
*
score_max
)
{
AVProbeData
lpd
=
*
pd
;
AVInputFormat
*
fmt1
=
NULL
,
*
fmt
;
int
score
,
id3
=
0
;
if
(
lpd
.
buf_size
>
10
&&
ff_id3v2_match
(
lpd
.
buf
,
ID3v2_DEFAULT_MAGIC
))
{
int
id3len
=
ff_id3v2_tag_len
(
lpd
.
buf
);
if
(
lpd
.
buf_size
>
id3len
+
16
)
{
lpd
.
buf
+=
id3len
;
lpd
.
buf_size
-=
id3len
;
}
id3
=
1
;
}
fmt
=
NULL
;
while
((
fmt1
=
av_iformat_next
(
fmt1
)))
{
if
(
!
is_opened
==
!
(
fmt1
->
flags
&
AVFMT_NOFILE
))
continue
;
score
=
0
;
if
(
fmt1
->
read_probe
)
{
score
=
fmt1
->
read_probe
(
&
lpd
);
}
else
if
(
fmt1
->
extensions
)
{
if
(
av_match_ext
(
lpd
.
filename
,
fmt1
->
extensions
))
score
=
AVPROBE_SCORE_EXTENSION
;
}
if
(
score
>
*
score_max
)
{
*
score_max
=
score
;
fmt
=
fmt1
;
}
else
if
(
score
==
*
score_max
)
fmt
=
NULL
;
}
// A hack for files with huge id3v2 tags -- try to guess by file extension.
if
(
!
fmt
&&
is_opened
&&
*
score_max
<
AVPROBE_SCORE_EXTENSION
/
2
)
{
while
((
fmt
=
av_iformat_next
(
fmt
)))
if
(
fmt
->
extensions
&&
av_match_ext
(
lpd
.
filename
,
fmt
->
extensions
))
{
*
score_max
=
AVPROBE_SCORE_EXTENSION
/
2
;
break
;
}
}
if
(
!
fmt
&&
id3
&&
*
score_max
<
AVPROBE_SCORE_EXTENSION
/
2
-
1
)
{
while
((
fmt
=
av_iformat_next
(
fmt
)))
if
(
fmt
->
extensions
&&
av_match_ext
(
"mp3"
,
fmt
->
extensions
))
{
*
score_max
=
AVPROBE_SCORE_EXTENSION
/
2
-
1
;
break
;
}
}
return
fmt
;
}
AVInputFormat
*
av_probe_input_format
(
AVProbeData
*
pd
,
int
is_opened
)
{
int
score
=
0
;
return
av_probe_input_format2
(
pd
,
is_opened
,
&
score
);
}
/* size of probe buffer, for guessing file type from file contents */
#define PROBE_BUF_MIN 2048
#define PROBE_BUF_MAX (1 << 20)
int
av_probe_input_buffer
(
AVIOContext
*
pb
,
AVInputFormat
**
fmt
,
const
char
*
filename
,
void
*
logctx
,
unsigned
int
offset
,
unsigned
int
max_probe_size
)
{
AVProbeData
pd
=
{
filename
?
filename
:
""
};
uint8_t
*
buf
=
NULL
;
int
ret
=
0
,
probe_size
;
if
(
!
max_probe_size
)
max_probe_size
=
PROBE_BUF_MAX
;
else
if
(
max_probe_size
>
PROBE_BUF_MAX
)
max_probe_size
=
PROBE_BUF_MAX
;
else
if
(
max_probe_size
<
PROBE_BUF_MIN
)
return
AVERROR
(
EINVAL
);
if
(
offset
>=
max_probe_size
)
return
AVERROR
(
EINVAL
);
avio_skip
(
pb
,
offset
);
max_probe_size
-=
offset
;
for
(
probe_size
=
PROBE_BUF_MIN
;
probe_size
<=
max_probe_size
&&
!*
fmt
;
probe_size
=
FFMIN
(
probe_size
<<
1
,
FFMAX
(
max_probe_size
,
probe_size
+
1
)))
{
int
score
=
probe_size
<
max_probe_size
?
AVPROBE_SCORE_MAX
/
4
:
0
;
/* Read probe data. */
if
((
ret
=
av_reallocp
(
&
buf
,
probe_size
+
AVPROBE_PADDING_SIZE
))
<
0
)
return
ret
;
if
((
ret
=
avio_read
(
pb
,
buf
+
pd
.
buf_size
,
probe_size
-
pd
.
buf_size
))
<
0
)
{
/* Fail if error was not end of file, otherwise, lower score. */
if
(
ret
!=
AVERROR_EOF
)
{
av_free
(
buf
);
return
ret
;
}
score
=
0
;
ret
=
0
;
/* error was end of file, nothing read */
}
pd
.
buf_size
+=
ret
;
pd
.
buf
=
buf
;
memset
(
pd
.
buf
+
pd
.
buf_size
,
0
,
AVPROBE_PADDING_SIZE
);
/* Guess file format. */
*
fmt
=
av_probe_input_format2
(
&
pd
,
1
,
&
score
);
if
(
*
fmt
)
{
/* This can only be true in the last iteration. */
if
(
score
<=
AVPROBE_SCORE_MAX
/
4
)
{
av_log
(
logctx
,
AV_LOG_WARNING
,
"Format detected only with low score of %d, "
"misdetection possible!
\n
"
,
score
);
}
else
av_log
(
logctx
,
AV_LOG_DEBUG
,
"Probed with size=%d and score=%d
\n
"
,
probe_size
,
score
);
}
}
if
(
!*
fmt
)
{
av_free
(
buf
);
return
AVERROR_INVALIDDATA
;
}
/* Rewind. Reuse probe buffer to avoid seeking. */
if
((
ret
=
ffio_rewind_with_probe_data
(
pb
,
buf
,
pd
.
buf_size
))
<
0
)
av_free
(
buf
);
return
ret
;
}
libavformat/utils.c
浏览文件 @
e253a9e2
...
...
@@ -41,7 +41,6 @@
#include "audiointerleave.h"
#include "avformat.h"
#include "avio_internal.h"
#include "id3v2.h"
#include "internal.h"
#include "metadata.h"
...
...
@@ -139,67 +138,6 @@ int av_filename_number_test(const char *filename)
(
av_get_frame_filename
(
buf
,
sizeof
(
buf
),
filename
,
1
)
>=
0
);
}
AVInputFormat
*
av_probe_input_format2
(
AVProbeData
*
pd
,
int
is_opened
,
int
*
score_max
)
{
AVProbeData
lpd
=
*
pd
;
AVInputFormat
*
fmt1
=
NULL
,
*
fmt
;
int
score
,
id3
=
0
;
if
(
lpd
.
buf_size
>
10
&&
ff_id3v2_match
(
lpd
.
buf
,
ID3v2_DEFAULT_MAGIC
))
{
int
id3len
=
ff_id3v2_tag_len
(
lpd
.
buf
);
if
(
lpd
.
buf_size
>
id3len
+
16
)
{
lpd
.
buf
+=
id3len
;
lpd
.
buf_size
-=
id3len
;
}
id3
=
1
;
}
fmt
=
NULL
;
while
((
fmt1
=
av_iformat_next
(
fmt1
)))
{
if
(
!
is_opened
==
!
(
fmt1
->
flags
&
AVFMT_NOFILE
))
continue
;
score
=
0
;
if
(
fmt1
->
read_probe
)
{
score
=
fmt1
->
read_probe
(
&
lpd
);
}
else
if
(
fmt1
->
extensions
)
{
if
(
av_match_ext
(
lpd
.
filename
,
fmt1
->
extensions
))
score
=
AVPROBE_SCORE_EXTENSION
;
}
if
(
score
>
*
score_max
)
{
*
score_max
=
score
;
fmt
=
fmt1
;
}
else
if
(
score
==
*
score_max
)
fmt
=
NULL
;
}
// A hack for files with huge id3v2 tags -- try to guess by file extension.
if
(
!
fmt
&&
is_opened
&&
*
score_max
<
AVPROBE_SCORE_EXTENSION
/
2
)
{
while
((
fmt
=
av_iformat_next
(
fmt
)))
if
(
fmt
->
extensions
&&
av_match_ext
(
lpd
.
filename
,
fmt
->
extensions
))
{
*
score_max
=
AVPROBE_SCORE_EXTENSION
/
2
;
break
;
}
}
if
(
!
fmt
&&
id3
&&
*
score_max
<
AVPROBE_SCORE_EXTENSION
/
2
-
1
)
{
while
((
fmt
=
av_iformat_next
(
fmt
)))
if
(
fmt
->
extensions
&&
av_match_ext
(
"mp3"
,
fmt
->
extensions
))
{
*
score_max
=
AVPROBE_SCORE_EXTENSION
/
2
-
1
;
break
;
}
}
return
fmt
;
}
AVInputFormat
*
av_probe_input_format
(
AVProbeData
*
pd
,
int
is_opened
)
{
int
score
=
0
;
return
av_probe_input_format2
(
pd
,
is_opened
,
&
score
);
}
static
int
set_codec_from_probe_data
(
AVFormatContext
*
s
,
AVStream
*
st
,
AVProbeData
*
pd
,
int
score
)
{
...
...
@@ -241,79 +179,6 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st,
/************************************************************/
/* input media file */
/** size of probe buffer, for guessing file type from file contents */
#define PROBE_BUF_MIN 2048
#define PROBE_BUF_MAX (1 << 20)
int
av_probe_input_buffer
(
AVIOContext
*
pb
,
AVInputFormat
**
fmt
,
const
char
*
filename
,
void
*
logctx
,
unsigned
int
offset
,
unsigned
int
max_probe_size
)
{
AVProbeData
pd
=
{
filename
?
filename
:
""
};
uint8_t
*
buf
=
NULL
;
int
ret
=
0
,
probe_size
;
if
(
!
max_probe_size
)
max_probe_size
=
PROBE_BUF_MAX
;
else
if
(
max_probe_size
>
PROBE_BUF_MAX
)
max_probe_size
=
PROBE_BUF_MAX
;
else
if
(
max_probe_size
<
PROBE_BUF_MIN
)
return
AVERROR
(
EINVAL
);
if
(
offset
>=
max_probe_size
)
return
AVERROR
(
EINVAL
);
avio_skip
(
pb
,
offset
);
max_probe_size
-=
offset
;
for
(
probe_size
=
PROBE_BUF_MIN
;
probe_size
<=
max_probe_size
&&
!*
fmt
;
probe_size
=
FFMIN
(
probe_size
<<
1
,
FFMAX
(
max_probe_size
,
probe_size
+
1
)))
{
int
score
=
probe_size
<
max_probe_size
?
AVPROBE_SCORE_MAX
/
4
:
0
;
/* Read probe data. */
if
((
ret
=
av_reallocp
(
&
buf
,
probe_size
+
AVPROBE_PADDING_SIZE
))
<
0
)
return
ret
;
if
((
ret
=
avio_read
(
pb
,
buf
+
pd
.
buf_size
,
probe_size
-
pd
.
buf_size
))
<
0
)
{
/* Fail if error was not end of file, otherwise, lower score. */
if
(
ret
!=
AVERROR_EOF
)
{
av_free
(
buf
);
return
ret
;
}
score
=
0
;
ret
=
0
;
/* error was end of file, nothing read */
}
pd
.
buf_size
+=
ret
;
pd
.
buf
=
buf
;
memset
(
pd
.
buf
+
pd
.
buf_size
,
0
,
AVPROBE_PADDING_SIZE
);
/* Guess file format. */
*
fmt
=
av_probe_input_format2
(
&
pd
,
1
,
&
score
);
if
(
*
fmt
)
{
/* This can only be true in the last iteration. */
if
(
score
<=
AVPROBE_SCORE_MAX
/
4
)
{
av_log
(
logctx
,
AV_LOG_WARNING
,
"Format detected only with low score of %d, "
"misdetection possible!
\n
"
,
score
);
}
else
av_log
(
logctx
,
AV_LOG_DEBUG
,
"Probed with size=%d and score=%d
\n
"
,
probe_size
,
score
);
}
}
if
(
!*
fmt
)
{
av_free
(
buf
);
return
AVERROR_INVALIDDATA
;
}
/* Rewind. Reuse probe buffer to avoid seeking. */
if
((
ret
=
ffio_rewind_with_probe_data
(
pb
,
buf
,
pd
.
buf_size
))
<
0
)
av_free
(
buf
);
return
ret
;
}
/* Open input file and probe the format if necessary. */
static
int
init_input
(
AVFormatContext
*
s
,
const
char
*
filename
,
AVDictionary
**
options
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录