Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
05e84c95
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,发现更多精彩内容 >>
提交
05e84c95
编写于
5月 22, 2011
作者:
A
Anton Khirnov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lavf: add avformat_open_input() as a replacement for av_open_input_*
Add support for demuxer private options.
上级
dc59ec5e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
153 addition
and
1 deletion
+153
-1
libavformat/avformat.h
libavformat/avformat.h
+22
-0
libavformat/options.c
libavformat/options.c
+28
-0
libavformat/utils.c
libavformat/utils.c
+103
-1
未找到文件。
libavformat/avformat.h
浏览文件 @
05e84c95
...
...
@@ -730,6 +730,7 @@ typedef struct AVFormatContext {
#if FF_API_FLAG_RTP_HINT
#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
#endif
#define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
int
loop_input
;
...
...
@@ -1040,6 +1041,27 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
int
buf_size
,
AVFormatParameters
*
ap
);
/**
* 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
);
/**
* Allocate an AVFormatContext.
* avformat_free_context() can be used to free the context and everything
...
...
libavformat/options.c
浏览文件 @
05e84c95
...
...
@@ -33,6 +33,33 @@ static const char* format_to_name(void* ptr)
else
return
"NULL"
;
}
static
const
AVOption
*
opt_find
(
void
*
obj
,
const
char
*
name
,
const
char
*
unit
,
int
opt_flags
,
int
search_flags
)
{
AVFormatContext
*
s
=
obj
;
AVInputFormat
*
ifmt
=
NULL
;
AVOutputFormat
*
ofmt
=
NULL
;
if
(
s
->
priv_data
)
{
if
((
s
->
iformat
&&
!
s
->
iformat
->
priv_class
)
||
(
s
->
oformat
&&
!
s
->
oformat
->
priv_class
))
return
NULL
;
return
av_opt_find
(
s
->
priv_data
,
name
,
unit
,
opt_flags
,
search_flags
);
}
while
((
ifmt
=
av_iformat_next
(
ifmt
)))
{
const
AVOption
*
o
;
if
(
ifmt
->
priv_class
&&
(
o
=
av_opt_find
(
&
ifmt
->
priv_class
,
name
,
unit
,
opt_flags
,
search_flags
)))
return
o
;
}
while
((
ofmt
=
av_oformat_next
(
ofmt
)))
{
const
AVOption
*
o
;
if
(
ofmt
->
priv_class
&&
(
o
=
av_opt_find
(
&
ofmt
->
priv_class
,
name
,
unit
,
opt_flags
,
search_flags
)))
return
o
;
}
return
NULL
;
}
#define OFFSET(x) offsetof(AVFormatContext,x)
#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
//these names are too long to be readable
...
...
@@ -72,6 +99,7 @@ static const AVClass av_format_context_class = {
.
item_name
=
format_to_name
,
.
option
=
options
,
.
version
=
LIBAVUTIL_VERSION_INT
,
.
opt_find
=
opt_find
,
};
static
void
avformat_get_context_defaults
(
AVFormatContext
*
s
)
...
...
libavformat/utils.c
浏览文件 @
05e84c95
...
...
@@ -605,6 +605,107 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
}
/* open input file and probe the format if necessary */
static
int
init_input
(
AVFormatContext
*
s
,
const
char
*
filename
)
{
int
ret
;
AVProbeData
pd
=
{
filename
,
NULL
,
0
};
if
(
s
->
pb
)
{
s
->
flags
|=
AVFMT_FLAG_CUSTOM_IO
;
if
(
!
s
->
iformat
)
return
av_probe_input_buffer
(
s
->
pb
,
&
s
->
iformat
,
filename
,
s
,
0
,
0
);
else
if
(
s
->
iformat
->
flags
&
AVFMT_NOFILE
)
return
AVERROR
(
EINVAL
);
return
0
;
}
if
(
(
s
->
iformat
&&
s
->
iformat
->
flags
&
AVFMT_NOFILE
)
||
(
!
s
->
iformat
&&
(
s
->
iformat
=
av_probe_input_format
(
&
pd
,
0
))))
return
0
;
if
((
ret
=
avio_open
(
&
s
->
pb
,
filename
,
AVIO_FLAG_READ
))
<
0
)
return
ret
;
if
(
s
->
iformat
)
return
0
;
return
av_probe_input_buffer
(
s
->
pb
,
&
s
->
iformat
,
filename
,
s
,
0
,
0
);
}
int
avformat_open_input
(
AVFormatContext
**
ps
,
const
char
*
filename
,
AVInputFormat
*
fmt
,
AVDictionary
**
options
)
{
AVFormatContext
*
s
=
*
ps
;
int
ret
=
0
;
AVFormatParameters
ap
=
{
0
};
AVDictionary
*
tmp
=
NULL
;
if
(
!
s
&&
!
(
s
=
avformat_alloc_context
()))
return
AVERROR
(
ENOMEM
);
if
(
fmt
)
s
->
iformat
=
fmt
;
if
(
options
)
av_dict_copy
(
&
tmp
,
*
options
,
0
);
if
((
ret
=
av_opt_set_dict
(
s
,
&
tmp
))
<
0
)
goto
fail
;
if
((
ret
=
init_input
(
s
,
filename
))
<
0
)
goto
fail
;
/* check filename in case an image number is expected */
if
(
s
->
iformat
->
flags
&
AVFMT_NEEDNUMBER
)
{
if
(
!
av_filename_number_test
(
filename
))
{
ret
=
AVERROR
(
EINVAL
);
goto
fail
;
}
}
s
->
duration
=
s
->
start_time
=
AV_NOPTS_VALUE
;
av_strlcpy
(
s
->
filename
,
filename
,
sizeof
(
s
->
filename
));
/* allocate private data */
if
(
s
->
iformat
->
priv_data_size
>
0
)
{
if
(
!
(
s
->
priv_data
=
av_mallocz
(
s
->
iformat
->
priv_data_size
)))
{
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
}
if
(
s
->
iformat
->
priv_class
)
{
*
(
const
AVClass
**
)
s
->
priv_data
=
s
->
iformat
->
priv_class
;
av_opt_set_defaults
(
s
->
priv_data
);
if
((
ret
=
av_opt_set_dict
(
s
->
priv_data
,
&
tmp
))
<
0
)
goto
fail
;
}
}
/* e.g. AVFMT_NOFILE formats will not have a AVIOContext */
if
(
s
->
pb
)
ff_id3v2_read
(
s
,
ID3v2_DEFAULT_MAGIC
);
if
(
s
->
iformat
->
read_header
)
if
((
ret
=
s
->
iformat
->
read_header
(
s
,
&
ap
))
<
0
)
goto
fail
;
if
(
s
->
pb
&&
!
s
->
data_offset
)
s
->
data_offset
=
avio_tell
(
s
->
pb
);
s
->
raw_packet_buffer_remaining_size
=
RAW_PACKET_BUFFER_SIZE
;
if
(
options
)
{
av_dict_free
(
options
);
*
options
=
tmp
;
}
*
ps
=
s
;
return
0
;
fail:
av_dict_free
(
&
tmp
);
if
(
s
->
pb
&&
!
(
s
->
flags
&
AVFMT_FLAG_CUSTOM_IO
))
avio_close
(
s
->
pb
);
avformat_free_context
(
s
);
*
ps
=
NULL
;
return
ret
;
}
/*******************************************************/
static
AVPacket
*
add_to_pktbuf
(
AVPacketList
**
packet_buffer
,
AVPacket
*
pkt
,
...
...
@@ -2573,7 +2674,8 @@ void avformat_free_context(AVFormatContext *s)
void
av_close_input_file
(
AVFormatContext
*
s
)
{
AVIOContext
*
pb
=
s
->
iformat
->
flags
&
AVFMT_NOFILE
?
NULL
:
s
->
pb
;
AVIOContext
*
pb
=
(
s
->
iformat
->
flags
&
AVFMT_NOFILE
)
||
(
s
->
flags
&
AVFMT_FLAG_CUSTOM_IO
)
?
NULL
:
s
->
pb
;
av_close_input_stream
(
s
);
if
(
pb
)
avio_close
(
pb
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录