Matteo Giani
Matteo Giani

Reputation: 106

Mplayer and pipe streaming

I'd like to use mplayer to play a stream of files via a named pipe.

From here I read that MPlayer can read from stdin (not named pipes).

named pipes can still be used in a bash script this way:

mkfifo pipe
cat pipe | mplayer -cache 1024 -cache-min 10 -really-quiet - &
cat test.wav > pipe

the problem with this is that after mplayer receives an EOF, it exits and I cannot pass more than one file, while I'd like mplayer to keep playing files through the pipe. The problem is somehow similar to this, from which the following script, meant to keep the pipe opened, is inspired:

mkfifo pipe
cat pipe | mplayer -cache 1024 -cache-min 10 -really-quiet - &
exec 3>pipe
cat test1.wav >&3
cat test2.wav >&3
..
exec 3>&- # close the pipe

the pipe remains indeed open; however, now despite the cache of mplayer getting filled, I get no playback unless I close the pipe, in which case it plays the first file only. I tried to send, after a file, an EOF signal:

mkfifo pipe
cat pipe | mplayer -cache 1024 -cache-min 10 -really-quiet - &
exec 3>pipe
cat test1.wav >&3
echo >&3
..
exec 3>&- # close the pipe

but still no luck.

Any suggestions on how to use mplayer as a stream player from a named pipe?

Upvotes: 0

Views: 3278

Answers (1)

Riccardo Petraglia
Riccardo Petraglia

Reputation: 2003

Did you check this one? In your case you should encapsulate all the cat commands:

mkfifo pipe
cat pipe | mplayer -cache 1024 -cache-min 10 -really-quiet - &
exec 3>pipe
(cat test1.wav test2.wav ) >&3
3>&- # close the pipe

In this way, when the command meets the closing parenthesis also send an EOF...

Honestly, I am not sure this is the answer, but it was too long for a comment... :)

In case this will work, the main downside is the memory usage...

Upvotes: 0

Related Questions