1

I would like to dynamically generate infinite video stream from video clips, so that choose next one on the fly. I was inspired by ffplayout project which runs ffplay and make it read from stdin, and then runs ffmpeg and stdout is redirected to ffplay. It works nice when streaming to rtmp server (probably because there is some buffering applied on the way), but when using ffplay you can notice some glitches on video transition.

Video is converted to mpegts for transport through pipe.

I was testing on this video which is made for looping.

In order to eliminate ffmpeg startup, file read delay, I did what follows:

# saved raw output
ffmpeg -i tunnel.mp4 -f mpegts tunnel.mpegts
# made fifo.ts
mkfifo fifo
# run ffplay to read from stdin
ffplay -an -f mpegts -i pipe:0 <fifo.ts
# write video to fifo
cat tunnel.mpegts tunnel.mpegts tunnel.mpegts tunnel.mpegts >> fifo.ts

still glitches on transition. I even tried to read video to memory and write to fifo to eliminate disk io

def main():
    with open('tunnel.mpegts', 'rb') as fd:
        tunnel = fd.read()

    with open('fifo.ts', 'wb') as fd:
        for _ in range(5):
            fd.write(tunnel)

still glitches.

Any idea how to make it work? Maybe another ffmpeg on the way that would buffer/delay/join/transcode?

0

I think the problem is not the caching, but the fact that ffplay don't get a clean encoded stream.

With your yellow tunnel clip you can try this:

while true; do
    ffmpeg -i tunnel.mp4 -c:v mpeg2video -b:v 50M -c:a s302m -strict -2 -ar 48k -f mpegts -;
done | ffmpeg -re -i - -c:v mpeg2video -b:v 50M -c:a s302m -strict -2 -ar 48k -f mpegts - | ffplay -

And you see, that there is almost no glitches anymore. This is not a really nice solution, but the second ffmpeg instance would recompress the hole stream.

When is just about playing on desktop I would try more somthing like python-mpv.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.