Python 屏幕录制和声音录制 GUI
以下是一个使用 Python 编写的录制屏幕和声音的 GUI 程序:
import tkinter as tk
import threading
import subprocess
class ScreenRecorderGUI:
def __init__(self, root):
self.root = root
self.root.title('Screen Recorder')
self.start_btn = tk.Button(self.root, text='Start Recording', command=self.start_recording)
self.start_btn.pack(pady=10)
self.stop_btn = tk.Button(self.root, text='Stop Recording', state=tk.DISABLED, command=self.stop_recording)
self.stop_btn.pack(pady=10)
def start_recording(self):
self.start_btn.config(state=tk.DISABLED)
self.stop_btn.config(state=tk.NORMAL)
self.recording_thread = threading.Thread(target=self.record_screen_and_audio)
self.recording_thread.start()
def stop_recording(self):
self.stop_btn.config(state=tk.DISABLED)
self.recording_thread.join()
def record_screen_and_audio(self):
subprocess.call('ffmpeg -f avfoundation -i :0.0 -f avfoundation -i :1 -c:v libx264 -preset ultrafast output.mp4', shell=True)
if __name__ == '__main__':
root = tk.Tk()
app = ScreenRecorderGUI(root)
root.mainloop()
这个程序使用 tkinter 库创建一个 GUI 窗口,并在窗口中添加了'Start Recording' 和 'Stop Recording' 按钮。点击 'Start Recording' 按钮后,程序将调用 ffmpeg 命令来录制屏幕和声音,并将录制结果保存为 output.mp4 文件。点击 'Stop Recording' 按钮后,程序将停止录制。
请注意,要运行此程序,您需要在系统上安装 ffmpeg 软件,并将其添加到系统的环境变量中。此外,此程序仅在 Mac OS 上进行了测试。如果您在其他操作系统上使用此程序,您可能需要修改 ffmpeg 命令的参数以适应您的系统。
原文地址: https://www.cveoy.top/t/topic/SAA 著作权归作者所有。请勿转载和采集!