Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
无聊人士张
you-get
提交
f8f9b777
Y
you-get
项目概览
无聊人士张
/
you-get
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
you-get
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f8f9b777
编写于
8月 03, 2014
作者:
M
Mort Yao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use concat demuxer on FFmpeg >= 1.1, fix #324
上级
1c3c586e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
23 deletion
+79
-23
src/you_get/processor/ffmpeg.py
src/you_get/processor/ffmpeg.py
+79
-23
未找到文件。
src/you_get/processor/ffmpeg.py
浏览文件 @
f8f9b777
...
...
@@ -9,58 +9,78 @@ def get_usable_ffmpeg(cmd):
out
,
err
=
p
.
communicate
()
vers
=
str
(
out
,
'utf-8'
).
split
(
'
\n
'
)[
0
].
split
(
' '
)
assert
(
vers
[
0
]
==
'ffmpeg'
and
vers
[
2
][
0
]
>
'0'
)
or
(
vers
[
0
]
==
'avconv'
)
return
cmd
return
cmd
,
[
int
(
i
)
for
i
in
vers
[
2
].
split
(
'.'
)]
except
:
return
None
FFMPEG
=
get_usable_ffmpeg
(
'ffmpeg'
)
or
get_usable_ffmpeg
(
'avconv'
)
FFMPEG
,
FFMPEG_VERSION
=
get_usable_ffmpeg
(
'ffmpeg'
)
or
get_usable_ffmpeg
(
'avconv'
)
def
has_ffmpeg_installed
():
return
FFMPEG
is
not
None
def
ffmpeg_convert_ts_to_mkv
(
files
,
output
=
'output.mkv'
):
def
ffmpeg_convert_ts_to_mkv
(
files
,
output
=
'output.mkv'
):
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
params
=
[
FFMPEG
,
'-i'
]
params
.
append
(
file
)
params
.
append
(
output
)
subprocess
.
call
(
params
)
return
def
ffmpeg_concat_mp4_to_mpg
(
files
,
output
=
'output.mpg'
):
def
ffmpeg_concat_mp4_to_mpg
(
files
,
output
=
'output.mpg'
):
# Use concat demuxer on FFmpeg >= 1.1
if
FFMPEG
==
'ffmpeg'
and
(
FFMPEG_VERSION
[
0
]
>=
2
or
(
FFMPEG_VERSION
[
0
]
==
1
and
FFMPEG_VERSION
[
1
]
>=
1
)):
concat_list
=
open
(
output
+
'.txt'
,
'w'
)
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
concat_list
.
write
(
"file '%s'
\n
"
%
file
)
concat_list
.
close
()
params
=
[
FFMPEG
,
'-f'
,
'concat'
,
'-i'
]
params
.
append
(
output
+
'.txt'
)
params
+=
[
'-c'
,
'copy'
,
output
]
if
subprocess
.
call
(
params
)
==
0
:
os
.
remove
(
output
+
'.txt'
)
return
True
else
:
raise
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
params
=
[
FFMPEG
,
'-i'
]
params
.
append
(
file
)
params
.
append
(
file
+
'.mpg'
)
subprocess
.
call
(
params
)
inputs
=
[
open
(
file
+
'.mpg'
,
'rb'
)
for
file
in
files
]
with
open
(
output
+
'.mpg'
,
'wb'
)
as
o
:
for
input
in
inputs
:
o
.
write
(
input
.
read
())
params
=
[
FFMPEG
,
'-i'
]
params
.
append
(
output
+
'.mpg'
)
params
+=
[
'-vcodec'
,
'copy'
,
'-acodec'
,
'copy'
]
params
.
append
(
output
)
subprocess
.
call
(
params
)
for
file
in
files
:
os
.
remove
(
file
+
'.mpg'
)
os
.
remove
(
output
+
'.mpg'
)
return
def
ffmpeg_concat_ts_to_mkv
(
files
,
output
=
'output.mkv'
):
if
subprocess
.
call
(
params
)
==
0
:
for
file
in
files
:
os
.
remove
(
file
+
'.mpg'
)
os
.
remove
(
output
+
'.mpg'
)
return
True
else
:
raise
def
ffmpeg_concat_ts_to_mkv
(
files
,
output
=
'output.mkv'
):
params
=
[
FFMPEG
,
'-isync'
,
'-i'
]
params
.
append
(
'concat:'
)
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
params
[
-
1
]
+=
file
+
'|'
params
+=
[
'-f'
,
'matroska'
,
'-c'
,
'copy'
,
output
]
try
:
if
subprocess
.
call
(
params
)
==
0
:
return
True
...
...
@@ -69,16 +89,34 @@ def ffmpeg_concat_ts_to_mkv(files, output = 'output.mkv'):
except
:
return
False
def
ffmpeg_concat_flv_to_mp4
(
files
,
output
=
'output.mp4'
):
def
ffmpeg_concat_flv_to_mp4
(
files
,
output
=
'output.mp4'
):
# Use concat demuxer on FFmpeg >= 1.1
if
FFMPEG
==
'ffmpeg'
and
(
FFMPEG_VERSION
[
0
]
>=
2
or
(
FFMPEG_VERSION
[
0
]
==
1
and
FFMPEG_VERSION
[
1
]
>=
1
)):
concat_list
=
open
(
output
+
'.txt'
,
'w'
)
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
concat_list
.
write
(
"file '%s'
\n
"
%
file
)
concat_list
.
close
()
params
=
[
FFMPEG
,
'-f'
,
'concat'
,
'-i'
]
params
.
append
(
output
+
'.txt'
)
params
+=
[
'-c'
,
'copy'
,
output
]
if
subprocess
.
call
(
params
)
==
0
:
os
.
remove
(
output
+
'.txt'
)
return
True
else
:
raise
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
params
=
[
FFMPEG
,
'-i'
]
params
.
append
(
file
)
params
+=
[
'-map'
,
'0'
,
'-c'
,
'copy'
,
'-f'
,
'mpegts'
,
'-bsf:v'
,
'h264_mp4toannexb'
]
params
.
append
(
file
+
'.ts'
)
subprocess
.
call
(
params
)
params
=
[
FFMPEG
,
'-i'
]
params
.
append
(
'concat:'
)
for
file
in
files
:
...
...
@@ -89,7 +127,7 @@ def ffmpeg_concat_flv_to_mp4(files, output = 'output.mp4'):
params
+=
[
'-c'
,
'copy'
,
output
]
else
:
params
+=
[
'-c'
,
'copy'
,
'-absf'
,
'aac_adtstoasc'
,
output
]
if
subprocess
.
call
(
params
)
==
0
:
for
file
in
files
:
os
.
remove
(
file
+
'.ts'
)
...
...
@@ -97,16 +135,34 @@ def ffmpeg_concat_flv_to_mp4(files, output = 'output.mp4'):
else
:
raise
def
ffmpeg_concat_mp4_to_mp4
(
files
,
output
=
'output.mp4'
):
def
ffmpeg_concat_mp4_to_mp4
(
files
,
output
=
'output.mp4'
):
# Use concat demuxer on FFmpeg >= 1.1
if
FFMPEG
==
'ffmpeg'
and
(
FFMPEG_VERSION
[
0
]
>=
2
or
(
FFMPEG_VERSION
[
0
]
==
1
and
FFMPEG_VERSION
[
1
]
>=
1
)):
concat_list
=
open
(
output
+
'.txt'
,
'w'
)
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
concat_list
.
write
(
"file '%s'
\n
"
%
file
)
concat_list
.
close
()
params
=
[
FFMPEG
,
'-f'
,
'concat'
,
'-i'
]
params
.
append
(
output
+
'.txt'
)
params
+=
[
'-c'
,
'copy'
,
output
]
if
subprocess
.
call
(
params
)
==
0
:
os
.
remove
(
output
+
'.txt'
)
return
True
else
:
raise
for
file
in
files
:
if
os
.
path
.
isfile
(
file
):
params
=
[
FFMPEG
,
'-i'
]
params
.
append
(
file
)
params
+=
[
'-c'
,
'copy'
,
'-f'
,
'mpegts'
,
'-bsf:v'
,
'h264_mp4toannexb'
]
params
.
append
(
file
+
'.ts'
)
subprocess
.
call
(
params
)
params
=
[
FFMPEG
,
'-i'
]
params
.
append
(
'concat:'
)
for
file
in
files
:
...
...
@@ -117,7 +173,7 @@ def ffmpeg_concat_mp4_to_mp4(files, output = 'output.mp4'):
params
+=
[
'-c'
,
'copy'
,
output
]
else
:
params
+=
[
'-c'
,
'copy'
,
'-absf'
,
'aac_adtstoasc'
,
output
]
if
subprocess
.
call
(
params
)
==
0
:
for
file
in
files
:
os
.
remove
(
file
+
'.ts'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录