1

I'm running a bash script that will play a video with mplayer depending on an input from an Arduino (on/off).

When the movie ends, I need to get a timestamp in a txt file. First question is whether there's a command in mplayer slave mode to tell me that, so I can output a timestamp easily.

If not, here's my strategy so far:

I'm running mplayer in slave mode with a fifo, where I echo "pause", whenever I want it to stop.

So, I've been doing this: echo "get_time_pos" to my fifo, which will tell mplayer to show in my Terminal the current position in the movie in seconds. When I say in my Terminal, it's in the same window where I'm running my script.

Now, I need to store this value in a variable to be able to compare with the total length and then output time.

I'm stuck at getting this output into a variable in my bash script.

Florin
  • 11
  • 3

1 Answers1

0

I recently put together a small bash library that may grow with time. At the moment, it has the functionality you're looking for. I'll explain how to get the info you seek and then point you to my library which simplifies the task.

To get the information you seek, you don't even need to call get_time_pos. You can simply dump the mplayer (not running in quiet mode) output to a file and search that for the last timestamp. The trick here is that the timestamps listed in the dump may not be intuitive to search because of some special characters that control how text is displayed. You have to replace some of these special characters with new lines so that you can easily search it. Then you have to grab the last two lines in case the last line is not a timestamp.

Using my bash library:
Now, if you would like to simplify this process, check out this little library I wrote. Follow the usage directions on my GitHub to incorporate it, and then when you play a media file, play it with the playMediaFile function. If you do this, you'll be able to call the getElapsedSeconds or getElapsedTimestamp function to retrieve the current playback position or the playback position after mplayer has stopped. Storing it to a variable from within bash would be as simple as:

pos=$(getElapsedSeconds)

or

pos=$(getElapsedTimestamp)

This library contains other functions as well. The isFinishedPlaying function may or may not also be of use to you.

b_laoshi
  • 443
  • 6
  • 12