6

I'm using ffmpeg to create a video, from a list of base64 encoded images that I pipe into ffmpeg.

Outputting to a file (using the attached code below) works perfectly, but what I would like to achieve is to get the output to a Python variable instead - meaning piping input and piping output but I can't seem to get it to work

My current code:

output = os.path.join(screenshots_dir, 'video1.mp4')

cmd_out = ['ffmpeg',
           '-y',  # (optional) overwrite output file if it exists
           '-f', 'image2pipe',
           '-vcodec', 'png',
           '-r', str(fps),  # frames per second
           '-i', '-',  # The input comes from a pipe
           '-vcodec', 'png',
           '-qscale', '0',
           output]

pipe = sp.Popen(cmd_out, stdin=sp.PIPE)

for screenshot in screenshot_list:
    im = Image.open(BytesIO(base64.b64decode(screenshot)))
    im.save(pipe.stdin, 'PNG')

pipe.stdin.close()
pipe.wait()

This results in a working mp4, but I would like to avoid saving to local.

Running the same code with changing output to '-' or 'pipe:1' and adding stdout=sp.PIPE results in an error

[NULL @ 0x2236000] Unable to find a suitable output format for 'pipe:'

2 Answers 2

1

FFmpeg guesses the output muxer by checking the output extension. With a pipe, that doesn't exist, so it has to be expressly set. Add '-f', 'image2pipe' just before output.

Sign up to request clarification or add additional context in comments.

8 Comments

Can't help you with the python part. Only ffmpeg.
Thanks for that anyway, for now seems to be working. I'll see if I indeed catch it and verify it is the video, if so I will accept
Seems that it gets stuck forever on the `Stream mapping: Stream #0:0 -> #0:0 (png (native) -> png (native)) part
Need to see full ffmpeg console.
Has your input terminated?
|
0

Try to add the following command after your sp.Popen :

output, _ = pipe.communicate()

I think you need to communicate it with the opened process. After that you can print it to make sure it worked :

print(_)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.