willprice / python-omxplayer-wrapper

:tv: Control OMXPlayer, the Raspberry Pi media player, from Python
http://python-omxplayer-wrapper.readthedocs.io
GNU Lesser General Public License v3.0
253 stars 71 forks source link

Not able to open two players at once and hide one video #123

Closed houtanb closed 6 years ago

houtanb commented 6 years ago

Issue Report

Description

I try to open two players. I hide both then play one. After a few seconds, both videos are flashing on the screen when I should never see the video in player1.

Problem reproduction

import time
from omxplayer.player import OMXPlayer

player0 = OMXPlayer('a.mp4', args=['--no-osd'])
player0.pause()
player0.hide_video()

player1 = OMXPlayer('b.mp4', args=['--no-osd'])
player1.pause()
player1.hide_video()

time.sleep(2)

player0.show_video()
player0.play()

time.sleep(2)

player0.pause()
player0.hide_video()

player0.quit()
player1.quit()

Environment details

Software Version
python-omxplayer-wrapper 0.1.0
python-dbus (dpkg -s python-dbus) 1.2.4-1
python (python --version) 2.7.13
omxplayer (omxplayer --version) 5a25a57
sevildevil1990 commented 6 years ago

Hi, try using the --layer argument on both of the players, with args=['--layer','2'] for player0 and args=['--layer','1'] for player1.

This should keep player0 on the foreground layer.

EDIT: Sorry, wasn't the layer-arg since you wanted player1 to never show anyway. My bad!

In that case, just add a unique dbus_name to each player, so that the script knows which instance of the omxplayer to reference

player0 = OMXPlayer('a.mp4', args=['--no-osd'], dbus_name="omxplayer.player0")
player0.pause()

player1 = OMXPlayer('b.mp4', args=['--no-osd'], dbus_name="omxplayer.player1")
player1.pause()
houtanb commented 6 years ago

@sevildevil1990 Thanks so much! So for me the limit seems to be 3 videos as on playing the fourth the screen goes black. I guess this is hitting the limits of the graphics card? Do you have any suggestions for increasing the number of videos that can be played? I've bumped my graphics card memory up to 500MB, which is far more than the several MB that the videos consume.....

Basically, I don't want to launch a new omxplayer instance when I need a new video because I need to avoid the startup lag (I want the videos to play on button press and the startup lag ruins the effect I'm going for)

For some reason this code works better than the looped version below....

import time
from omxplayer.player import OMXPlayer

player0 = OMXPlayer('a.mp4', args=['--no-osd'], dbus_name='org.mpris.MediaPlayer2.omxplayer' + str(0))
player0.pause()
player0.hide_video()

player1 = OMXPlayer('b.mp4', args=['--no-osd'], dbus_name='org.mpris.MediaPlayer2.omxplayer' + str(1))
player1.pause()
player1.hide_video()

player2 = OMXPlayer('c.mp4', args=['--no-osd'], dbus_name='org.mpris.MediaPlayer2.omxplayer' + str(2))
player2.pause()
player2.hide_video()

player3 = OMXPlayer('d.mp4', args=['--no-osd'], dbus_name='org.mpris.MediaPlayer2.omxplayer' + str(3))
player3.pause()
player3.hide_video()

player4 = OMXPlayer('e.mp4', args=['--no-osd'], dbus_name='org.mpris.MediaPlayer2.omxplayer' + str(4))
player4.pause()
player4.hide_video()

player5 = OMXPlayer('f.mp4', args=['--no-osd'], dbus_name='org.mpris.MediaPlayer2.omxplayer' + str(5))
player5.pause()
player5.hide_video()

time.sleep(2)

player0.show_video()
player0.play()

time.sleep(2)

player0.pause()
player0.hide_video()

player1.show_video()
player1.play()

time.sleep(2)

player1.pause()
player1.hide_video()

player2.show_video()
player2.play()

time.sleep(2)

player2.pause()
player2.hide_video()

player3.show_video()
player3.play()

time.sleep(2)

player3.pause()
player3.hide_video()

player4.show_video()
player4.play()

time.sleep(2)

player0.quit()
player1.quit()
player2.quit()
player3.quit()
player4.quit()
player5.quit()

Looped version:

import time
from omxplayer.player import OMXPlayer

names = 'a.mp4', 'b.mp4', 'c.mp4'
players = []

for idx, movie in enumerate(names):
    players.append(OMXPlayer(movie, args=['--no-osd'], dbus_name='org.mpris.MediaPlayer2.omxplayer' + str(idx)))
    time.sleep(0.1)
    players[idx].pause()
    time.sleep(0.1)
    players[idx].hide_video()
    time.sleep(0.1)

time.sleep(2)

for idx in range(len(names) - 1):
    players[idx].pause()
    time.sleep(0.1)
    players[idx].hide_video()
    time.sleep(0.1)
    players[idx+1].show_video()
    time.sleep(0.1)
    players[idx+1].play()
    time.sleep(2)

[p.quit() for p in players]
sevildevil1990 commented 6 years ago

@houtanb I think we're running more into issues with the Raspi's overall performance.

On the button press: Will there be buttons to access all of the videos at random, or will it be more like a 'next' button? For the last case, you could only use two players: One that is playing the current video and one that already loads the next video into the memory. While pressing the button you would start the already loaded video, stop the previous player (and by that killing it's process) and then prepare the player for the next video in the queue.

houtanb commented 6 years ago

@sevildevil1990 Thanks for taking the time to respond. But, in effect, I am looking for something more like the former. 3 buttons and 6 videos: one video for button press and one for button release. And there's no knowing what action will come ahead of time

houtanb commented 6 years ago

I will close this issue as it is not a bug with the python-omxplayer-wrapper

MakeProjects commented 6 years ago

Hello everyone,

I´m trying to switch two video faster, but I always get an error when try to use different playersx, for example:

#!/usr/bin/env python3
import time
from omxplayer.player import OMXPlayer
import os.path
from time import sleep
import subprocess
from keyb import KBHit
import os

vid1 = 'Videos/video1.mp4'
vid2 = 'Videos/video2.mp4'

player0 = OMXPlayer(vid1, args=['--no-osd','--blank'],dbus_name="omxplayer.player0",)
player0.pause()

player1 = OMXPlayer(vid2, args=['--no-osd','--blank'],dbus_name="omxplayer.player1",)
player1.pause()

player0.quit()
player1.quit()

I got this error:

Traceback (most recent call last):
  File "prueba6.py", line 15, in <module>
    player0.pause()
  File "<decorator-gen-56>", line 2, in pause
  File "/usr/local/lib/python3.4/dist-packages/omxplayer/player.py", line 46, in wrapped
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/omxplayer/player.py", line 497, in pause
    self._player_interface.Pause()
  File "/usr/local/lib/python3.4/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/local/lib/python3.4/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus)

I tried to develop different examples, but alway that I use something different like single player.quit () or player.play, etc I did not work. I got work with player0 but when i try to pause this video or user play1 is impossible.

Any ideas?

thanks

houtanb commented 6 years ago

First, please enclose code in "```". See: Github Markdown

Second, I don't quite understand what you're saying. But the Raspberry Pi has trouble supporting more than one omxplayer at a time.

The solution for me was to link all the videos together then jump to different positions depending on what I wanted to play.

MakeProjects commented 6 years ago

My apologaize for my mistake @houtanb, I´ve fixed the last post. It is the first time that I write on github. I hope my problem help to someone to.

I need to switch betewen different videos, I tried different options with omxplayer-wrapper but I always got a black screen during the videos are switching. I need to switch between video1 and video2 without black screen and within delay.

I think that you solution is the best. Put the videos together and then jump to de the position.

Could you show me how to do this?

Thanks a lot.