Python Script freeze video while execute

nicotino

New Member
Hi, I'm creating a script to add a "Now Playing" from VLC video source. It basicaly get the pid of the obs proccess, get all files used by it, and filter the file type. Once I get the file I read the metadata(title) and set this result into a text source. This procedure works just fine, but, it take aproximately 1 second to run. While running it the video get freezed, and when finish the video continue. Why happend that?? There is a solution??
For testing purpose, I add a sleep in that function and the video freeze durings that seconds...

Part of the script:
Python:
def find_nowplaying_file(path):
    time.sleep(7)
    # Get the PID
    for proc in psutil.process_iter(attrs=['pid', 'name']):
        if proc.name() == 'obs64.exe' :
            obs_proc=proc
            break
        #print (proc.info)
    print ("OBS PID: ",obs_proc.pid)
    obs_proc=psutil.Process(obs_proc.pid)
    

    print("PATH:",os.path.abspath(path))
    # Get the file used by OBS filtered by settings path
    for archivo in obs_proc.open_files():
        if os.path.abspath(archivo[0]).startswith(os.path.abspath(path)):
            video=archivo[0]
            print ("ARCHIVO:",archivo[0])
            break

    with open(video, 'rb') as f:
        mkv = enzyme.MKV(f)
    
    #print (mkv.info.title)
    return mkv.info.title

def update_text():
    global interval
    global source_name

    text = find_nowplaying_file("C:/Streaming/VideoTEST")
    if text is None:
            text = "No Title"
            
    source = obs.obs_get_source_by_name(source_name)
    if source is not None:
        settings = obs.obs_data_create()
        obs.obs_data_set_string(settings, "text", text)
        obs.obs_source_update(source, settings)
        obs.obs_data_release(settings)

        obs.obs_source_release(source)

    
    print("Run")
        
def refresh_pressed(props, prop):
    update_text()

def script_update(settings):
    global interval
    global source_name

    interval    = obs.obs_data_get_int(settings, "interval")
    source_name = obs.obs_data_get_string(settings, "source")

    obs.timer_remove(update_text)

    if source_name != "":
        obs.timer_add(update_text, interval * 1000)
 

RomJosh

New Member
I faced similar issue (if you still do...). You should execute you update_text() function within a thread to avoid freezing of the video.
 

joeyzhang105

New Member
sorry to bring this up again, but I encounter exactly the same problem, obs.timer_add freezes my playing video every interval time.
so it there any solution to work around?
 
Top