[FFmpeg-user] Pad real-time input stream when there is no input data available at this moment

Fusl ffmpeg at lists.dedilink.eu
Sat Dec 7 13:33:09 CET 2013


Hey guys,

i am currently writing a live-streaming in node.js with ffmpeg and stuck
at some buffering issues.

- So what do i have?

The node.js-script, which manages the stdin source for the following
ffmpeg process (switch between live-stream and playlist-stream on the fly).

The ffmpeg-process, called encoder, which takes data from stdin and
writes them out in mp3 format to stdout.

 -ac 2
 -acodec pcm_u8
 -analyzeduration 5000
 -ar 48000
 -f u8
 -re
 -i pipe:0
 -ab 128k
 -ac 2
 -acodec libmp3lame
 -ar 44100
 -f mp3
 -flags2 local_header
 -strict -2
 pipe:1

- What is wrong with this bit of code?

As written above, the node.js script manages the stdin source for the
ffmpeg-process and therefor switches around live-streaming and
playlist-streaming (there is also an advertisement-streaming and a
silence-stream if none of these three streams are sending data).
Sometimes, the live-streaming source just freezes and the node.js-script
has to wait for a defined timeout to occur. When this timeout occurs,
the script disconnects the live-streaming source and connect the
playlist-streaming source on-the-fly. So far so good, but there is still
one problem: When the script is waiting for the timeout to occur (for
example 2 seconds), there is a gap between these streaming sources for
exact 2 seconds, which is also noticable on the output-stream of the
ffmpeg-process. Result -> The client needs to resync/rebuffer the stream
for another 2 seconds. This problem has been temporarily bounded with a
prebuffering of 25 seconds, done in the node.js-part which processes the
output of the ffmpeg process but only for about 13 timeouts and then the
client again needs to resync/rebuffer the stream.

- So what do i need to fix this issue?

I need some sort of example of a very complex (i think it is very
complex) ffmpeg-command, which is doing this:

When ffmpeg starts, start buffering a real-time anullsrc and pause the
buffer-processing for now.

When ffmpeg receives a chunk on stdin (over and over again), reset the
buffer to 0, pause the buffer-processing and reset the timer for the
timeout to 0.

When a timeout of a defined time (e.g. 2 seconds) occurs, resume the
buffer-processing of the anullsink-buffer so, that also prebuffered
chunks of anullsrc are being processed.


Is this somehow possible with ffmpeg or are these a bit too much
requirements for it?

PS: If someone wants to check out the code: http://github.com/Fusl/nodecast


Thank you for your attention!


Best regards

Kevin Holly - root at hallowe.lt - http://hallowe.lt/


More information about the ffmpeg-user mailing list