Just starting out in the wonderful world of RPi maker projects, scored a Model 2b v.1.1, installed the latest Raspbian and now ready for my first project :-)
What I want to build is a video player for an event which sends out GPIO triggers at specific time codes of the video (only 1 video is being used at this moment), i.e. at 00:32:12 in the video, trigger GPIO x which in turn switches off a light.
Hardware-wise, I think I'm all set, I have:
- A working Pi 2b 1.1
- a breadboard
- a double relay module
- wires etc.
Now all(?) I need is a way to sync the video time code to trigger the right GPIO. I've read a bit about omxplayer-wrapper and I'm aware of OSC, but perhaps my goal can be achieved much simpler since I don't need any external syncing.
Edit - So apparently, python-omxplayer-wrapper is the way to go, thanks to @jsotola for pointing me in the right direction. Actually, just launching the player and a GPIO script simultaneously with the right amount of sleep time works on a basic level. But since this approach provides no 'real' syncing, as soon as any delay is introduced for whatever reason, the timing goes bad. Hence the python-omxplayer-wrapper route.
After a lot of tinkering, I've got python-omxplayer-wrapper installed and working. I also got the GPIO part working (will provide more detail on both when I've got everything working), so all that's left is combining the two to trigger the GPIO's a the right time code.
That's where I got stranded in the provided example code:
from omxplayer import OMXPlayer from time import sleep from pathlib import Path #/* Setup the player as shown in omxplayer-wrapper examples : */ path = Path('Videos/myvideo.m4v') player = OMXPlayer(path, args=['--no-osd', '--blank']) player.pause() sleep(5) player.play() #/* Make a query to position() inside infinite loop : */ while (1): position = player.position() * 1000 # /* Event timecodes values are stored in "events" */ for event in events.values(): if position - 20 <= event['tc'] and position + 20 >= event['tc']: # /* Put your code here */ print("This is where the first GPIO should be triggered") player.quit()
When I run this, the video plays fine, but then I get this message in the terminal:
Traceback (most recent call last): File "./bm_test.py", line 21, in <module> for event in events.values(): NameError: name 'events' is not defined
Unfortunately, I don't have enough reputation yet to respond to the author of the script (source: Simon's answer at https://stackoverflow.com/questions/45532783/fire-events-at-specific-timestamps-during-video-playback/), but apparently I need to do something with events. Now I'm not sure if this requires extra packages, such as https://pypi.org/project/Events/ and perhaps https://pypi.org/project/timecode/ , or it's just a matter of adding some extra code.
Being a complete beginner with Python, I need some help here :-)