From multiple video files to single output

半世苍凉 提交于 2021-02-18 18:53:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!