User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

How to play 2 videos simultaneously? - Pi 4 ModelB

Fri Dec 06, 2019 11:45 am

Hello, everyone!

I've been tasked with creating a simple solution to make 2 different videos play SIMULTANEOUSLY on 2 different screens/projectors.

The Raspberry Pi we have at our disposal is the Raspberry Pi 4, Model B. It has 2 HDMI outs, so that's part of the solution already.
I did a lot of digging to no fruitful result.
All I could find is a lot of people claiming this is EASY and no one actually explaining how to.

For the little I learned on the past few days of research, OMXPLAYER should be capable of something like that.
The line

Code: Select all

omxplayer --display=2 Video1.mp4
successfully plays Video1(.mp4) on the first HDMI, while

Code: Select all

omxplayer --display=7 Video2.mp4
successfully plays Video2(.mp4) on the second HDMI!
Separating both commands with ";"

Code: Select all

omxplayer --display=2 Video1.mp4 ; omxplayer --display=7 Video2.mp4
results in playing Video1 on screen 1 and once it's DONE, video 2 on screen 2.
One post claims that the error there is to use ";" instead of "&", since "&" would result in omxplayer playing video1 on screen 1 on background, while running the second video on the second screen, but whenever I do that

Code: Select all

omxplayer --display=2 Video1.mp4 & omxplayer --display=7 Video2.mp4
I get nothing on screen 1 and only video2 on screen 2.

Does anyone know what am I doing wrong?
I found many posts on how to play multiple videos with MULTIPLE Raspberries, but the intention was to use only one (since it seems to be possible...)


Any the help is much appreciated!
ʕ •ᴥ•ʔ

User avatar
procount
Posts: 2411
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Fri Dec 06, 2019 12:14 pm

try

Code: Select all

omxplayer --display=2 Video1.mp4 &; omxplayer --display=7 Video2.mp4
or put them on separate lines:

Code: Select all

omxplayer --display=2 Video1.mp4 &
omxplayer --display=7 Video2.mp4 &
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

GlowInTheDark
Posts: 1238
Joined: Sat Nov 09, 2019 12:14 pm

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Fri Dec 06, 2019 1:38 pm

First of all, let me say that this is a topic of specific interest to me. I had been about to post a similar question when I saw this one.

Now, I wouldn't worry about the shell syntax. The form:

$ cmd1 & cmd2

is perfectly well defined in all sh-derived shells. It means to run cmd1 and not wait for it to finish, and to then run cmd2 and wait (as usual). Just as if you had hit the Enter key after the &.

Anyway, the problem here is that omxplayer generates tty output and background jobs aren't allowed to write to the terminal in modern shells. So, what happens is that the first job gets stopped by the shell (you see a message "Stopped: tty output") and is not allowed to run.

Worse, it seems to be writing directly to the terminal (via /dev/tty, I think), since the usual redirection tricks (> /dev/null 2>&1) did not solve the problem (in my testing).

I *was* able to get it to work (sort of, see below) via:

$ xterm -e omxplayer Video1.mp4 & sleep 5;omxplayer --display=7 Video2.mp4

I'm not sure if the sleep is necessary or not, but I put it in to be safe.

The key is to run one of the omxplayers in a separate xterm, so that it gets its own tty to write to.

Now, the problem: Although the --display thing changes the *video* to appear on the second HDMI screen, the *audio* still goes to the main HDMI screen. This is true whenever you play a video on the second HDMI; in the above case, where you are running two omxplayers at once, you end up with mixed audio (both tracks playing simultaneously) on the main screen. I assume this is not what you want.

"man omxplayer" shows that there is a "-o" option which tells where to send the audio output. However, there is no indication about how to handle multiple HDMIs. If anyone knows how to do this, please advise.

And here's another thing, while we are on the general subject of running omxplayer on the Pi 4. I no longer get an onscreen display (for example, if I pause the video). All previous versions of omxplayer, on all previous versions of Raspbian and all previous versions of the Pi, did display the OSD. There is an option in "man omxplayer" to disable the OSD, but no way (AFAICT) to *enable* it.

Again, if anyone knows how to fix this, please advise.

Finally, where do the magic numbers 2 & 7 come from? Yes, I know the quick answer is "I googled it and Google told me to do that", but I'm actually curious where they really come from.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10265
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Fri Dec 06, 2019 2:01 pm

GlowInTheDark wrote:
Fri Dec 06, 2019 1:38 pm
Now, the problem: Although the --display thing changes the *video* to appear on the second HDMI screen, the *audio* still goes to the main HDMI screen. This is true whenever you play a video on the second HDMI; in the above case, where you are running two omxplayers at once, you end up with mixed audio (both tracks playing simultaneously) on the main screen. I assume this is not what you want.

"man omxplayer" shows that there is a "-o" option which tells where to send the audio output. However, there is no indication about how to handle multiple HDMIs. If anyone knows how to do this, please advise.
"-o hdmi0" and "-o hdmi1" should do the trick.
GlowInTheDark wrote:And here's another thing, while we are on the general subject of running omxplayer on the Pi 4. I no longer get an onscreen display (for example, if I pause the video). All previous versions of omxplayer, on all previous versions of Raspbian and all previous versions of the Pi, did display the OSD. There is an option in "man omxplayer" to disable the OSD, but no way (AFAICT) to *enable* it.
The OSD used the firmware OpenVG implementation, which used the GLES driver. With the switch to Mesa and ARM based GL driver that is no longer an option.
Until the OSD code is rewritten to use some alternate renderer, OSD is automatically disabled on Pi4.
GlowInTheDark wrote:Finally, where do the magic numbers 2 & 7 come from? Yes, I know the quick answer is "I googled it and Google told me to do that", but I'm actually curious where they really come from.
DispmanX display numbers.
https://github.com/raspberrypi/userland ... ypes.h#L58
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

GlowInTheDark
Posts: 1238
Joined: Sat Nov 09, 2019 12:14 pm

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Sat Dec 07, 2019 12:16 am

@6by9, thanks for answering all my questions. Too bad about the OSD...

However, the "-o hdmi1" does not work. Get err msg:

Bad argument for -o: Output device must be `local', `hdmi', `both' or `alsa'

I am running omxplayer dated August 1, 2019, under latest Rasbian Buster. Note that I tested this before and after doing an update/upgrade - just to make sure I had the latest version. omxplayer was not among the packages that were updated in the update/upgrade (note that there were a *lot* of updates, but omxplayer was not among them).

Maybe there is a "development version" floating around that does support "-o hdmi1" ?
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10265
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Mon Dec 09, 2019 6:03 pm

Whilst the firmware had been updated to accept "hdmi0" and "hdmi1", omxplayer hadn't.
https://github.com/popcornmix/omxplayer/pull/754 should resolve that.

Please remember that there hasn't been a significant increase in the video decode hardware with Pi4, so don't expect dual 1080p60 decode to keep up.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
dividuum
Posts: 229
Joined: Sun Jun 16, 2013 1:18 pm
Location: Germany
Contact: Website

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Mon Dec 09, 2019 6:16 pm

6by9 wrote:
Mon Dec 09, 2019 6:03 pm
Whilst the firmware had been updated to accept "hdmi0" and "hdmi1", omxplayer hadn't.
https://github.com/popcornmix/omxplayer/pull/754 should resolve that.
I guess there isn't a target that sends to both? Does it have to be splitted in userland? Can `hdmi0` be used pre-Pi4 and behaves identical to the existing `hdmi`?
info-beamer hosted - A user and programmer friendly digital signage platform for the Pi: https://info-beamer.com/hosted

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10265
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Mon Dec 09, 2019 6:27 pm

dividuum wrote:
Mon Dec 09, 2019 6:16 pm
6by9 wrote:
Mon Dec 09, 2019 6:03 pm
Whilst the firmware had been updated to accept "hdmi0" and "hdmi1", omxplayer hadn't.
https://github.com/popcornmix/omxplayer/pull/754 should resolve that.
I guess there isn't a target that sends to both? Does it have to be splitted in userland? Can `hdmi0` be used pre-Pi4 and behaves identical to the existing `hdmi`?
"both" will send to the analogue output and "hdmi".
"hdmi" and "hdmi0" and synonymous - they map to the same enum eventually.
Sending to "hdmi1" pre-Pi4 would hopefully not crash, but I'm not chasing it down now. (I didn't make the change, and the person who did isn't around at the moment).
No, there isn't a magic way to route to both "hdmi0" and "hdmi1" simultaneously. As with the current handling of "both", you need an audio_splitter component routing to two audio_render components. I haven't got the enthusiasm to make that sort of change to omxplayer.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

GlowInTheDark
Posts: 1238
Joined: Sat Nov 09, 2019 12:14 pm

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Mon Dec 09, 2019 8:10 pm

6by9 wrote:
Mon Dec 09, 2019 6:03 pm
Whilst the firmware had been updated to accept "hdmi0" and "hdmi1", omxplayer hadn't.
https://github.com/popcornmix/omxplayer/pull/754 should resolve that.

Please remember that there hasn't been a significant increase in the video decode hardware with Pi4, so don't expect dual 1080p60 decode to keep up.
I don't know anything about githubs and pulls and stuff like that.

So, I guess I just wait until an updated omxplayer shows up in the update/upgrade mix.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Wed Dec 11, 2019 9:51 am

Hey! Thanks for the suggestions!
Here's what I got:
procount wrote:
Fri Dec 06, 2019 12:14 pm

Code: Select all

omxplayer --display=2 Video1.mp4 &; omxplayer --display=7 Video2.mp4
This didn't work... :c
I get

Code: Select all

bash: syntax error near unexpected token ';'
procount wrote:
Fri Dec 06, 2019 12:14 pm

Code: Select all

omxplayer --display=2 Video1.mp4 &
omxplayer --display=7 Video2.mp4 &
This also failed... :c

I don't know if I'm doing this right (COMPLETELY new to all this) so I'm breaking a line by adding "\" to the end of the first line (which results in ">"on the beggining of the next line)

Code: Select all

omxplayer --display=2 Video1.mp4 &\
>omxplayer --display=7 Video2.mp4 &
to which I get:

* Video2.mp4 plays on screen2 (--display=7) *

Code: Select all

[1] 1333
Video codec omg-264 width 1440 height 1080 profile 77 fps 25.000000
Audio codec arc channels 2 samplerate 48000 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
V:PortSettingsChanged: 1440x1080@25.00 interlace:0 deinterlace:0 anaglyph:0 par:1.33 display:7 layer:0 alpha:255 aspectMode:0
have a nice day ;)

[1]+ Stopped					omxplayer --display=2 1.mp4

So basically all the info on Vid2 and "STOPPED" for vid1...

I also tried
GlowInTheDark wrote:
Fri Dec 06, 2019 1:38 pm

Code: Select all

$ xterm -e omxplayer Video1.mp4 & sleep 5;omxplayer --display=7 Video2.mp4
Also didn't do the trick... :c

To this, I get:

Code: Select all

[2]  1381
bash: $: command not found
(followed by the whole list of the --help command)
As to the audio, it's not a big issue for me at the moment.
The set up we will be having is a couple of projectors and only one set of speakers, so ALL the audio needs to come from the same place.
For that reason, we made Video1.mp4 having both audios and Video2.mp4 having no audio at all.

We managed to make this work before, using a macbook pro and Quicktime, but this time we will need to leave it running and not be there, so the macbook will need to come back, while the exhibition goes on, hence the raspberry!

In any case, we are starting to consider exploring the omxplayer-sync.
I googled little about that since it needs two raspberries to run (in a master/slave system) and we're trying to avoid having to purchase the second device...
That is cheaper than most of the alternatives, however, so if it proves to be necessary, we can work that out, I guess!

Thank you so much for all the replies and the awesome discussion!
I'm always amazed by how much I can learn from people that have the good will to reply posts clearly as you guys have done!!!

Thank you all indeed!
Will continue to try stuff and will post it here if I manage to sort it out!!!

ʕ •ᴥ•ʔ

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 27778
Joined: Sat Jul 30, 2011 7:41 pm

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Wed Dec 11, 2019 11:25 am

bearpixels wrote:
Wed Dec 11, 2019 9:51 am
Hey! Thanks for the suggestions!
Here's what I got:
procount wrote:
Fri Dec 06, 2019 12:14 pm

Code: Select all

omxplayer --display=2 Video1.mp4 &; omxplayer --display=7 Video2.mp4
This didn't work... :c
I get

Code: Select all

bash: syntax error near unexpected token ';'
procount wrote:
Fri Dec 06, 2019 12:14 pm

Code: Select all

omxplayer --display=2 Video1.mp4 &
omxplayer --display=7 Video2.mp4 &
This also failed... :c

I don't know if I'm doing this right (COMPLETELY new to all this) so I'm breaking a line by adding "\" to the end of the first line (which results in ">"on the beggining of the next line)

Code: Select all

omxplayer --display=2 Video1.mp4 &\
>omxplayer --display=7 Video2.mp4 &
to which I get:

* Video2.mp4 plays on screen2 (--display=7) *

Code: Select all

[1] 1333
Video codec omg-264 width 1440 height 1080 profile 77 fps 25.000000
Audio codec arc channels 2 samplerate 48000 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
V:PortSettingsChanged: 1440x1080@25.00 interlace:0 deinterlace:0 anaglyph:0 par:1.33 display:7 layer:0 alpha:255 aspectMode:0
have a nice day ;)

[1]+ Stopped					omxplayer --display=2 1.mp4

So basically all the info on Vid2 and "STOPPED" for vid1...

I also tried
GlowInTheDark wrote:
Fri Dec 06, 2019 1:38 pm

Code: Select all

$ xterm -e omxplayer Video1.mp4 & sleep 5;omxplayer --display=7 Video2.mp4
Also didn't do the trick... :c

To this, I get:

Code: Select all

[2]  1381
bash: $: command not found
(followed by the whole list of the --help command)
As to the audio, it's not a big issue for me at the moment.
The set up we will be having is a couple of projectors and only one set of speakers, so ALL the audio needs to come from the same place.
For that reason, we made Video1.mp4 having both audios and Video2.mp4 having no audio at all.

We managed to make this work before, using a macbook pro and Quicktime, but this time we will need to leave it running and not be there, so the macbook will need to come back, while the exhibition goes on, hence the raspberry!

In any case, we are starting to consider exploring the omxplayer-sync.
I googled little about that since it needs two raspberries to run (in a master/slave system) and we're trying to avoid having to purchase the second device...
That is cheaper than most of the alternatives, however, so if it proves to be necessary, we can work that out, I guess!

Thank you so much for all the replies and the awesome discussion!
I'm always amazed by how much I can learn from people that have the good will to reply posts clearly as you guys have done!!!

Thank you all indeed!
Will continue to try stuff and will post it here if I manage to sort it out!!!

ʕ •ᴥ•ʔ
You don't need a Pi4 to playback H264, you could use a $5 Pi0.....you already spent more than in time asking your questions on here, so if the real problem is money that might be a good route.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10265
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Wed Dec 11, 2019 12:26 pm

Code: Select all

omxplayer --no-keys --display=2 foo.mov & omxplayer --display=7 bar.mkv
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 3:01 am

jamesh wrote:
Wed Dec 11, 2019 11:25 am
You don't need a Pi4 to playback H264, you could use a $5 Pi0.....you already spent more than in time asking your questions on here, so if the real problem is money that might be a good route.
Yeah, Pi0 would be a cheaper option, but it doesn't have 2 HDMIs, right? (again, completely new to this)
Also, there's a place we really trust to buy our equipment close by, and they only carry pi3 and pi4, with a small difference in price, so that's why we decided to invest a tiny bit extra on the 4 and potentially avoid having to buy 2...
In any case, I'm sure we'll be re-using the Raspberries a lot, so not a waste to have gotten the 4, I hope!
But thanks for the reply! :3

As to
6by9 wrote:
Wed Dec 11, 2019 12:26 pm

Code: Select all

omxplayer --no-keys --display=2 foo.mov & omxplayer --display=7 bar.mkv
Tried that too. Not much luck.
To this, I get:

Code: Select all

[1] 978
Video codec omx-264 width 1440 height 1080 profile 77 fps 25.000000
Video codec omx-264 width 1440 height 1080 profile 77 fps 25.000000
Have a nice day ;)
Have a nice day ;)
[1]+ Exit 1					omxplayer --no-keys --display=2 video2.mp4
As far as I understand, the "--no-keys" thing is to make omxplayer non-responsive to any keys pressed, so that I would not be able to command that instance of omxplayer, and be completely free to control the second one, right?

So I tried a few other things, to see if that would work:

1:
Tried letting the --no-keys playing while typing in the command for the second screen

Code: Select all

omxplayer --no-keys --display=2 video1.mp4 
Video1 plays on screen 1 while I am free to type whatever I want on the Terminal. So I quickly add:

Code: Select all

omxplayer --display=7 video2.mp4
This results in video1 playing on screen1 all the way and ONCE IT'S FINISHED, video2 on screen2

So I decided to add "&" at the end of step1:

Code: Select all

omxplayer --no-keys --display=2 video1.mp4 &
Video1 starts on screen1, I add:

Code: Select all

omxplayer --display=7 video2.mp4
and all I get is an added

Code: Select all

have a nice day ;)
straight away.

I tried all of the above with "--no-keys" on the second step too, same results. The only difference is that I can't stop the video before it finishes on its own. If I use "\" to try to activate both commands at the same time but in different lines, I get the same results as doing it all in one single line.
:c

Starting to feel like we're gonna need that second Raspberry anyways.
I keep having people replying that "Oh, Raspberry 4 can DEFINITELY do that!" and no one seems to reply HOW, so I don't know if there's a myth about it or if real people actually get to make it work :P

GowInTheDark mentioned being able to get it to work
GlowInTheDark wrote:
Fri Dec 06, 2019 1:38 pm
I *was* able to get it to work (sort of, see below) via:

$ xterm -e omxplayer Video1.mp4 & sleep 5;omxplayer --display=7 Video2.mp4
but I can't reproduce that or figure out what am I doing wrong...
the "$" is already in the command line in terminal, so I assumed I shouldn't type it, since typing it results in

Code: Select all

bash: $: command not found
So I tried to skip it and go straight for

Code: Select all

 xterm -e omxplayer Video1.mp4 & sleep 5;omxplayer --display=7 Video2.mp4
which results in

Code: Select all

 bash: xterm: command not found 
and then video2 playing on screen2...

I'm sure I'm doing something wrong there, just can't figure out what :c

Anyways, thanks once again for all the help, everyone!
ʕ •ᴥ•ʔ

GlowInTheDark
Posts: 1238
Joined: Sat Nov 09, 2019 12:14 pm

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 4:59 am

# apt-get install xterm

should be all you need.

Note: The convention is that if you show a command with a $ like this:

$ ls foo

it means to run that as the default user (pi). If you show it with a # like this:

# fdisk -l

it means to run it as root (in the context of Raspbian on the Pi), you become root by doing:

$ sudo bash

By the way, it might be possible to do this without installing "xterm" by using "lxterminal" instead. But there are advantages to having xterm installed - there are some things it can do that lxterminal either doesn't do and that lxterminal does them in a weird way. So, I always end up with xterm installed on my systems.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 5:36 am

GlowInTheDark wrote:
Thu Dec 12, 2019 4:59 am
# apt-get install xterm

should be all you need.

Note: The convention is that if you show a command with a $ like this:

$ ls foo

it means to run that as the default user (pi). If you show it with a # like this:

# fdisk -l

it means to run it as root (in the context of Raspbian on the Pi), you become root by doing:

$ sudo bash

By the way, it might be possible to do this without installing "xterm" by using "lxterminal" instead. But there are advantages to having xterm installed - there are some things it can do that lxterminal either doesn't do and that lxterminal does them in a weird way. So, I always end up with xterm installed on my systems.

Oh, I see! Thanks for the explanation!

Ok, so first things first:
I became root

Code: Select all

sudo bash
and installed the xterm

Code: Select all

apt-get install xterm
then I used

Code: Select all

exit
and became user again.
right?

Then I tried:

Code: Select all

xterm -e omxplayer video1.mp4 & sleep 5;omxplayer --display=7 video2.mp4
and I get

Code: Select all

[1] 1689
xterm: cannot load font "--Misc-Fixed-medium-R-*-*-13-120-75-75-C-120-ISO10646-1"
xterm: cannot load font "--misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1"
have a nice day ;)
and video1 playing on screen1. No video2, even after it's done.
A new terminal window seems to pop up while Video1 is playing (so I guess that's the XTERM one) and the "have a nice day ; )" message comes up 5 seconds after video1 starts, so I'm guessing that's the "sleep 5" part of the command making it wait for 5 seconds then trying video2 and finishing immediately?


But still no success :c
I can't seem to figure out what am I doing wrong.

Thanks once again!!!
ʕ •ᴥ•ʔ

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10265
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 7:49 am

I hadn't provided the command line lightly, I'd tested it beforehand and it works. There is obviously something different on your system.

My next guess is that you haven't given the gpu sufficient memory to be able to do 2 simultaneous decodes.
Have you increased gpu_mem in config.txt at all? The default is 64MB which is only going to be sufficient for one 1080p decode. Try increasing it, or use lower resolution clips as a test. Or try sshing into the box with two sessions and starting a video from each. If the second one you errors it is down to a lack of resources somewhere.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 8:09 am

6by9 wrote:
Thu Dec 12, 2019 7:49 am
I hadn't provided the command line lightly, I'd tested it beforehand and it works. There is obviously something different on your system.
Oh, I'm sure it's something on my side, don't worry, about it!
I'm VERY new to all this, so I don't really know WHAT I'm doing wrong, but I'm sure I'm doing SOMETHING wrong!
My next guess is that you haven't given the gpu sufficient memory to be able to do 2 simultaneous decodes.
Have you increased gpu_mem in config.txt at all?
That is PROBABLY IT! Haha
I haven't, no. And I actually have no clue on how to do that, so I'll look into that right now and test if that works!

[qute]
Try increasing it, or use lower resolution clips as a test.
[/quote]
Or try sshing into the box with two sessions and starting a video from each. If the second one you errors it is down to a lack of resources somewhere.
Have no idea how to, but can look into that too!

I'll try the memory first and get back with results in a minute!!!

Thank you IMMENSELY, seriously! :3
ʕ •ᴥ-ʔ
ʕ •ᴥ•ʔ

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 8:48 am

6by9 wrote:
Thu Dec 12, 2019 7:49 am
My next guess is that you haven't given the gpu sufficient memory to be able to do 2 simultaneous decodes.
Have you increased gpu_mem in config.txt at all?
OOOOH YOU LOVELY GORGEOUS AMAZING BEAST :D
That did it and I could not be happier!
Haha


Turns out there was not enough memory for it to run both at the same time and it would probably crash one in the process, trying to do both...
You did give me the right line but also the way to fix the mistakes I made on that! yeah!!!

Awesome! Thank you so much to everyone that was involved!!!

For the future, in case someone is having the same problem as I was, here's how:
On Raspberry Pi's main menu, I chose PREFERENCES > Raspberry Pi Configuration
under the PERFORMANCE tab, changed the GPU MEMORY: to a larger number (512 for now)

Then the line provided before did it:
6by9 wrote:
Wed Dec 11, 2019 12:26 pm

Code: Select all

omxplayer --no-keys --display=2 foo.mov & omxplayer --display=7 bar.mkv

:D




Now next step is make it loop and do it whenever it boots, so all that is needed to be done is plug the power in...
I'll probably get it done on my own, but I'll come back for help if I need to!

Once again, thank you to everyone involved!
ʕ •ᴥ•ʔ

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 9:15 am

bearpixels wrote:
Thu Dec 12, 2019 8:48 am
Now next step is make it loop
Ok, that was easy. The --loop command works:

Code: Select all

omxplayer --no-keys --loop video1.mp4 & omxplayer --display=7 --loop video2.mp4
Done!


Now for the tricky part!
bearpixels wrote:
Thu Dec 12, 2019 8:48 am
...and do it whenever it boots, so all that is needed to be done is plug the power in...
That was less tricky than I thought!
Here's how I did it (step by step):

First I moved the two video files to the Desktop. Just in case. I could be neater and keep them hidden but that would require a little bit more coding and I think it's good to have the files easy to find, in case we need to update them during the exhibition or something.

Secondly I opened the TERMINAL and moved into the Desktop, because there is where I want the executable to be:

Code: Select all

cd Desktop
Then I created a file, via terminal, on the Desktop, named Play2 (because it plays 2 videos) .sh (because it's gonna be a shell file) by using the commands:

Code: Select all

sudo nano Play2.sh
That lead me into the file editing for the Play2.sh, that was created in my desktop.
There I added the commands I wanted to have running after double-clicking the .sh (first line is a must for all shell files, apparently)

Code: Select all

#!/bin/bash

omxplayer --no-keys --loop --display=2 video1.mp4 & omxplayer --loop --display=7 video2.mp4
Closed it with Ctrl+X and hit Y(YES) to confirm I wanted to save this.
Pressed Enter on the next prompt (what name to save the file as, and it already had a pre-determined Play2.sh).

And then I used EXIT to quit Terminal.

Files are on my Desktop, Play2.sh is too and it all works as planned! :D Double-click it and it asked me if I want to EXECUTE or EXECUTE IN TERMINAL, but EXECUTING only is already enough and it plays both files at the same time, in sync, one in each monitor! HOORAY


I can't thank you guys enough, this was AWESOME and you've made it work!
I hope this post comes to help more people in the future and I wrote it all down here because I know I will need to revisit this in the future if I ever need to do this again! haha


Thanks once again, to all! Keep making this community the awesome place it is!!!
ʕ •ᴥ•ʔ

User avatar
rpdom
Posts: 17980
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Thu Dec 12, 2019 9:46 am

omxplayer doesn't require the desktop at all, so you could boot to command line which will be faster.

Then look at a way to autostart the omxplayer instances. One method would be to put them in your crontab with the @reboot option.
Unreadable squiggle

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Tue Dec 17, 2019 2:44 am

Hey everyone!
Me again!


So thanks to all of you I managed to get it working!
We had a simple 30-sec video to test with (Black screen, numbers 1-30) and it worked just fine!
Then we decided to leave it playing, in loop, for about 8hrs (which will be the case in the coming exhibition) and everything was ok.

Now we finally have the actual videos that will be showing and things are not that simple anymore...

So the two videos are exactly 70 minutes long. Video1 has audio and video2 does not.
When we play them both, it starts to show that they are out of sync about 10 minutes in. It becomes real clear by then, but it's really hard to tell, since there is not a lot that is synchronized throughout the video, but I believe it's gradually delaying/speeding up one of the two videos. I tried playing Video2 and a CopyofVideo2, just to see if it happened too and it is synced perfectly way after the mark in which it becomes clear, if it's playing 1 and 2 instead.
They are still different files and named differently, so they should be treated as two videos, rather than the same file (so it kinda should be processing two videos fully even though they happen to look the same, no?).

I then tested Video1 and Video1(same file), to see if the audio presence had anything to do with it and again synced perfectly well.
Video1 and CopyOfvideo1, also synced.

The GPU MEMORY is as high as I managed to keep it (anything more than the current 648 and the Pi won't boot).

We then proceeded to export the videos in a smaller size (lower quality a bit) to test if the size of fies had anything to do with it (they were about 3GB each).
Now the two new files are about 2.5GB in size. Same problem.

Is there any way to force it to sync? Like include something on the code that constantly compares the time of each file or something like that? Or should we really move on to using more than one Raspberry PI?

Thanks in advance, once again!
ʕ •ᴥ•ʔ

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10265
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Tue Dec 17, 2019 10:02 am

If you want to play two video clips exactly in sync then you need a single application playing the two streams (and the audio). There is no guaranteed way to have two applications play in sync.

The container (mkv, mp4, avi, etc) includes timestamps for each frame (whether video, audio, subtitle, or other) for when it needs to be presented to the viewer. If you have two independent clocks for those then they can drift.

You also have a question of which clock to take as reference. For a clip with audio, under OpenMax that is normally taken as the reference and video will be synchronised to the audio clock. For a clip without audio, a system clock is taken as reference.
You may find that this is the reason for your drift. Add a silent audio track to your second file to force it to use the audio clock, and video playback may be closely enough synchronised. (Make sure it's the same sample rate and depth as the audio on the other track).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
bearpixels
Posts: 9
Joined: Fri Dec 06, 2019 11:26 am

Re: How to play 2 videos simultaneously? - Pi 4 ModelB

Tue Dec 17, 2019 12:51 pm

6by9 wrote:
Tue Dec 17, 2019 10:02 am
If you want to play two video clips exactly in sync then you need a single application playing the two streams (and the audio). There is no guaranteed way to have two applications play in sync.

The container (mkv, mp4, avi, etc) includes timestamps for each frame (whether video, audio, subtitle, or other) for when it needs to be presented to the viewer. If you have two independent clocks for those then they can drift.

You also have a question of which clock to take as reference. For a clip with audio, under OpenMax that is normally taken as the reference and video will be synchronised to the audio clock. For a clip without audio, a system clock is taken as reference.
You may find that this is the reason for your drift. Add a silent audio track to your second file to force it to use the audio clock, and video playback may be closely enough synchronised. (Make sure it's the same sample rate and depth as the audio on the other track).

Aw yeah! Gotta love a well explained post.
Not only it solves the problem but also learned how things work and what the reason was!

The audio was INDEED the reason why!
We were exporting smaller versions to see if it would make any difference, during the afternoon, and BY MISTAKE exported video1 with no audio track (we were exporting them so many times...) and then the images were in perfect sync!
We did add a silent audio to video2 and it all works now! We're exporting the high quality videos now and will test them tomorrow.

Once again, thank you so much for the great help!
ʕ •ᴥ•ʔ

Return to “Graphics, sound and multimedia”