Python - ffmpeg(启动,停止录制的命令)

时间:2017-11-24 11:36:22

标签: python cmd ffmpeg command

我需要一个可以打开cmd的程序,并且有一个命令可以在cmd中开始录制并停止在cmd中录制

import win32com.client
from datetime import datetime
import time

shell = win32com.client.Dispatch("WScript.Shell")
shell.run("cmd") #run's command panel
shell.AppActivate("cmd")
time.sleep(3) #wait's 3 seconds
shell.SendKeys('ffmpeg -y -f dshow -i video="Logitech HD Webcam C270"  
kamera.mp4') #type's in cmd the following (start's recording)
time.sleep(3)
shell.SendKeys("{ENTER}") #enter is pressed in cmd
time.sleep(6)
shell.SendKeys('exit')
shell.SendKeys("{ENTER}") #here is a problem, the proggrame wont shutdown after 6 sec

我可以在ffmpeg中使用-t 00:00:03,但我需要通过命令关闭程序

1 个答案:

答案 0 :(得分:1)

我已经自己破解了,如果有人需要这里的代码,那就是:

import win32com.client
from datetime import datetime
import time

datestring = datetime.strftime(datetime.now(), '%Y-%m-%d-%H-%M-%S')
shell = win32com.client.Dispatch("WScript.Shell")

shell.run("cmd")
shell.AppActivate("cmd")

#shell.run('ffmpeg -y -f dshow -i video="Logitech HD Webcam C270"  kamera' + datestring + '.mp4')
time.sleep(2)
shell.SendKeys('ffmpeg -y -f dshow -i video="Logitech HD Webcam C270"  kamera.mp4')
time.sleep(2)
shell.SendKeys("{ENTER}")
time.sleep(10)
shell.SendKeys('^c')
time.sleep(2)
shell.SendKeys("{ENTER}")