MKV script for handling a counter

Iraito

New Member
Ok i have a video of multiple drops of particles, i wanna use that video for a death counter, i was thinking if it was possible to add chapters to the mkv and create a script that plays one chapter, stops and with the press of a hotkey it would go to the next one.
 

AaronD

Active Member
I don't know how to do that *exactly*, but treating it as an XY problem got me this:

Load the original video into an editor, split it into the sections that you want, and save both the sections as their own videos and the still frames at each split point. Then put each of those sections into its own scene in OBS, and likewise for the still frames. Set up a series of macros in the Advanced Scene Switcher plugin, for each of the sections being done, and cut to the corresponding still frame. Then to show the next section, just cut to its scene.
Or if OBS hangs on the last frame, then you don't need the still images or the automation to show them.
 

Iraito

New Member
I did something similar in the past, it was heavy as hell on resources, that's why i would like to use obs scripts and a way to simply play and stop a video, if i have to split 1000 drops in 1000 videos it's the end.
 

Iraito

New Member
Python:
import time
import keyboard
 
 # Define the timestamps in hours, minutes, and seconds
timestamps = [
     (0, 0, 10),   # 00:00:10
     (0, 1, 30),   # 00:01:30
     (0, 3, 45)    # 00:03:45
 ]
 
 # Function to play media at a specific timestamp
def play_media(timestamp):
     # Convert the timestamp to seconds
     seconds = timestamp[0] * 3600 + timestamp[1] * 60 + timestamp[2]
    
     # Set the media playback position in OBS
     # Replace 'media_source' with the actual name of your media source in OBS
     obs.media_source_set_position('SaltCounter', seconds)
    
     # Start playing the media
     obs.media_play('SaltCounter')
 
 # Loop through the timestamps and play media at each timestamp
for timestamp in timestamps:
     # Play media at the current timestamp
     play_media(timestamp)
    
     # Pause the script for 2 seconds
     time.sleep(2)
    
     # Pause the media playback
     obs.media_pause('SaltCounter')
    
     # Wait for the hotkey to resume playback
     keyboard.wait('space')
    
     # Resume the media playback


So this script should do the job but i'm having issues:

[Salt_counter.py] Traceback (most recent call last):
[Salt_counter.py] File "C:\Salt_counter.py", line 26, in <module>
[Salt_counter.py] play_media(timestamp)
[Salt_counter.py] File "C:\Salt_counter.py", line 18, in play_media
[Salt_counter.py] obs.media_source_set_position('SaltCounter', seconds)
[Salt_counter.py] ^^^
[Salt_counter.py] NameError: name 'obs' is not defined. Did you mean: 'abs'?
 

AaronD

Active Member
You haven't defined what "obs" is yet. So python doesn't recognize it.

You'll need to import it, but it escapes me now, what it's actually called to import.
 

Iraito

New Member
Yeah that seems to be the thing that's blocking me from having the script functioning, i really need this script to work.
 

Iraito

New Member
I solved it outside of OBS, a kind soul created a script to stop MPV at every chapter, it works really well but i would still like to see a script that handles something this simple directly in OBS.
 

AaronD

Active Member
You haven't defined what "obs" is yet. So python doesn't recognize it.

You'll need to import it, but it escapes me now, what it's actually called to import.

Someone just happened to post it:
Python:
import obspython as obs
If you want to come back to this, see if that works.
 
Top