问题
**It's my first time posting on Stack Overflow so please excuse any formatting issues - I'll try to improve as I go! **
I am building an artwork that uses looped videos on multiple screens, and I need the video to jump to a specific point when a trigger is activated (in the end via a motion sensor).
I would like the program to make the video jump to a specific point in a video using OMXplayer on Raspberry Pi. In the end, I hope to do this with a signal coming from a PIR motion sensor wired into the GPIO pins in the Pi, but for now I am testing with a key entry. I am using OMXplayer-wrapper by Will Price, which so far has been pretty effective, but I'm missing some logic and would appreciate any help (https://github.com/willprice/python-omxplayer-wrapper/)
I have some code written that uses the seek() function (see below) triggered off a key entry in Python. This is working, and I can make the video seek forward (not backward). Worst case scenario, I will program the video to loop a section and then jump forward if needs be, but this will make everything a little more complicated. Ideally, I need to jump to an absolute position.
From the documentation (https://python-omxplayer-wrapper.readthedocs.io/en/latest/omxplayer/) I found the function to 'seek': seek(relative_position)[source] Seek the video by relative_position seconds
Parameters: relative_position (float) – The position in seconds to seek to.
This works fine, but it only seeks forward and only to a relative point. I would like to use a function that will:
video.seek(absolute_position)
I am pretty sure this can be done, and have looks at: positionEvent = None Event called on setting position callback(player, absolute_position)
But I am missing something here. This doesn't seem to operate as a function. I hope this is just my dithering logic and not an impossible quest - any help would be very much appreciated.
from omxplayer.player import OMXPlayer #runs from the popcornmix omxplayer wrapper at https://github.com/popcornmix/omxplayerhttps://github.com/popcornmix/omxplayer and https://python-omxplayer-wrapper.readthedocs.io/en/latest/)
from pathlib import Path
import time
import subprocess
VIDEO_PATH = Path("video.mp4") #any test video - this works, loads and plays
player = OMXPlayer(VIDEO_PATH)
positionEvent = 3
while True:
key = input()
currtime = player.position()
#below an attempt at looping back 3 seconds after the first thrre seconds. This is not working.
if(currtime > 3):
player.seek(-300)
print(currtime)
#below seek works fine when I enter the key, but it only seeks to a relative position
if key == 'h':
player.seek(300)
sleep(5)
No error messages here. The video plays, and the seek forward works. I just want to see if I can get the video to seek to an absolute position. Maybe I'm missing something simple - I hope so.
There are keycodes for absolute seek, but I don't know how to call these: omxplayer.keys.SEEK_ABSOLUTE = 26¶
Again, any help would be very much appreciated.
来源:https://stackoverflow.com/questions/56282992/omxplayer-wrapper-and-python-jump-to-a-specific-point-in-video