ffmpegstreampcmmjpegffplay

How to Combine two Live Streams(mjpeg + pcm) for ffmpeg or ffplay playback?


What's the correct command to combine two live streams (mjpeg + pcm) for playback? Currently, I have to playback them separately via ffplay. Is it possible to combine them as one for playback?

//video stream mjpeg
ffplay "udp://127.0.0.1:3001"

//audio stream raw pcm
ffplay -f s16le -ac 1 -ar 11025 "udp://127.0.0.1:3002"

I found some example commands suggested by others, but not sure how to implement for my above use case. https://superuser.com/questions/1410764/how-to-play-two-remote-streams-simultaneously

ffmpeg -headers X -i .. -headers Y -i .. -c copy -f nut - | ffplay -f nut -i -

Edit 2022/09/07:

Thanks for @kesh suggestion, below script works for first ~1 second with video and sound.

ffmpeg -i "udp://127.0.0.1:3001" \
-f s16le -ac 1 -ar 11025 -i "udp://127.0.0.1:3002" \
-c copy -f nut - | ffplay -f nut -i -

However, sound was muted after first error occured.

udp://127.0.0.1:3001: Input/output error

Updates: Above issue has been solved, with below commands:

ffmpeg -i "udp://127.0.0.1:3001?overrun_nonfatal=1&fifo_size=100000" \
-f s16le -ac 1 -ar 11025 -i "udp://127.0.0.1:3002?overrun_nonfatal=1&fifo_size=100000" \
-c copy -f nut - | ffplay -f nut -i -

However, if the mjpeg stream is paused or skipped few frames, the audio will stop too. It's not necessary to sync them, and how to keep the audio stream playing as long as it receives data?

Q1: the default video fps is 25, can I set it to 30 or 60?

Q2: pcm data stream is consistence, but mjpeg is not consistence. audio stream will stop once mjpeg is paused/resumed. What's the best solution?


Solution

  • just replace the input options as you have them with ffplay (after prepending -i to each filename):

    ffmpeg -i "udp://127.0.0.1:3001" \
           -f s16le -ac 1 -ar 11025 -i "udp://127.0.0.1:3002" \
           -c copy -f nut - | ffplay -f nut -i -