From: Scott Worley Date: Wed, 1 Oct 2025 01:12:32 +0000 (-0700) Subject: Option to record from webcam X-Git-Url: http://git.scottworley.com/srec/commitdiff_plain/07dc9ebeb425baaae6d1588e6e26687b36184c9b Option to record from webcam --- diff --git a/srec.py b/srec.py index da14735..d0a0392 100644 --- a/srec.py +++ b/srec.py @@ -33,16 +33,18 @@ def make_filename() -> str: return os.path.join(directory, f'srec {timestamp}.mkv') +def video_source(stack: Gtk.Stack) -> list[str]: + if stack.get_child_by_name('not_recording').get_first_child().get_active(): + return ['-f', 'v4l2', '-i', '/dev/video0'] + return ['-f', 'x11grab', '-i', ':0.0+0,0'] + + def on_start_recording(_: Gtk.Button, stack: Gtk.Stack) -> None: global recording # pylint: disable=global-statement assert recording is None filename = make_filename() - command = [ - 'ffmpeg', - '-framerate', '25', - '-f', 'x11grab', '-i', ':0.0+0,0', - '-f', 'pulse', '-ac', '2', '-i', 'default', - filename] # nopep8 + command = (['ffmpeg', '-framerate', '25'] + video_source(stack) + + ['-f', 'pulse', '-ac', '2', '-i', 'default', filename]) # pylint: disable=consider-using-with recording = Recording( filename=filename, @@ -80,6 +82,9 @@ def on_activate(app: Gtk.Application) -> None: nr_box = Gtk.Box() nr_box.set_orientation(Gtk.Orientation.VERTICAL) + webcam = Gtk.CheckButton(label='Webcam', active=True) + nr_box.append(webcam) + nr_box.append(Gtk.CheckButton(label='Screen', group=webcam)) nr_box.append(make_button("Start Recording", on_start_recording, stack)) stack.add_named(nr_box, "not_recording")