Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
791 views
in Technique[技术] by (71.8m points)

php - Can FFmpeg concatenate files from a different domain?

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'

and then concatenate them like so:

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

and then convert the file like so:

ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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] Line 1: unknown keyword 'http://somewebsite.com/files/videoclip1.ts

mylist.txt: Invalid data found when processing input

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] Unsafe file name 'http://somewebsite.com/files/videoclip1.ts'

mylist.txt: Operation not permitted

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] Protocol 'http' not on whitelist 'file,crypto'!

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

mylist.txt: Invalid argument

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...