def start_process(self):
"""
Start the ffmpeg subprocess
"""
if self.process and self.process.poll() is None:
raise RuntimeError('Refusing to start process when already running')
cmd = self.get_process_command()
self.process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.DEVNULL,
)
# Make the pipes non-blocking
flags = fcntl.fcntl(self.process.stdout, fcntl.F_GETFL)
fcntl.fcntl(self.process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
flags = fcntl.fcntl(self.process.stderr, fcntl.F_GETFL)
fcntl.fcntl(self.process.stderr, fcntl.F_SETFL, flags | os.O_NONBLOCK)
# Clear any output from previous incarnations
self.clear_process_stdout()
self.clear_process_stderr()
# Update the UI when there's output from the process
def output_callback(fd, condition, pipe, func):
""" Read from pipe, and pass to the given func """
output = pipe.read()
if not output:
return False
func(output.decode('utf-8'))
return condition != GLib.IO_HUP
stdout_read_cb = GLib.io_add_watch(
self.process.stdout,
GLib.PRIORITY_DEFAULT,
GLib.IO_IN | GLib.IO_HUP,
output_callback,
self.process.stdout,
self.append_process_stdout,
)
GLib.io_add_watch(
self.process.stderr,
GLib.PRIORITY_DEFAULT,
GLib.IO_IN | GLib.IO_HUP,
output_callback,
self.process.stderr,
self.append_process_stderr,
)
# Update the UI
self.show_process_state()
评论列表
文章目录