問題描述
我正在嘗試將各種 .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 的默認協議白名單僅包括 file
和 crypto
.為了也允許 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 可以連接來自不同域的文件嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!