问题
Let's say that I have a list of hundreds of possible video files. Using ffmpeg
it's pretty easy to take multiple files and stitch them together to single video output, but that's where the things become tricky.
I'm looking for a way to have them stream live and dynamically add videos to queue as stream goes on. Think of something like SSAI but for the whole video.
Stream live is there so we don't have a delay while waiting for ffmpeg
to finish the whole video but rather start as soon as possible, and also so we could choose next files in queue during the live stream.
Simplified, it would look something like this:
[v] [v] [v] [v] - stored video files, eg. on S3
[v] - chosen file
| |
| | - during the live stream
| |
\ /
V
_________ ___________ ___________
\ / | | || ||
\ / =====> | | =====> || |:> ||
\___/ |_________| ||_______||
Video queue FFMPEG? Live stream
Transcoding module?
Magic?
I'm writing this in Node.js if that makes any difference.
Is this even possible? If you need any more information please ask away, and every suggestion is greatly appreciated!
回答1:
The basic method to do this is using 2 levels of the concat demuxer and looping the top-level concat input.
Create two text files.
root.txt:
file nested.txt
file nested.txt
nested.txt:
file current-video.mp4
and then,
ffmpeg -re -f concat -safe 0 -stream_loop -1 -i root.txt -c copy {output options}
Update nested.txt with new filename before the playing of the current file ends.
FFmpeg git version > Jan 2019 or 4.2+ is required.
All files must have streams with identical encoding. Timebase for streams should be the same. Duration of all streams within a file should be the same, in order to maintain sync.
来源:https://stackoverflow.com/questions/57143892/from-multiple-video-files-to-single-output