DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

OMXPLAYER VIDEO STATUS

Wed Jan 15, 2020 4:27 pm

Hi , Everyone

I want a python script / shell script that returns a value while exiting but not any value the value should be the video status of omxplayer ( True / False )

sorry if this is a reapeted question ... i don't think so isearched everywhere.

Thanks.
Thank God

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

Re: OMXPLAYER VIDEO STATUS

Wed Jan 15, 2020 6:30 pm

DEXTER_STARK wrote:
Wed Jan 15, 2020 4:27 pm
Hi , Everyone

I want a python script / shell script that returns a value while exiting but not any value the value should be the video status of omxplayer ( True / False )

sorry if this is a reapeted question ... i don't think so isearched everywhere.

Thanks.
So you want a script that returnsTRUEif OMX player is running, false if it is not?

Use the `ps ax` command to list processes perhaps, then grep on omxplayer in some way?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

User avatar
rpiMike
Posts: 1076
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: OMXPLAYER VIDEO STATUS

Wed Jan 15, 2020 10:17 pm

You could use the Python omxplayer wrapper.

https://python-omxplayer-wrapper.readth ... en/latest/

Code: Select all

from omxplayer.player import OMXPlayer
import time,signal,sys

def signalHandler(sig,frame):
    print('Ctrl+C pressed')
    player.quit()
    sys.exit(0)
    
def playerPause():
    print('pause')

def playerExit(code):
    print('exit',code)

signal.signal(signal.SIGINT,signalHandler)

filename = '/opt/vc/src/hello_pi/hello_video/test.h264'

player = OMXPlayer(filename)
player.pauseEvent += lambda _: playerPause()    
player.exitEvent += lambda _, exit_code: playerExit(exit_code)

time.sleep(3) # wait for omxplayer

player.set_position(player.duration()-5) # skip close to end

while True:
    time.sleep(1)

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 9:54 am

Hello Thanks jamesh for replying to my topic

Actually that wasn't my question .... my bad i didn't explain well. :roll:

my question was i want a script that return true if there is a video signal ( OMXPLAYER can be running but showing nothinhg in this case i want the return value to be false ) and false if not .

Thanks. :D :D :D :D
Last edited by DEXTER_STARK on Thu Jan 16, 2020 10:05 am, edited 1 time in total.
Thank God

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

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 10:04 am

Hmm, that's a bit more difficult. ALthough still a bit confused. If OMXplayer is running it will always be outputting something. Do you mean outputting a black screen?

And of course, the HDMI will always be outputting something (desktop, console etc) even when OMXPlayer is not running.

So specifically, what use case are you trying to detect?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 10:12 am

jamesh wrote:
Thu Jan 16, 2020 10:04 am
Hmm, that's a bit more difficult. ALthough still a bit confused. If OMXplayer is running it will always be outputting something. Do you mean outputting a black screen?

And of course, the HDMI will always be outputting something (desktop, console etc) even when OMXPlayer is not running.

So specifically, what use case are you trying to detect?

Hi jamesh

i play a video from an rtmp so the code be like :

Code: Select all

omxplayer rtmp www.example/live:1356.com 
so it is not always showing a video for example when the connexion goes very bad the video stops when it does that i want to have a false return value otherwise when the video is playing and all things are right i want to get a true return value .

hope i explaind well this time , Thanks a lot for being here and helping me.

;) ;)
Last edited by DEXTER_STARK on Thu Jan 16, 2020 10:38 am, edited 1 time in total.
Thank God

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 10:32 am

rpiMike wrote:
Wed Jan 15, 2020 10:17 pm
You could use the Python omxplayer wrapper.

https://python-omxplayer-wrapper.readth ... en/latest/

Code: Select all

from omxplayer.player import OMXPlayer
import time,signal,sys

def signalHandler(sig,frame):
    print('Ctrl+C pressed')
    player.quit()
    sys.exit(0)
    
def playerPause():
    print('pause')

def playerExit(code):
    print('exit',code)

signal.signal(signal.SIGINT,signalHandler)

filename = '/opt/vc/src/hello_pi/hello_video/test.h264'

player = OMXPlayer(filename)
player.pauseEvent += lambda _: playerPause()    
player.exitEvent += lambda _, exit_code: playerExit(exit_code)

time.sleep(3) # wait for omxplayer

player.set_position(player.duration()-5) # skip close to end

while True:
    time.sleep(1)
Hi rpiMike, hope you're doing well .
So, i tried this solution but it didn't work neither lidbus would be installed nor the omxplayer-wrapper.
however, the code seems to me isn't returning anything ,

Thanks. ;)
Thank God

User avatar
rpiMike
Posts: 1076
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 10:41 am

I don't think this code will do what you are after. However the code should work, it runs fine for me. Are you using the latest fully updated Raspbian Buster with Desktop?

Should just need:

Code: Select all

pip3 install omxplayer-wrapper

Code: Select all

python3 test.py

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 10:50 am

rpiMike wrote:
Thu Jan 16, 2020 10:41 am
I don't think this code will do what you are after. However the code should work, it runs fine for me. Are you using the latest fully updated Raspbian Buster with Desktop?

Should just need:

Code: Select all

pip3 install omxplayer-wrapper
I totaly agree with you and yes i'v got all update.

if you have any idea that can help with what i'm looking for , i'll be thankfull if you post it ;) ;)

by the way the two commands you just gave worked :D and also the code did ;) unless that not what i'm looking for.
Thank God

User avatar
rpiMike
Posts: 1076
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 10:54 am

So what does 'pip3 install omxplayer-wrapper' output?

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 11:04 am

rpiMike wrote:
Thu Jan 16, 2020 10:54 am
So what does 'pip3 install omxplayer-wrapper' output?
it worked actually, it had to add the '3 :roll:
Thank God

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

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 11:43 am

Just deleted the other thread on exact same subject, please keep it to one thread.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

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

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 11:49 am

Note that they were not quite duplicates. This thread (the one I am posting to now) is Python-centric. The other one was language agnostic (It specifically said "any language"). I gave a shell-based solution in the other thread.

Of course, who knows what OP really wants or needs...
GitD's list of things that are not quite ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 11:55 am

GlowInTheDark wrote:
Thu Jan 16, 2020 11:49 am
Note that they were not quite duplicates. This thread (the one I am posting to now) is Python-centric. The other one was language agnostic (It specifically said "any language"). I gave a shell-based solution in the other thread.

Of course, who knows what OP really wants or needs...
Agree 100% with you ;)


Any solutions please i'm stuck i tried to do the command :

Code: Select all

 omxplayer --video_fifo
it is quite interesting but it display the information i want in the terminal , if there is any way to grep it from the terminal and store it in a variable i'll be gratefull to have it.

Thanks
Thank God

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

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 12:56 pm

Here's the post I was composing on the other thread (When I went to post it, got err msg that the thread no longer exists).
this url goes to a page that displays 404 not found
You may have to do a little research and/or wait for someone else to post wherever is the right URL this week. I just did a quick search on the forum for "dbuscontrol" and that's the URL I found.
and the command shows a summary in the terminal which i don't want . I just want a value (True / False) stored in a variable.
How do you know that if you weren't able to download it?

Anyway, as I noted in my previous post, you may need to redirect the output to /dev/null.

Like this:

Code: Select all

dbuscontrol.sh status > /dev/null 2>&1 || echo "It failed!"
GitD's list of things that are not quite ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3

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

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 1:04 pm

Code: Select all

omxplayer --video_fifo
it is quite interesting but it display the information i want in the terminal , if there is any way to grep it from the terminal and store it in a variable i'll be grateful to have it.
I could not get that command to do anything useful - not that I tried very hard. It seems to want an arg, so I tried both 2 and 7 (the only numbers I know), but all it did was generate several screenfuls of usage information.

Anyway, the general method is to do (in shell script):

Code: Select all

whatevercommand 2>&1 | grep whatever > /dev/null && echo "It worked!"
That should get on the path to wherever it is you want to go.

The "> /dev/null" is to silence the output of the grep command. Note that there are options to grep (e.g., -q) to do something similar, but do note that grep is a little squirrelly in terms of what exactly those options do. Read the man page, then sit back and take a deep breath...
GitD's list of things that are not quite ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 1:25 pm

GlowInTheDark wrote:
I could not get that command to do anything useful - not that I tried very hard. It seems to want an arg, so I tried both 2 and 7 (the only numbers I know), but all it did
Thanks for trying. :D

Code: Select all

whatevercommand 2>&1 | grep whatever > /dev/null && echo "It worked!"
That should get on the path to wherever it is you want to go.

The "> /dev/null" is to silence the output of the grep command. Note that there are options to grep (e.g., -q) to do something similar, but do note that grep is a little squirrelly in terms of what exactly those options do. Read the man page, then sit back and take a deep breath...
so if you did

Code: Select all

grep whatever > /code/scan.sh
it will store the output in scan.sh file ? and what i didn't understand is what does 2>&1 do !

i invite you to read this
DEXTER_STARK wrote:
jamesh wrote:
Thu Jan 16, 2020 10:04 am
Hmm, that's a bit more difficult. ALthough still a bit confused. If OMXplayer is running it will always be outputting something. Do you mean outputting a black screen?

And of course, the HDMI will always be outputting something (desktop, console etc) even when OMXPlayer is not running.

So specifically, what use case are you trying to detect?

Hi jamesh

i play a video from an rtmp so the code be like :

Code: Select all

omxplayer rtmp www.example/live:1356.com 
so it is not always showing a video for example when the connexion goes very bad the video stops when it does that i want to have a false return value otherwise when the video is playing and all things are right i want to get a true return value .

hope i explaind well this time , Thanks a lot for being here and helping me.

;) ;)
Thanks a lot one more time ;)
Thank God

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

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 3:39 pm

Can you monitor the connection somehow, and if the data rate drops down you know that something is awry?

You would need to google for how to monitor a network interface for current speed.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 3:46 pm

jamesh wrote: Can you monitor the connection somehow, and if the data rate drops down you know that something is awry?

You would need to google for how to monitor a network interface for current speed.
you mean like a cacti thing ? i don't need that because i need these result for another thing ( display on a mini screen live or error ) so i need them in a script . monitoring connection won't give me anything i think .

unless i didn't understand what do you mean.
Thank God

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

Re: OMXPLAYER VIDEO STATUS

Thu Jan 16, 2020 5:21 pm

DEXTER_STARK wrote:
Thu Jan 16, 2020 3:46 pm
jamesh wrote: Can you monitor the connection somehow, and if the data rate drops down you know that something is awry?

You would need to google for how to monitor a network interface for current speed.
you mean like a cacti thing ? i don't need that because i need these result for another thing ( display on a mini screen live or error ) so i need them in a script . monitoring connection won't give me anything i think .

unless i didn't understand what do you mean.
I may have misunderstood specifically what you are trying to achieve, I thought you wanted to know when a OMXplayer stream was stalled so it had stopped playing. One way would be to monitor the stream, if the data rate goes down, then its stalled.



And please don't keep creating new threads on the same topic. I'll just keep deleting them.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

Return to “Python”