3

I'm trying to create an infinite video stream that I can push to a local RTMP server.

I believe it's worth mentioning that I'm not very good with ffmpeg, I started using it some weeks ago.

Here is a similat question, but it doesn't fully answer what I need.

What I tried

At my first attempt, I made a bash script that spawned a new ffmpeg instance for each video I was trying to stream. I noticed that that the few seconds that takes to spawn the new instance interrupts the stream.

After I noticed this problem, I decided to google some kind of queue system, and I found that ffmpeg has a concat function, that reads a file with a custom syntax and queues it.

So I made a script that lists the files in the directory where I store all my videos, modifies the output with sed, shuffles it (so the episodes are random), and then it redirects the output to a playlist.txt

find /mnt/episode/ -print | sed '/**.mp4/!d' | sed "s/^/file '/; s/$/'/" | shuf > playlist.txt

playlist.txt

example:
...
file '/mnt/episode/9/1.mp4'
file '/mnt/episode/8/4.mp4'
file '/mnt/episode/5/11.mp4'
file '/mnt/episode/7/15.mp4'
...

This creates 2 problems:

  1. For some reason, while using the playlist/queue method, when it finishes a video... it takes like 30 seconds to switch to the next video.
ffmpeg -f concat -safe 0 -i playlist.txt -f v4l2 /dev/video0

(simplified command, using /dev/video0 device for testing purposes)

ffmpeg does output something after the first video, but i'm not quite sure what it means.

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55c8abc1b900] st: 1 edit list: 1 Missing key frame while searching for timestamp: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55c8abc1b900] st: 1 edit list 1 Cannot find an index entry before timestamp: 0.
  1. Once the playlist finishes, the stream is over. I could run the script that generates the playlist again, but that would mean that the stream cuts, which I don't want.

What I want

I need a way to pick a random file, stream it normally via RTMP and once it finished, automatically pick another one without interrupting the streaming, and keep doing this until I decide to turn it off.

This is the directory format:

episodes
│
├── 1
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
├── 2
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
├── 3
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
├── 4
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
├── 5
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
├── 6
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
├── 7
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
├── 8
│   ├── 1.mp4
│   ├── 2.mp4
│   ├── 3.mp4
│   ...
└── 9
    ├── 1.mp4
    ├── 2.mp4
    ├── 3.mp4
    ...

Gladly appreciate some help here. I tried to make the problem as clear as possible.

Thanks <3

samoht9277
  • 31
  • 3

0 Answers0