SHARE
    TWEET
    Najeebsk

    DESKTOP_RECODER.pyw

    Jun 15th, 2024
    811
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 3.61 KB | None | 0 0
    1. import sys
    2. import subprocess
    3. from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QVBoxLayout, QWidget
    4. from PyQt5.QtCore import QThread, pyqtSignal, pyqtSlot
    5. class Recorder(QThread):
    6. changeStatus = pyqtSignal(str)
    7. def __init__(self, ffmpeg_path):
    8. super().__init__()
    9. self.recording = False
    10. self.process = None
    11. self.ffmpeg_path = ffmpeg_path
    12. def run(self):
    13. self.recording = True
    14. command = [
    15. self.ffmpeg_path,
    16. '-y', # Overwrite output file if it exists
    17. '-f', 'gdigrab',
    18. '-framerate', '20',
    19. '-i', 'desktop', # Capture the entire desktop
    20. '-c:v', 'libx264',
    21. '-preset', 'ultrafast',
    22. 'output.mp4'
    23. ]
    24. try:
    25. self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    26. self.changeStatus.emit("Recording started...")
    27. while self.recording:
    28. output = self.process.stderr.readline()
    29. if output == '' and self.process.poll() is not None:
    30. break
    31. if output:
    32. print(output.strip())
    33. if self.process.poll() is None:
    34. self.process.terminate()
    35. self.process.wait()
    36. self.changeStatus.emit("Recording stopped and saved to output.mp4.")
    37. except Exception as e:
    38. self.changeStatus.emit(f"Error: {e}")
    39. self.recording = False
    40. def stop_recording(self):
    41. self.recording = False
    42. if self.process and self.process.poll() is None:
    43. self.process.terminate()
    44. self.process.wait()
    45. class App(QMainWindow):
    46. def __init__(self, ffmpeg_path):
    47. super().__init__()
    48. self.setWindowTitle("Desktop Video Recorder")
    49. self.setGeometry(100, 100, 400, 200)
    50. self.recorder = None
    51. self.ffmpeg_path = ffmpeg_path
    52. self.initUI()
    53. def initUI(self):
    54. self.status_label = QLabel("Press Start to begin recording the desktop.", self)
    55. self.status_label.resize(400, 50)
    56. self.start_button = QPushButton("Start Recording", self)
    57. self.start_button.clicked.connect(self.start_recording)
    58. self.stop_button = QPushButton("Stop Recording", self)
    59. self.stop_button.clicked.connect(self.stop_recording)
    60. self.stop_button.setEnabled(False)
    61. layout = QVBoxLayout()
    62. layout.addWidget(self.status_label)
    63. layout.addWidget(self.start_button)
    64. layout.addWidget(self.stop_button)
    65. container = QWidget()
    66. container.setLayout(layout)
    67. self.setCentralWidget(container)
    68. def start_recording(self):
    69. self.recorder = Recorder(self.ffmpeg_path)
    70. self.recorder.changeStatus.connect(self.updateStatus)
    71. self.recorder.start()
    72. self.start_button.setEnabled(False)
    73. self.stop_button.setEnabled(True)
    74. def stop_recording(self):
    75. if self.recorder:
    76. self.recorder.stop_recording()
    77. self.recorder.wait()
    78. self.stop_button.setEnabled(False)
    79. self.start_button.setEnabled(True)
    80. @pyqtSlot(str)
    81. def updateStatus(self, message):
    82. self.status_label.setText(message)
    83. print(message) # Print to console for debugging
    84. if __name__ == '__main__':
    85. ffmpeg_path = r'C:\CMDER\APP\ffmpeg.exe' # Update with your ffmpeg path
    86. app = QApplication(sys.argv)
    87. ex = App(ffmpeg_path)
    88. ex.show()
    89. sys.exit(app.exec_())
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /