import subprocess import os import keyboard command2 = 'ffmpeg' command = 'ffmpeg -f gdigrab -framerate 60 -offset_x 640 -offset_y 340 -video_size 640x360 -i desktop -c:v libx264 -pix_fmt bgra -preset ultrafast -crf 0 16562015027263.avi && ffmpeg2.exe -i 16562015027263.avi -vf "scale=iw*6:-1:flags=neighbor" -crf 0 -c:v h264_nvenc -pix_fmt bgra -b:v 50000k 16562015027263upscale.avi' command3 = 'ffmpeg -y -f gdigrab -framerate 60 -offset_x 640 -offset_y 340 -video_size 640x360 -i desktop -c:v libx264 -pix_fmt bgra -preset ultrafast -crf 0 1.avi' command4 = 'ffmpeg -i 1.avi -vf "scale=iw*6:-1:flags=neighbor" -crf 0 -c:v h264_nvenc -pix_fmt bgra -b:v 50000k 2.avi' #p1 = subprocess.run(command3, shell=True, capture_output=True) #print(p1) p = subprocess.Popen(command3, shell=True) while True: if keyboard.is_pressed("f9"): print("You pressed 'f9'.") #p.communicate(input='q')[0] os.system("taskkill /f /im ffmpeg.exe") p = subprocess.Popen(command4, shell=True) break a