with open('test.avi', 'rb') as infile:
    p = Popen(['ffmpeg', '-i', '-', '-f', 'matroska', '-vcodec', 'mpeg4',
        '-acodec', 'aac', '-strict', 'experimental', '-'], stdin=infile,
        stdout=PIPE)
while True:
    data = p.stdout.read(1024)
if len(data) == 0:
    break
print(data)
How do I use ffmpeg with Python by passing File Objects (instead of locations to files on disk)