1

I am trying to store an image that is the result of ffmpeg.

Using this command, I have frame.png as an external file output:

ffmpeg -flags2 +export_mvs -i video.avi -vf 'select=gte(n\,200),codecview=mv=pf+bf+bb' -vframes 1 frame.png

I want to be able to load the frame.png directly into python, maybe using openCV but without saving it in the computer.

I thought of something like this:

cmd = "ffmpeg -flags2 +export_mvs -i video.avi -vf 'select=gte(n\,200),codecview=mv=pf+bf+bb' -vframes 1 frame.png"    

img = cv.imread(sp.Popen(cmd, shell=True, stdout = sp.PIPE, stderr = sp.PIPE).communicate()[0])

But I get an error:

TypeError: bad argument type for built-in operation

Any clue how to do this? The idea is, no frame.png should be generated as a file.

tavalendo
  • 857
  • 2
  • 11
  • 30

1 Answers1

0

You can set the output file as /dev/stdout (you might need to specify the output format with -f) Then you redirect your output to your python script like so

ffmpeg options /dev/stdout | python your_script.py

Then you can read this question to see how you can read an image from a file object. Just replace StringIO with sys.stdin

Fred
  • 1,462
  • 8
  • 15