例如cmd的命令应该是
ffmpeg -i "D:/video/test.mp4" -acodec copy -vn "D:/video/test.aac"
用python调用cmd
import os
os.system('ffmpeg -i "D:/video/test.mp4" -acodec copy -vn "D:/video/test.aac"')
传参数给cmd命令
应该按照下面这样来传参数。应该使用三个单引号来把 字符串 引起来,可以避免cmd命令里的双引号,单引号。
import os
cmd48 = '''ffmpeg -i "''' + path + '''" -acodec copy -vn "''' + os.path.splitext(path)[0] + '''.aac"'''
os.system('%s' % (cmd48))
下面是我写的完整的代码
# -*- coding: utf-8 -*-
import os
from tkinter import *
import tkinter.filedialog
root = Tk()
def window48():
filenames = tkinter.filedialog.askopenfilenames()
if len(filenames) != 0:
for i in range(0, len(filenames)):
path = filenames[i]
print(path)
cmd48 = '''ffmpeg -i "''' + path + '''" -acodec copy -vn "''' + os.path.splitext(path)[0] + '''.aac"'''
os.system('%s' % (cmd48))
print('完成了'+os.path.dirname(filenames[0]))
else:
lb.config(text = "You did not select any files")
def center_window(w, h):
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# 计算 x, y 位置
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
center_window(425, 210)
lb = Label(root, text='please install ffmpeg before use')
lb.pack()
btn = Button(root, text="please select video file", command=window48)
btn.pack()
root.mainloop()