0

I'm writing a script that use ffmpeg to create a video from a picture. I need to save the file like file name something.mp4 (with spaces between words in the filename). When I try to do this, I receive this error:

[NULL @ 02c2fa20] Unable to find a suitable output format for './lol/media/videos/Lets' ./lol/media/videos/Lets: Invalid argument. 

The script gets only the first word of the filename. Here's the code:

from subprocess import check_output import ntpath import os class videomaker(): def makevidoes(self, path, savepath, time=15): if not os.path.exists(savepath): os.makedirs(savepath) try: filename = ntpath.basename(os.path.splitext(path)[0].replace('+', ' ') + ".mp4") print filename #file name is something like 'Lets play games.mp4' check_output("ffmpeg -loop 1 -i " + path + " -c:v libx264 -t " + str(time) + " -pix_fmt yuv420p -vf scale=1024:728 " + "" + savepath + filename + "", shell=True) return savepath + filename except: print "error" 
1
  • I always find it helpful to start with a working command line in a shell, and then use that command line in my scripts. Try to use " around paths with spaces. Commented Jul 18, 2015 at 5:23

1 Answer 1

1

Pass check_output a list of the separate terms:

 check_output(["ffmpeg", "-loop", "1", "-i", path, "-c:v", "libx264", "-t", str(time), "-pix_fmt", "yuv420p", "-vf", "scale=1024:728", savepath + filename], shell=True) 

This will ensure they are treated correctly as distinct arguments even when they contain special characters.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.