1

I am trying to execute ffmpeg commands in python. When the following command was executed from command line in windows cmd it worked:

C:\FFmpeg\bin\ffmpeg -rtbufsize 100000k -r 65535/2733 -f dshow -i audio="virtual-audio-capturer":video="screen-capture-recorder" output100.avi

However when I try to run the this command in python in this way:

cmd='C:\FFmpeg\bin\ffmpeg -rtbufsize 100000k -r 65535/2733 -f dshow -i audio="virtual-audio-capturer":video="screen-capture-recorder" output100.avi'
subprocess.call(cmd, shell=true)

it doesn't work

I also tried this way

cmd='C:\FFmpeg\bin\ffmpeg -rtbufsize 100000k -r 65535/2733 -f dshow -i audio="virtual-audio-capturer":video="screen-capture-recorder" output100.avi'
subprocess.check_call(cmd) 

But it didn't work as well

I would like to know what am I doing wrong.I using python 2.76.Thanks.

4
  • cmd='C:\FFmpeg\bin\ffmpeg -rtbufsize 100000k -r 65535/2733 -f dshow -i audio="virtual-audio-capturer":video="screen-capture-recorder" output100.avi' it not syntax error Commented Mar 31, 2014 at 18:16
  • 1
    How do you, it's not working? What is the error you are getting? Commented Mar 31, 2014 at 18:21
  • the error is Windowserror:[Error 2] the system cannot find the file specified, it is the same error for the 2 ways I tried Commented Apr 1, 2014 at 8:58
  • be careful, with newer ffmpeg’s you need to use “-framerate” instead of “-r” for the input framerate: trac.ffmpeg.org/wiki/DirectShow#Specifyinginputframerate Commented Jun 3, 2014 at 21:52

6 Answers 6

3

I wanted to convert some movie files to audio files,but I couldn't get ffmpeg to execute in Python, until I explicitly included paths, something like:

import os

Executable = r'C:\Users\rrabcdef\Documents\p\apps\ffmpeg\ffmpeg.exe'
input = r'C:\Users\rrabcdef\Documents\p\myStuff\clip_1.mov'
output = r'C:\Users\rrabcdef\Documents\p\myStuff\clip_1.mp3'
myCommand = Executable + " -i " + input + " -f mp3 -ab 320000 -vn " + output
os.system(myCommand)
Sign up to request clarification or add additional context in comments.

1 Comment

simple, beautiful and elegant
1

This is an old post but I still find it useful today. I got mine working and so I would like to share that with you.

My video file is more than 3 hour long (3:09:09), I just wanted to extract one frame specifically at 20 minutes and 17 seconds (20:17) to a picture. So here's the working code (tested on Windows 10, 64-bit, Python 3.7):

import os
#Input video file
in_video=r"C:\temp\tu\my-trip-on-the-great-wall.rmvb"
#Output image file
out_image=r"C:\Users\rich_dad\Documents\test2.jpg"

#ffmpeg installation path
appDir=r"c:\ffmpeg\bin"

#Change directory on the go
os.chdir(appDir)

#Execute command
os.system("ffmpeg -ss 20:17 -i "+in_video+" -vframes 1 -q:v 2 "+out_image)

I would definitively add a loop to this if I need to get more photos out of a video. I hope you will find this useful.

Comments

0

Try this:

import os
os.system(cmd)

As far as I can tell this method isn't as advanced as subprocess, but it does what it's supposed to do.

1 Comment

i tried this too, doesn't work as well, thanks anyway
0

Without the error message, I can't tell, but most documentation says to use "ffmpeg.exe" as the binary when calling the executable. Also, you could make the args a list and pass it in:

NOT TESTED

import subprocess as sp

def get_ffmpeg_bin():
    ffmpeg_dir = "C:\\FFmpeg\\bin\\ffmpeg"
    FFMPEG_BIN = os.path.join(ffmpeg_dir, "ffmpeg.exe")
    return FFMPEG_BIN


pipe = sp.Popen([ffmpeg_binary, "-rtbufsize", "100000k", "-r", "65535/2733", "-f", "dshow", "-i", 'audio="virtual-audio-capturer":video="screen-capture-recorder"', "output100.avi"])

pipe.wait()

1 Comment

the error is Windowserror:[Error 2] the system cannot find the file specified, it is the same error for the 2 previous ways I tried
0

Windowserror:[Error 2] is coming due to shell=False error.

If You are running the command giving cmd as string, then you must use shell=True:

cmd='C:\FFmpeg\bin\ffmpeg -rtbufsize 100000k -r 65535/2733 -f dshow -i audio="virtual-audio-capturer":video="screen-capture-recorder" output100.avi'
subprocess.check_call(cmd, shell=True)

If you are running without shell=True, you have to pass cmd as list:

cmd='C:\FFmpeg\bin\ffmpeg -rtbufsize 100000k -r 65535/2733 -f dshow -i audio="virtual-audio-capturer":video="screen-capture-recorder" output100.avi'
subprocess.check_call([cmd])

above statements are same for Popen and check_call functions.

3 Comments

i still have the same error.I tried splitting the command also like this
def call_command(command): subprocess.check_call(command.split(' '),shell=True) call_command('C:\FFmpeg\bin\ffmpeg -rtbufsize 100000k -r 65535/2733 -f dshow -i audio="virtual-audio-capturer":video="screen-capture-recorder" output10.avi')
the error is the filename, directory name or volume label syntax is incorrect
0

user3 was almost right, you need to pass the command as a list of strings:

cmd=['C:\FFmpeg\bin\ffmpeg', '-rtbufsize', '100000k', '-r', '65535/2733', '-f', 'dshow', '-i', 'audio="virtual-audio-capturer":video="screen-capture-recorder"', 'output100.avi']
subprocess.check_call(cmd) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.