Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can FFmpeg concatenate files from a different domain?

Tags:

php

ffmpeg

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.

like image 547
user3080392 Avatar asked Oct 24 '25 23:10

user3080392


1 Answers

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.

like image 182
rickdenhaan Avatar answered Oct 27 '25 14:10

rickdenhaan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!