Posts: 21
Joined: Thu Mar 05, 2015 3:41 pm

Playing 2 videos one after the other using Omxplayer

Thu Feb 09, 2017 3:11 pm

Hi all,

Ive been trying to feed a playlist into Omxplayer to run through with near no gaps inbetween. Ive managed to find this post viewtopic.php?f=38&t=101425, slightly changed it and worked perfectly on a Pi i built about a year ago - thanks Douglas6!

Code: Select all


import subprocess
import time

v1 = "/home/pi/videos/1.mp4"
v2 = "/home/pi/videos/6.mp4"
name2 = "org.mpris.MediaPlayer2.omxplayer2"
name3 = "org.mpris.MediaPlayer2.omxplayer2"

#Cache the first video by loading and then sending a pause command
p1 = subprocess.Popen(["omxplayer", v1, "--no-osd"], stdin=subprocess.PIPE)

#Test loop 2 videos 10000 times
count = 0
while (count < 10000):

#From this point in python we are in a loop, all code in a loop has to be indented.
#Play video 1 by sending the pause command again which unpauses the video.

#Whilst the first video plays, we are now going to load the second video and pause it
	p2 = subprocess.Popen(["omxplayer", v2, "--no-osd"], stdin=subprocess.PIPE)

#We're going to play the first video for 3 seconds

#Now we're going to quit the first video and then unpause the second

#As we have quit the first video, we need to load it again and pause.
#We cant send a rewind command, doesnt work correctly in OMXPlayer 
	p1 = subprocess.Popen(["omxplayer", v1, "--no-osd", "--dbus_name", name3], stdin=subprocess.PIPE)

#We're gonna play the second video for 5 seconds and quit.

#Increment the count by 1
	count = count + 1
I've just built a new Pi using the latest Jessie with Pixel, set to boot to console, tried the same code but it errors with

Traceback (most recent call last):
File "", line 34, in <module>
IOError: [Errno 32] Broken Pipe

Then about 5 seconds later I get

"Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply time out expired, or the network connection was broken."

My coding skills are pretty basic and my background is in Microsoft so im wondering if im missing something really simple but ive been at this problem for 2 days now and just going blind so some help would be greatly appreciated!

User avatar
Posts: 4779
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Playing 2 videos one after the other using Omxplayer

Fri Feb 10, 2017 1:11 am

I can't really reply to that. I haven't used omxplayer since I wrote that post. I'm not aware of any changes in Python that would cause your issue. It's odd that the quit command failed while the pause command apparently succeeded. No idea.

Return to “Python”