Using FFMPEG to stream continuously videos files to a RTMP server

Update (as I can’t delete the accepted answer): the proper solution is to implement a custom demuxer, similar to the concat one. There’s currently no other clean way. You have to get your hands dirty and code!

Below is an ugly hack. This is a very bad way to do it, just don’t!

The solution uses the concat demuxer and assumes all your source media files use the same codec. The example is based on MPEG-TS but the same can be done for RTMP.

  1. Make a playlist file holding a huge list of entry points for you dynamic playlist with the following format:


    file 'item_1.ts'
    file 'item_2.ts'
    file 'item_3.ts'
    [...]
    file 'item_[ENOUGH_FOR_A_LIFETIME].ts'

    These files are just placeholders.

  2. Make a script that keeps track of you current playlist index and creates symbolic links on-the-fly for current_index + 1

    ln -s /path/to/what/to/play/next.ts item_1.ts

    ln -s /path/to/what/to/play/next.ts item_2.ts

    ln -s /path/to/what/to/play/next.ts item_3.ts

    [...]

  3. Start playing
    ffmpeg -f concat -i playlist.txt -c copy output -f mpegts udp://<ip>:<port>

  4. Get chased and called names by an angry system administrator

Leave a Comment