FFmpeg 可以连接来自不同域的文件吗? [英] Can FFmpeg concatenate files from a different domain?

查看:29
本文介绍了FFmpeg 可以连接来自不同域的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将各种 .ts 视频剪辑连接成一个视频,然后将视频转换为 .mp4 文件.我知道我可以制作一个格式如下的 .txt 文件:

I'm attempting to concatenate various .ts video clips into one video and then convert the video into an .mp4 file. I know I can make a .txt file formatted like so:

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 文件可以是来自另一个域的网址吗?例如:

My question is, can my .txt file be urls from another domain? e.g.:

http://somewebsite.com/files/videoclip1.ts
http://somewebsite.com/files/videoclip2.ts
http://somewebsite.com/files/videoclip3.ts

或者,我是否必须先下载所有这些剪辑,将它们本地存储在我的域中,然后制作一个指向它们的 .txt 文件?我正在使用 PHP.谢谢.

Or, do I first have to download all these clips, store them locally on my domain, then make a .txt file pointing to them? I'm using PHP. Thanks.

推荐答案

是的,这是可能的.请注意,在以下示例中,我使用了您问题中的 url 和文件名,测试时我在自己的网络服务器上使用了一些测试文件.

Yes, this is possible. Note that in the following examples I use the urls and filenames from your question, when testing I used some test files on my own web server.

使用您提供的示例文本文件尝试此操作将给出非常明确的错误消息:

Trying this with the example text file you provided will give a pretty clear error message:

[concat @ 0x7f892f800000] 第 1 行:未知关键字 'http://somewebsite.com/files/videoclip1.ts

[concat @ 0x7f892f800000] Line 1: unknown keyword 'http://somewebsite.com/files/videoclip1.ts

mylist.txt:处理输入时发现无效数据

mylist.txt: Invalid data found when processing input

通过在 mylist.txt 中重新引入 'file' 关键字很容易解决这个问题:

This is easily fixed by re-introducing the 'file' keyword in mylist.txt:

file 'http://somewebsite.com/files/videoclip1.ts'
file 'http://somewebsite.com/files/videoclip2.ts'
file 'http://somewebsite.com/files/videoclip3.ts'

更新后的文件会给出不同的错误信息:

That updated file will give a different error message:

[concat @ 0x7fa467800000] 不安全的文件名 'http://somewebsite.com/files/videoclip1.ts'

[concat @ 0x7fa467800000] Unsafe file name 'http://somewebsite.com/files/videoclip1.ts'

mylist.txt:不允许操作

mylist.txt: Operation not permitted

这样做的原因是ffmpeg默认不允许http-urls.这可以通过在 ffmpeg 调用中包含 -safe 0 参数before -i 参数来绕过:

The reason for this is that ffmpeg will not allow http-urls by default. This can be bypassed by including the -safe 0 argument in your ffmpeg call before the -i argument:

ffmpeg -f concat -safe 0 -i mylist.txt -c copy all.ts

这可能在您的安装中开箱即用,在我的安装中,这给出了另一条错误消息:

This might work out of the box on your installation, on mine this gave another error message:

[http @ 0x7faa68507940] 协议 'http' 不在白名单 'file,crypto' 中!

[http @ 0x7faa68507940] Protocol 'http' not on whitelist 'file,crypto'!

[concat @ 0x7faa69001200] 无法打开 'http://somewebsite.com/files/videoclip1.ts'

[concat @ 0x7faa69001200] Impossible to open 'http://somewebsite.com/files/videoclip1.ts'

mylist.txt:无效参数

mylist.txt: Invalid argument

这是因为,在我的安装中,ffmpeg 的默认协议白名单仅包括 filecrypto.为了也允许 http 协议,我们需要在命令中明确提供允许的协议白名单.事实证明,tcp 也是必需的:

This is because, on my installation, ffmpeg's default protocol whitelist only includes file and crypto. To allow the http protocol as well, we need to explicitly provide the allowed protocols whitelist in the command. As it turns out, tcp is also required:

ffmpeg -f concat -safe 0 -protocol_whitelist file,http,tcp -i mylist.txt -c copy all.ts

这允许我的安装下载和连接视频文件.

This allowed my installation to download and concatenate the video files.

这篇关于FFmpeg 可以连接来自不同域的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆