Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save onyx-and-iris/3170490d4fb1cfe31127951395b0bc55 to your computer and use it in GitHub Desktop.
Save onyx-and-iris/3170490d4fb1cfe31127951395b0bc55 to your computer and use it in GitHub Desktop.
OBS - Stop record, delete file and then start recording again
#!/usr/bin/env python3
# LICENSE: GPL-3.0-or-later
# Copyright (C) 2025 Onyx and Iris
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
__version__ = "0.2.0"
from pathlib import Path
import time
import obsws_python as obs
def on_record_state_changed(data):
if data.output_state == "OBS_WEBSOCKET_OUTPUT_STOPPED":
file_pn = Path(data.output_path)
if file_pn.exists():
print(f"Deleting file: {file_pn}")
file_pn.unlink()
def main():
with (
obs.ReqClient() as req_client,
obs.EventClient() as event_client
):
resp = req_client.get_record_status()
if not resp.output_active:
print("Recording is not active.")
return
event_client.callback.register(on_record_state_changed)
req_client.stop_record()
time.sleep(1) # Wait for the stop to complete
req_client.start_record()
print("New recording started.")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment