I would like to stream frames from one Python script (A) to another (B) so that B only gets them as fast as A can produce them. Everything I've seen with ffmpeg takes an entire video, or streams from a camera. I guess what I'd like to do is treat a Python script like a camera that generates frames.

I've seen this: http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/ but I don't want to send output to a video file, I want another script to read it. I also got a broken pipe error using that code, anyway.


ffmpeg can read from STDIN, so all you have to do is pipe the frames from your script to ffmpeg via that stream, in some format that ffmpeg understands.

For example, if I use ffmpeg to decode a video stream into individual frames using YUV420P as a pixel format, I can read them back in, but I just have to specify the dimensions, frame rate, and pixel format again:

ffmpeg -i input.mp4 -f rawvideo - | \
ffmpeg -f rawvideo -s 1920x1080 -r 60 -pix_fmt yuv420p -i - output.mp4

Of course, if you can stream valid formats from your script – and preferably streamable formats like like MPEG-2 TS – then ffmpeg would of course also be able to read it.

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.