Hello,
I need to set up a script to record at certain times. I setup the below script. However the latest version of OBS does not like it. It crashes with nothing pertinent in the log to explain why. Actually it just hangs indefinitely, once I click something in the OBS window it then asks me to shutdown the process.
I need to set up a script to record at certain times. I setup the below script. However the latest version of OBS does not like it. It crashes with nothing pertinent in the log to explain why. Actually it just hangs indefinitely, once I click something in the OBS window it then asks me to shutdown the process.
Python:
import os
import time
import subprocess
import schedule
# Set the start and end times for the first recording session
session1_start_time = "08:28"
session1_end_time = "17:00"
# Set the start and end times for the second recording session
session2_start_time = "17:30"
session2_end_time = "03:30"
# Set the duration of the recording in seconds
duration = 36000
# Set the path to your OBS executable
obs_path = 'C:\\Program Files\\obs-studio\\bin\\64bit\\obs64.exe'
# Set the path to your OBS recording profile
profile_path = 'C:\\Users\\admcarrara\\AppData\\Roaming\\obs-studio\\basic\\profiles\\Untitled'
# Set the path to the folder where you want to save your recordings
output_folder = 'C:\\Users\\admcarrara\\Videos'
# Function to start the recording
def start_recording():
# Get the current time
now = time.strftime("%H:%M", time.localtime())
# Start the first session of recording if the current time matches the session 1 start time
if now == session1_start_time:
# Set the start time for the recording in seconds since epoch
start_time_sec = time.time()
# Start the recording
subprocess.call([obs_path, '--startrecording', '--minimize-to-tray', '--profile', profile_path, '--output', os.path.join(output_folder, 'Session1_Recording_{0}.mp4'.format(time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(start_time_sec))))])
# Wait for the duration of the recording
time.sleep(duration)
# Stop the recording
subprocess.call([obs_path, '--stoprecording'])
# Start the second session of recording if the current time matches the session 2 start time
elif now == session2_start_time:
# Set the start time for the recording in seconds since epoch
start_time_sec = time.time()
# Start the recording
subprocess.call([obs_path, '--startrecording', '--minimize-to-tray', '--profile', profile_path, '--output', os.path.join(output_folder, 'Session2_Recording_{0}.mp4'.format(time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(start_time_sec))))])
# Wait for the duration of the recording
time.sleep(duration)
# Stop the recording
subprocess.call([obs_path, '--stoprecording'])
# Schedule the recording sessions to run every day
schedule.every().day.at(session1_start_time).do(start_recording)
schedule.every().day.at(session2_start_time).do(start_recording)
# Run the scheduled tasks
while True:
schedule.run_pending()
time.sleep(1)