我尝试将各种.ts视频片段连接成一个视频,然后将视频转换为.mp4文件。我知道我可以制作一个格式如下的.txt文件:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
然后将它们连接起来:
ffmpeg -f concat -i mylist.txt -c copy all.ts
然后像这样转换文件:
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
我的问题是,我的.txt文件可以是来自其他域名的网址吗? e.g:
http://somewebsite.com/files/videoclip1.ts
http://somewebsite.com/files/videoclip2.ts
http://somewebsite.com/files/videoclip3.ts
或者,我是否首先必须下载所有这些剪辑,将它们本地存储在我的域中,然后制作指向它们的.txt文件?我正在使用PHP。感谢。
答案 0 :(得分:1)
是的,这是可能的。请注意,在以下示例中,我使用您问题中的url和文件名,在测试时我在自己的Web服务器上使用了一些测试文件。
使用您提供的示例文本文件尝试此操作会给出一个非常明确的错误消息:
[concat @ 0x7f892f800000]第1行:未知关键字“http://somewebsite.com/files/videoclip1.ts
mylist.txt:处理输入时找到的数据无效
通过在Collecting boto3
Downloading boto3-1.6.11-py2.py3-none-any.whl (128kB)
100% |████████████████████████████████| 133kB 2.7MB/s
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /Library/Python/2.7/site-packages (from boto3)
Collecting botocore<1.10.0,>=1.9.11 (from boto3)
Downloading botocore-1.9.11-py2.py3-none-any.whl (4.1MB)
100% |████████████████████████████████| 4.1MB 278kB/s
Collecting s3transfer<0.2.0,>=0.1.10 (from boto3)
Using cached s3transfer-0.1.13-py2.py3-none-any.whl
Collecting python-dateutil<2.7.0,>=2.1 (from botocore<1.10.0,>=1.9.11->boto3)
Using cached python_dateutil-2.6.1-py2.py3-none-any.whl
Collecting docutils>=0.10 (from botocore<1.10.0,>=1.9.11->boto3)
Using cached docutils-0.14-py2-none-any.whl
Requirement already satisfied: futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" in /Library/Python/2.7/site-packages (from s3transfer<0.2.0,>=0.1.10->boto3)
Collecting six>=1.5 (from python-dateutil<2.7.0,>=2.1->botocore<1.10.0,>=1.9.11->boto3)
Using cached six-1.11.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, docutils, botocore, s3transfer, boto3
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/12/8qvv2_x53rz6ww3t22j2qbr80000gn/T/pip-E6G8ue-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
:
mylist.txt
该更新的文件将提供不同的错误消息:
[concat @ 0x7fa467800000]不安全的文件名“http://somewebsite.com/files/videoclip1.ts”
mylist.txt:不允许操作
原因是ffmpeg默认情况下不允许http-urls。这可以通过在file 'http://somewebsite.com/files/videoclip1.ts'
file 'http://somewebsite.com/files/videoclip2.ts'
file 'http://somewebsite.com/files/videoclip3.ts'
参数之前的ffmpeg调用中包含-safe 0
参数来绕过:
-i
这可能在您的安装上开箱即用,在我的上面给出了另一条错误消息:
[http @ 0x7faa68507940]协议'http'不在白名单'文件,加密'!
[concat @ 0x7faa69001200]无法打开“http://somewebsite.com/files/videoclip1.ts”
mylist.txt:参数无效
这是因为,在我的安装中,ffmpeg的默认协议白名单仅包含ffmpeg -f concat -safe 0 -i mylist.txt -c copy all.ts
和file
。为了允许crypto
协议,我们需要在命令中明确提供允许的协议白名单。事实证明,http
也是必需的:
tcp
这允许我的安装程序下载并连接视频文件。