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"
MattDMo
  • 100,794
  • 21
  • 241
  • 231
Andrea
  • 39
  • 6
  • 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. – Jens Jul 18 '15 at 05:23

1 Answers1

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.

Joe
  • 29,416
  • 12
  • 68
  • 88