I am trying to play a video with omxplayer and have it pause after 10 seconds. To load the video I am using a shell script that runs the command. I would also like the user to be able to resume the video so it can fade out (I am using a video of a still image).

What I have tried is omxplayer --no-osd -b Media/test.flv sleep 3 p

That runs the p after the video plays.

Thank you.

  • So, you basically want the video to pause after 10 seconds, but don't know how? – RPiAwesomeness Mar 28 '14 at 17:21
  • @RPiAwesomeness Yes. – ben545 Mar 28 '14 at 21:06
  • Okay, was kind of hard to understand what your actual question was. Just clarifying. So, you want the video to play and after 10 seconds, go off to this other application. Wouldn't backgrounding (or even killing for that matter) the OMXPlayer process work? – RPiAwesomeness Mar 28 '14 at 21:10
  • 1
    expect is build for this kind of things. Of the top of my head, something like expect -c "spawn omxplayer --no-osd -b Media/test.flv; sleep 3; send p; interact" – Gerben Mar 29 '14 at 12:50

OK. You're on the right track to start with. I believe we can pipe keyboard input into omxplayer from the command line and use that to control it. I'm just going to write it out, then explain what's happening

mkfifo t
cat t | omxplayer --no-osd -b Media/test.flv &
sleep 10s
echo p > t
rm t

First a special type of file called a FIFO, or first-in first-out file is created. Anything we write to the file comes out in the order it was put in when the file is read. The second command cats the output of this and pipes it into omxplayer. There's nothing in the file to start with though, so nothing happens. We wait 10 seconds. We then write "p" into the FIFO file with the echo command. Cat will then see this and pipe that to omxplayer, pausing the video. The last line just removes the FIFO file since we're done with it. If you're doing this lots though, you can just leave it there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.