php - FFmpeg 可以连接来自不同域的文件吗?

标签 php ffmpeg

我正在尝试将各种 .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 文件可以是来自另一个域的网址吗?例如:

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

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

最佳答案

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

尝试使用您提供的示例文本文件将给出非常清晰的错误消息:

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

mylist.txt: Invalid data found when processing input

这很容易通过在 mylist.txt 中重新引入"file"关键字来解决:

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

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

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

mylist.txt: Operation not permitted

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

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

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

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

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

mylist.txt: Invalid argument

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

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

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

关于php - FFmpeg 可以连接来自不同域的文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49343174/

相关文章:

nginx - HLS 文件夹未在 NGINX-RTMP 中创建

php - 如何使用 PHPUnit 测试 Zend Framework 2 中的 EventListener

php - 如何在自定义 PHP 文件中包含 Wordpress 帖子?

php - ffmpeg 在 php 或 python 中获取元数据

ffmpeg - 裁剪、调整大小和剪切全部在一个命令中 - FFMPEG

android - Android 上的 FFMpeg : Streaming HTTP audio stream

php - 如何替换字符串的某些部分?

php - 图像作为 PHP 文件

javascript - 尝试使用 Ajax 提交数据而无需页面加载以及选择的更改事件

ffmpeg - 使用 ffmpeg 重新缩放,但保持像素密度不变