I need help with my moviefileout operator. Indeed, I’m writing a video file to disk, that I need to load immediately using a moviefilein. Yes, I need to write it down on the disk before reloading it.
The issue is that sometimes the moviefilein loads the movie before moviefileout has finished writing it completely. How can I make sure to avoid this?
Is there a callback function to ensure moviefileout finished writing?
Or is there a python function (“open” seems not to make the deal) to check whether the file is valid?
How are you controlling your movie file out? Is this scripted or CHOPs?
I typically use a timer CHOP for writing movies to disk. You could use the done channel with a delay CHOP to offset your loading of the movie file TOP. Does that help?
Hey! I just dealt with some of this myself - you might want to kick off a python watchdog process in a standalone instance of Python and have it phone back to a listener in TD when it sees event.type == ‘modified’. Here’s an example to get you going:
[code]
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
from watchdog.events import FileSystemEventHandler
WATCHPATH = ‘somepath/path’
FILETYPE = ‘*.mp4’
class Watcher:
def init(self):
self.observer = Observer()
class Handler(PatternMatchingEventHandler): @staticmethod
def on_any_event(event):
if event.is_directory:
return None
elif event.event_type == 'modified':
# Take any action here when a file is modified or when it's finished writing to disk
print("Received modified event - %s." % event.src_path)
elif event.event_type == 'created':
# Taken any action here when a file is created.
print("Received created event - %s." % event.src_path)
else:
print('Received other event: {} {}'.format(event.event_type, event.src_path))
A timer is not the solution I prefer, as it is not a guarantee that my file is completely written, nor that I spend too much time waiting for it to complete even if it might be completed already.
The watchdog solution is neat! Only thing is that I need to run a parallel task for it! But otherwise, very good! And moreover, it gave me the idea of using the os.path.getmtime(“test.mp4”)) function, to check if my file is still being modified (and thus the file modified time is still changing). I’m still investigating this solution…
Another solution which came to my mind this morning was to use the warning message of the moviefilein operator: if the moviefilein operator has a “warning” message, I try to “reload” my file till there is no “warning” message anymore. It sounds like the perfect solution for me! The only question is:
How do I get access to the warning message of the moviefilein operator?
I tried with “op(‘/project1/Monitor/element0/moviefilein1’).warnings” but I get a “<built-in method warnings of td.moviefileinTOP object at 0x11cd330a8>”. Is there a way to count or get the error message/code of an operator?
You could also considering using the python threading library to spawn a ‘followup’ thread to take care of this task for you without blocking the main thread, although watchdog is threaded itself and shouldn’t be blocking either.