brianpickford
Posts: 7
Joined: Wed Jul 04, 2012 8:31 am

omxplayer loop script

Wed Jul 04, 2012 8:38 am

a hoi hoi,

I have set up Raspbian and omxplayer from source. This is working well and is doing a great job.

I want to be able to play a single video file in an endless loop on my stand at the farnbrough air show next week, but my lack of bash skills id defeating me. I hope some on can spot the error and help me out ...


#!/bin/sh

SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "runing" # sleep 1
else
omxplayer -o hdmi video.mp4 United\ Springs\ Master.mp4 &
sleep 180
fi
done

This script and a few variants of it either return "Have a nice day ;)" or play the video once through then cycle the same message

Grateful for any pointers

mark1
Posts: 1
Joined: Mon Jun 25, 2012 2:10 pm

Re: omxplayer loop script

Wed Jul 04, 2012 4:02 pm

Check the command line arguments you are passing to omxplayer. Your script will run fine with the appropriate arguments.

Nr90
Posts: 216
Joined: Sat Nov 26, 2011 12:39 pm

Re: omxplayer loop script

Wed Jul 04, 2012 4:44 pm

Found the error it's running :lol:

brianpickford
Posts: 7
Joined: Wed Jul 04, 2012 8:31 am

Re: omxplayer loop script

Wed Jul 04, 2012 5:07 pm

#!/bin/sh -x

SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "runing" # sleep 1
else
omxplayer -o hdmi United\ Springs\ Master.mp4

fi
done

The issue was: omxplayer -o hdmi video.mp4 United\ Springs\ Master.mp4 &

I tested the script with vlc on an ubuntu box, and I must have left this extraneous video4.mp4 from there

/me slaps forehead

Many thanks

I also set the colours so that the terminal output was not visible between cycles with the following lines at the bottom of /etc/profile

setterm -term linux -background white
setterm -term linux -clear
./video.sh

but this means that you cant see any text when you log in locally or remotely so I added a small reset script called reset.sh that I can run when needed

#!/bin/sh
#reset.sh
setterm -term linux -background black
setterm -term linux -clear

... perfect

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Sun Oct 14, 2012 10:16 pm

=============================================
#!/usr/bin/python
import sys
import subprocess

while (1):
<tab>print "Running..."
<tab>a = subprocess.call( [ "omxplayer", sys.argv[1] ] )
=============================================
Replace the <tab> by an actual tab character.
Name the script "omx-loop" or whatever.
Make it executable: chmod +x omx-loop
Use it as: omx-loop filename.mp4

thisdoug
Posts: 1
Joined: Sat Oct 27, 2012 2:53 am

Re: omxplayer loop script

Sat Oct 27, 2012 3:08 am

These scripts work really well, thank you.

Is there a way to loop video with omxplayer so there is no break between each loop? I have a piece of video that I would like to loop endlessly, and have the last frame immediately followed by the first frame, with no jump.

is that possible?

Thanks

Doug

skitchy
Posts: 5
Joined: Wed Nov 07, 2012 1:34 am

Re: omxplayer loop script

Wed Nov 07, 2012 1:42 am

Please help me.
I just added this script to the end of /etc/profile in order to play a sound file on an infinite loop when the pi starts.
Works great - too great in fact, as now I am completely locked out of doing anything else! The Pi is stuck in an infinite loop. I naively assumed that I would be able to break the loop with CTRL-Z or CTRL-C, but is doesn't work (the ^C and ^Z characters just pop up, but do nothing as there is no command prompt).
I am obviously a Linux noob, and understand this was probably a monumentally stupid thing to do. Is there any way out of this predicament?

skitchy
Posts: 5
Joined: Wed Nov 07, 2012 1:34 am

Re: omxplayer loop script

Wed Nov 07, 2012 1:47 am

I should add that I used Brianpickfords script, not the Python one.

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Wed Nov 07, 2012 9:16 am

skitchy wrote:I should add that I used Brianpickfords script, not the Python one.
I have seen the same gap with Python as well.

It is on the wish list as it seems:
https://github.com/huceke/omxplayer/issues/16

Just an idea:
Try to put your media file in "/run/shm" folder and see if it improves the loading speed at the end.
Remember to keep the media file somewhere else as well as it will not be there after a reboot or shutdown.

GeorgeIoak
Posts: 43
Joined: Thu Aug 30, 2012 1:50 am

Re: omxplayer loop script

Thu Nov 15, 2012 4:37 pm

use the hello_video program and edit it following this thread, http://www.raspberrypi.org/phpBB3/viewt ... 2&p=161169 I use that to loop the same video and it works perfectly without any gaps.

nfendall
Posts: 4
Joined: Sun Nov 11, 2012 10:48 pm

Re: omxplayer loop script

Fri Nov 16, 2012 12:02 pm

I've been trying to do the same thing but all I get is the Have a nice day message, even when I run the bash script by brianpickford, any ideas??

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Fri Nov 16, 2012 12:28 pm

nfendall wrote:I've been trying to do the same thing but all I get is the Have a nice day message, even when I run the bash script by brianpickford, any ideas??
Can you post your commands?

nfendall
Posts: 4
Joined: Sun Nov 11, 2012 10:48 pm

Re: omxplayer loop script

Fri Nov 16, 2012 12:41 pm

#!/bin/sh

SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "runing" # sleep 1
else
omxplayer -o hdmi home/pi/test/test.mp4 &

fi
done

the file is saved as a .sh and I am running this from terminal using command

bash video.sh

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Fri Nov 16, 2012 1:22 pm

nfendall wrote:#!/bin/sh

SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "runing" # sleep 1
else
omxplayer -o hdmi home/pi/test/test.mp4 &

fi
done

the file is saved as a .sh and I am running this from terminal using command

bash video.sh
Try "/home/pi/test/test.mp4" with the leading "/".

nfendall
Posts: 4
Joined: Sun Nov 11, 2012 10:48 pm

Re: omxplayer loop script

Fri Nov 16, 2012 3:24 pm

massive step forward! I have looping video!!
Thanks for your help!

rottydean
Posts: 3
Joined: Tue Feb 05, 2013 12:42 pm

Re: omxplayer loop script

Tue Feb 05, 2013 12:45 pm

I would like to use this little script but it keeps coming back with errors:

line10: syntax error near unexpected token `done'
line 10: `done'

cant get my head around it!

i can run this line on its own omxplayer -o hdmi /home/pi/1.mp4 &

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Tue Feb 05, 2013 1:15 pm

rottydean wrote:I would like to use this little script but it keeps coming back with errors:

line10: syntax error near unexpected token `done'
line 10: `done'

cant get my head around it!

i can run this line on its own omxplayer -o hdmi /home/pi/1.mp4 &
Check for the "do" statement in the beginning.

Copy-paste problem?

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Tue Feb 05, 2013 1:22 pm

===========================================
#!/bin/bash
SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "Running" # sleep 1
else
$SERVICE -o hdmi "$1" &
fi
done
===========================================
chmod +x omx-loop.sh
./omx-loop /home/1.mp4

rottydean
Posts: 3
Joined: Tue Feb 05, 2013 12:42 pm

Re: omxplayer loop script

Wed Feb 06, 2013 4:22 pm

retyped it all

still get this

/home/pi/omx-loop.sh: line 10: syntax error near unexpected token `done'
/home/pi/omx-loop.sh: line 10: `done'

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Wed Feb 06, 2013 4:57 pm

Try the python script.
Search this page for "#!/usr/bin/python".

rottydean
Posts: 3
Joined: Tue Feb 05, 2013 12:42 pm

Re: omxplayer loop script

Wed Feb 06, 2013 5:48 pm

found the fault. It was my text editor :@ thanks for quick responce guys

arti0504
Posts: 24
Joined: Wed Jan 30, 2013 8:40 am

Re: omxplayer loop script

Mon Feb 11, 2013 9:47 am

Hi

I made file with this code:

===========================================
#!/bin/bash
SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "Running" # sleep 1
else
$SERVICE -o hdmi "$1" &
fi
done
===========================================
chmod +x omx-loop.sh
./omx-loop /home/1.mp4

and I see in Terminal only text:
Running
Running
Running

How can I fix it?

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Mon Feb 11, 2013 10:08 am

Which terminal?

Screen or SSH session?

Try to run:
omxplayer -o hdmi /home/1.mp4

and paste back the messages here.

arti0504
Posts: 24
Joined: Wed Jan 30, 2013 8:40 am

Re: omxplayer loop script

Mon Feb 11, 2013 12:46 pm

When I write in command line:

omxplayer -o hdmi /home/1.mp4

open movie good. When I want use loop script, I have only:
Running
Running
Running
Running

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: omxplayer loop script

Mon Feb 11, 2013 1:07 pm

arti0504 wrote:When I write in command line:

omxplayer -o hdmi /home/1.mp4

open movie good. When I want use loop script, I have only:
Running
Running
Running
Running
Do you pass the file name to the script?
Otherwise, use the python script (search above).

Return to “Graphics, sound and multimedia”