2

Here is the Python code:

import subprocess 

cmnd = ["ffmpeg", "-i", "/home/xincoz/test/connect.flv", "-acodec", "copy", "-ss", "00:00:00", "-t", "00:00:30", "/home/xincoz/test/output.flv"]

subprocess.call(cmnd)

Here I get the 30sec long video output file output.flv from connect.flv video. But i want to store that 30sec long binary data in a variable instead of copying that into an output file. How can I able to do that?

Please help me. Thanks a lot in advance.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
rash
  • 1,316
  • 1
  • 12
  • 17
  • http://stackoverflow.com/questions/2502833/python-store-output-of-subprocess-popen-call-in-a-string – matino Jun 25 '13 at 09:51

1 Answers1

3

You'll have to tell to ffmpeg to output to stdout and also tell if the output format. Then from python, as @matino said, use Popen to read what was written to stdout:

cmnd = ["ffmpeg", "-i", "/your/file.avi", "-acodec", "copy", "-ss", "00:00:00", "-t", "00:00:30", "-f", "avi", "pipe:1"]

p = subprocess.Popen(cmnd, stdout=subprocess.PIPE)

out, err = p.communicate()

print len(out) # print the length of the data received
Guillaume
  • 10,463
  • 1
  • 33
  • 47