Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
f43d09cd
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,发现更多精彩内容 >>
提交
f43d09cd
编写于
2月 09, 2013
作者:
N
Nicolas George
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lavf: add tee pseudo-muxer.
上级
350128b2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
318 addition
and
2 deletion
+318
-2
Changelog
Changelog
+1
-0
doc/muxers.texi
doc/muxers.texi
+35
-0
libavformat/Makefile
libavformat/Makefile
+1
-0
libavformat/allformats.c
libavformat/allformats.c
+1
-0
libavformat/tee.c
libavformat/tee.c
+278
-0
libavformat/version.h
libavformat/version.h
+2
-2
未找到文件。
Changelog
浏览文件 @
f43d09cd
...
...
@@ -14,6 +14,7 @@ version <next>:
and treble audio filter
- improved showspectrum filter, with multichannel support and sox-like colors
- histogram filter
- tee muxer
version 1.1:
...
...
doc/muxers.texi
浏览文件 @
f43d09cd
...
...
@@ -749,4 +749,39 @@ situations, giving a small seek granularity at the cost of additional container
overhead.
@end table
@section tee
The tee muxer can be used to write the same data to several files or any
other kind of muxer. It can be used, for example, to both stream a video to
the network and save it to disk at the same time.
It is different from specifying several outputs to the @command{ffmpeg}
command-line tool because the audio and video data will be encoded only once
with the tee muxer; encoding can be a very expensive process. It is not
useful when using the libavformat API directly because it is then possible
to feed the same packets to several muxers directly.
The slave outputs are specified in the file name given to the muxer,
separated by '|'. If any of the slave name contains the '|' separator,
leading or trailing spaces or any special character, it must be
@ref{quoting_and_escaping, escaped}.
Options can be specified for each slave by prepending them as a list of
@var{key}=@var{value} pairs separated by ':', between square brackets. If
the options values contain a special character or the ':' separator, they
must be @ref{quoting_and_escaping, escaped}; note that this is a second
level escaping.
Example: encode something and both archive it in a WebM file and stream it
as MPEG-TS over UDP:
@example
ffmpeg -i ... -c:v libx264 -c:a mp2 -f tee
"archive-20121107.mkv|[f=mpegts]udp://10.0.1.255:1234/"
@end example
Note: some codecs may need different options depending on the output format;
the auto-detection of this can not work with the tee muxer. The main example
is the @option{global_header} flag.
@c man end MUXERS
libavformat/Makefile
浏览文件 @
f43d09cd
...
...
@@ -358,6 +358,7 @@ OBJS-$(CONFIG_SWF_DEMUXER) += swfdec.o swf.o
OBJS-$(CONFIG_SWF_MUXER)
+=
swfenc.o swf.o
OBJS-$(CONFIG_TAK_DEMUXER)
+=
takdec.o apetag.o img2.o rawdec.o
OBJS-$(CONFIG_TEDCAPTIONS_DEMUXER)
+=
tedcaptionsdec.o
OBJS-$(CONFIG_TEE_MUXER)
+=
tee.o
OBJS-$(CONFIG_THP_DEMUXER)
+=
thp.o
OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER)
+=
tiertexseq.o
OBJS-$(CONFIG_MKVTIMESTAMP_V2_MUXER)
+=
mkvtimestamp_v2.o
...
...
libavformat/allformats.c
浏览文件 @
f43d09cd
...
...
@@ -263,6 +263,7 @@ void av_register_all(void)
REGISTER_DEMUXER
(
SUBVIEWER
,
subviewer
);
REGISTER_MUXDEMUX
(
SWF
,
swf
);
REGISTER_DEMUXER
(
TAK
,
tak
);
REGISTER_MUXER
(
TEE
,
tee
);
REGISTER_DEMUXER
(
TEDCAPTIONS
,
tedcaptions
);
REGISTER_MUXER
(
TG2
,
tg2
);
REGISTER_MUXER
(
TGP
,
tgp
);
...
...
libavformat/tee.c
0 → 100644
浏览文件 @
f43d09cd
/*
* Tee pesudo-muxer
* Copyright (c) 2012 Nicolas George
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpeg; if not, write to the Free Software * Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/avutil.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "avformat.h"
#define MAX_SLAVES 16
typedef
struct
TeeContext
{
const
AVClass
*
class
;
unsigned
nb_slaves
;
AVFormatContext
*
slaves
[
MAX_SLAVES
];
}
TeeContext
;
static
const
char
*
const
slave_delim
=
"|"
;
static
const
char
*
const
slave_opt_open
=
"["
;
static
const
char
*
const
slave_opt_close
=
"]"
;
static
const
char
*
const
slave_opt_delim
=
":]"
;
/* must have the close too */
static
const
AVClass
tee_muxer_class
=
{
.
class_name
=
"Tee muxer"
,
.
item_name
=
av_default_item_name
,
.
version
=
LIBAVUTIL_VERSION_INT
,
};
static
int
parse_slave_options
(
void
*
log
,
char
*
slave
,
AVDictionary
**
options
,
char
**
filename
)
{
const
char
*
p
;
char
*
key
,
*
val
;
int
ret
;
if
(
!
strspn
(
slave
,
slave_opt_open
))
{
*
filename
=
slave
;
return
0
;
}
p
=
slave
+
1
;
if
(
strspn
(
p
,
slave_opt_close
))
{
*
filename
=
(
char
*
)
p
+
1
;
return
0
;
}
while
(
1
)
{
ret
=
av_opt_get_key_value
(
&
p
,
"="
,
slave_opt_delim
,
0
,
&
key
,
&
val
);
if
(
ret
<
0
)
{
av_log
(
log
,
AV_LOG_ERROR
,
"No option found near
\"
%s
\"\n
"
,
p
);
goto
fail
;
}
ret
=
av_dict_set
(
options
,
key
,
val
,
AV_DICT_DONT_STRDUP_KEY
|
AV_DICT_DONT_STRDUP_VAL
);
if
(
ret
<
0
)
goto
fail
;
if
(
strspn
(
p
,
slave_opt_close
))
break
;
p
++
;
}
*
filename
=
(
char
*
)
p
+
1
;
return
0
;
fail:
av_dict_free
(
options
);
return
ret
;
}
static
int
open_slave
(
AVFormatContext
*
avf
,
char
*
slave
,
AVFormatContext
**
ravf
)
{
int
i
,
ret
;
AVDictionary
*
options
=
NULL
;
AVDictionaryEntry
*
entry
;
char
*
filename
;
char
*
format
=
NULL
;
AVFormatContext
*
avf2
=
NULL
;
AVStream
*
st
,
*
st2
;
if
((
ret
=
parse_slave_options
(
avf
,
slave
,
&
options
,
&
filename
))
<
0
)
return
ret
;
if
((
entry
=
av_dict_get
(
options
,
"f"
,
NULL
,
0
)))
{
format
=
entry
->
value
;
entry
->
value
=
NULL
;
/* prevent it from being freed */
av_dict_set
(
&
options
,
"f"
,
NULL
,
0
);
}
avformat_alloc_output_context2
(
&
avf2
,
NULL
,
format
,
filename
);
if
(
ret
<
0
)
goto
fail
;
av_free
(
format
);
for
(
i
=
0
;
i
<
avf
->
nb_streams
;
i
++
)
{
st
=
avf
->
streams
[
i
];
if
(
!
(
st2
=
avformat_new_stream
(
avf2
,
NULL
)))
{
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
}
st2
->
id
=
st
->
id
;
st2
->
r_frame_rate
=
st
->
r_frame_rate
;
st2
->
time_base
=
st
->
time_base
;
st2
->
start_time
=
st
->
start_time
;
st2
->
duration
=
st
->
duration
;
st2
->
nb_frames
=
st
->
nb_frames
;
st2
->
disposition
=
st
->
disposition
;
st2
->
sample_aspect_ratio
=
st
->
sample_aspect_ratio
;
st2
->
avg_frame_rate
=
st
->
avg_frame_rate
;
av_dict_copy
(
&
st2
->
metadata
,
st
->
metadata
,
0
);
if
((
ret
=
avcodec_copy_context
(
st2
->
codec
,
st
->
codec
))
<
0
)
goto
fail
;
}
if
(
!
(
avf2
->
oformat
->
flags
&
AVFMT_NOFILE
))
{
if
((
ret
=
avio_open
(
&
avf2
->
pb
,
filename
,
AVIO_FLAG_WRITE
))
<
0
)
{
av_log
(
avf
,
AV_LOG_ERROR
,
"Slave '%s': error opening: %s
\n
"
,
slave
,
av_err2str
(
ret
));
goto
fail
;
}
}
if
((
ret
=
avformat_write_header
(
avf2
,
&
options
))
<
0
)
{
av_log
(
avf
,
AV_LOG_ERROR
,
"Slave '%s': error writing header: %s
\n
"
,
slave
,
av_err2str
(
ret
));
goto
fail
;
}
if
(
options
)
{
entry
=
NULL
;
while
((
entry
=
av_dict_get
(
options
,
""
,
entry
,
AV_DICT_IGNORE_SUFFIX
)))
av_log
(
avf2
,
AV_LOG_ERROR
,
"Unknown option '%s'
\n
"
,
entry
->
key
);
ret
=
AVERROR_OPTION_NOT_FOUND
;
goto
fail
;
}
*
ravf
=
avf2
;
return
0
;
fail:
av_dict_free
(
&
options
);
return
ret
;
}
static
void
close_slaves
(
AVFormatContext
*
avf
)
{
TeeContext
*
tee
=
avf
->
priv_data
;
AVFormatContext
*
avf2
;
unsigned
i
;
for
(
i
=
0
;
i
<
tee
->
nb_slaves
;
i
++
)
{
avf2
=
tee
->
slaves
[
i
];
avio_close
(
avf2
->
pb
);
avf2
->
pb
=
NULL
;
avformat_free_context
(
avf2
);
tee
->
slaves
[
i
]
=
NULL
;
}
}
static
int
tee_write_header
(
AVFormatContext
*
avf
)
{
TeeContext
*
tee
=
avf
->
priv_data
;
unsigned
nb_slaves
=
0
,
i
;
const
char
*
filename
=
avf
->
filename
;
char
*
slaves
[
MAX_SLAVES
];
int
ret
;
while
(
*
filename
)
{
if
(
nb_slaves
==
MAX_SLAVES
)
{
av_log
(
avf
,
AV_LOG_ERROR
,
"Maximum %d slave muxers reached.
\n
"
,
MAX_SLAVES
);
ret
=
AVERROR_PATCHWELCOME
;
goto
fail
;
}
if
(
!
(
slaves
[
nb_slaves
++
]
=
av_get_token
(
&
filename
,
slave_delim
)))
{
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
}
if
(
strspn
(
filename
,
slave_delim
))
filename
++
;
}
for
(
i
=
0
;
i
<
nb_slaves
;
i
++
)
{
if
((
ret
=
open_slave
(
avf
,
slaves
[
i
],
&
tee
->
slaves
[
i
]))
<
0
)
goto
fail
;
av_freep
(
&
slaves
[
i
]);
}
tee
->
nb_slaves
=
nb_slaves
;
return
0
;
fail:
for
(
i
=
0
;
i
<
nb_slaves
;
i
++
)
av_freep
(
&
slaves
[
i
]);
close_slaves
(
avf
);
return
ret
;
}
static
int
tee_write_trailer
(
AVFormatContext
*
avf
)
{
TeeContext
*
tee
=
avf
->
priv_data
;
AVFormatContext
*
avf2
;
int
ret_all
=
0
,
ret
;
unsigned
i
;
for
(
i
=
0
;
i
<
tee
->
nb_slaves
;
i
++
)
{
avf2
=
tee
->
slaves
[
i
];
if
((
ret
=
av_write_trailer
(
avf2
))
<
0
)
if
(
!
ret_all
)
ret_all
=
ret
;
if
(
!
(
avf2
->
oformat
->
flags
&
AVFMT_NOFILE
))
{
if
((
ret
=
avio_close
(
avf2
->
pb
))
<
0
)
if
(
!
ret_all
)
ret_all
=
ret
;
avf2
->
pb
=
NULL
;
}
}
close_slaves
(
avf
);
return
ret_all
;
}
static
int
tee_write_packet
(
AVFormatContext
*
avf
,
AVPacket
*
pkt
)
{
TeeContext
*
tee
=
avf
->
priv_data
;
AVFormatContext
*
avf2
;
AVPacket
pkt2
;
int
ret_all
=
0
,
ret
;
unsigned
i
,
s
;
AVRational
tb
,
tb2
;
for
(
i
=
0
;
i
<
tee
->
nb_slaves
;
i
++
)
{
avf2
=
tee
->
slaves
[
i
];
s
=
pkt
->
stream_index
;
if
(
s
>=
avf2
->
nb_streams
)
{
if
(
!
ret_all
)
ret_all
=
AVERROR
(
EINVAL
);
continue
;
}
if
((
ret
=
av_copy_packet
(
&
pkt2
,
pkt
))
<
0
||
(
ret
=
av_dup_packet
(
&
pkt2
))
<
0
)
if
(
!
ret_all
)
{
ret
=
ret_all
;
continue
;
}
tb
=
avf
->
streams
[
s
]
->
time_base
;
tb2
=
avf2
->
streams
[
s
]
->
time_base
;
pkt2
.
pts
=
av_rescale_q
(
pkt
->
pts
,
tb
,
tb2
);
pkt2
.
dts
=
av_rescale_q
(
pkt
->
dts
,
tb
,
tb2
);
pkt2
.
duration
=
av_rescale_q
(
pkt
->
duration
,
tb
,
tb2
);
if
((
ret
=
av_interleaved_write_frame
(
avf2
,
&
pkt2
))
<
0
)
if
(
!
ret_all
)
ret_all
=
ret
;
}
return
ret_all
;
}
AVOutputFormat
ff_tee_muxer
=
{
.
name
=
"tee"
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"Multiple muxer tee"
),
.
priv_data_size
=
sizeof
(
TeeContext
),
.
write_header
=
tee_write_header
,
.
write_trailer
=
tee_write_trailer
,
.
write_packet
=
tee_write_packet
,
.
priv_class
=
&
tee_muxer_class
,
.
flags
=
AVFMT_NOFILE
,
};
libavformat/version.h
浏览文件 @
f43d09cd
...
...
@@ -30,8 +30,8 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 6
1
#define LIBAVFORMAT_VERSION_MICRO 10
4
#define LIBAVFORMAT_VERSION_MINOR 6
2
#define LIBAVFORMAT_VERSION_MICRO 10
0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录