I am experimenting with video playback using python for a small project I am working on. Basically I want to be able to play a certain video clip dependent upon a action.
To start with I have been experimenting with a sort of screen saver video, this is a video that plays when nothing happens, the video loops.
When something happens, such as motion is detected, the looping video needs to pause or stop and a different video will be played, once the second video has finished, if nothing else has happened the first video will continue (if paused) or start again.
I have managed to get this working using two separate videos but when the first video pauses although I can hear the second video it is hidden by the first?? I think the problem can be solved using different video layers but can't work out how to do this?
Here is my code, the first video plays and loops and the second video starts when motion is detected, currently when motion is detected again the video says its playing again but does not appear to do so?
Code: Select all
#!/usr/bin/env python
#Import libraries
import time
from omxplayer import OMXPlayer
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
PIR_PIN = 7
GPIO.setup(PIR_PIN,GPIO.IN)
print("Starting visual front end")
wait_loop1 = OMXPlayer('/home/pi/Videos/Vid_Wait_Loop1.mp4',args=['--loop'])
vid1 = OMXPlayer('/home/pi/Videos/Vid_Name_Hammerstein.mp4')
wait_loop1.play()
try:
print("Motion detection activated")
time.sleep(2)
print("Security alarm functioning")
while True:
if GPIO.input(PIR_PIN):
wait_loop1.pause()
print("Intruder Detected")
vid1.play()
print("Playing Vid_Name_Hammerstein")
time.sleep(10)
vid1.quit()
except KeyboardInterrupt:
print("terminated by user")
wait_loop1.quit()
vid1.quit()
GPIO.cleanup()I started this a while ago but left it to move on to other things.
