Author Topic: mplayer gapless with fifo  (Read 9729 times)

bk201

  • Newbie
  • *
  • Posts: 5
    • View Profile
mplayer gapless with fifo
« on: April 16, 2010, 17:47:27 »
In regards to getting gapless playback with mplayer...

If a named pipe is used to stream the audio, linux does enough buffering to achieve gapless playback. Just set up aplay to read from a pipe and use mplayer to send raw pcm to the pipe.

Code: [Select]
$ mkfifo audiofifo
$ aplay -t raw -c 2 -f S16_LE -r 44100 audiofifo &
$ mplayer -ao pcm:nowaveheader:file=audiofifo <audio files>

Ideas taken from http://www.volkerschatz.com/hardware/itxplayer.html (scroll down to software/audio player)

bk201

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: mplayer gapless with fifo
« Reply #1 on: April 16, 2010, 17:53:16 »
Actually, I just tested this by putting mplayer options

Code: [Select]
-ao pcm:nowaveheader:file=/home/user/gmbfifo
into gmusicbrowser and then creating a pipe

Code: [Select]
mkfifo /home/user/gmbfifo
and then an aplay instance

Code: [Select]
aplay -t raw -c 2 -f S16_LE -r 44100 /home/user/gmbfifo
And it works beautifully when playing any audio from the library!  8)

Quentin Sculo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1082
    • View Profile
Re: mplayer gapless with fifo
« Reply #2 on: April 16, 2010, 21:29:53 »
thanks, good to know.
I don't know if I'll add an option to do that automatically, but at least I'll mention this trick in the FAQ

ochosi

  • Full Member
  • ***
  • Posts: 187
    • View Profile
Re:mplayer gapless with fifo
« Reply #3 on: April 21, 2010, 18:25:59 »
just tried this cause in general i've been missing this feature a bit in mplayer (gstreamer just uses more cpu).
in general it seems to work, but somehow it screws up my progress-scale widget and the pos-widget. the overall runtime of a song sometimes gets exceeded by the counter (especially when skipping towards the end of a track to try the gapless feature ;) ).

also: would i have to create the pipe and the aplay instance everytime i start gmb? (not that this is a problem, i could simply make a script for that.) i don't know much about pipes in linux, do they have to be closed again?

Quentin Sculo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1082
    • View Profile
Re: mplayer gapless with fifo
« Reply #4 on: April 25, 2010, 19:33:24 »
It can cause delays between what you hear and the displayed position, other problems are probably coming from mplayer (try to running it from the command line).

The fifo doesn't need to be recreated
I'm not sure on what condition aplay quits, you could run
Code: [Select]
while true ; do aplay -t raw -c 2 -f S16_LE -r 44100 /home/user/gmbfifo ; doneto make sure it is re-launched when it quits.

fernadoPoo

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: mplayer gapless with fifo
« Reply #5 on: March 08, 2016, 12:13:23 »
I have found that at times the size of the fifo is not large enough. aplay eats all the data in the fifo before mplayer can provide more. I think when this happens aplay stops. The size of the fifo buffer can be increased. This hero has written a C program to do that: https://gist.github.com/cyfdecyf/1ee981611050202d670c