2

I am struggling with muxing a few UDP inputs (SPTS from file) in one UDP output (MPTS). When I use following command

ffmpeg -thread_queue_size 2048 -i "udp://233.0.0.1:4005?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4000?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4001?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4002?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4003?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4004?fifo_size=1000000&buffer_size=10000000" -map 0 -map 1 -map 2 -map 3 -map 4 -map 5 -program title=Program0:st=0:st=1 -program title=Program1:st=2:st=3 -program title=Program2:st=4:st=5 -program title=Program3:st=6:st=7 -program title=Program4:st=8:st=9 -program title=Program5:st=10:st=11 -c copy -metadata service_provider=FILE -f mpegts -muxrate 40000000 -flush_packets 0 "udp://239.2.2.2:2222?overrun_nonfatal=1&fifo_size=1000000&buffer_size=10000000&pkt_size=1316&ttl=1"

I can play (with VLC) the MPTS content many hours with no problems.

When I add a bitrate parameter to make UDP output stream as CBR

"udp://239.2.2.2:2222?overrun_nonfatal=1&fifo_size=1000000&buffer_size=10000000&pkt_size=1316&ttl=1&bitrate=40000000"

instead of

"udp://239.2.2.2:2222?overrun_nonfatal=1&fifo_size=1000000&buffer_size=10000000&pkt_size=1316&ttl=1"

a hear many audio cuts, and from VLC I see then:

main warning: timing screwed (drift: -89659 us): stopping resampling
main warning: playback too early (-89367): down-sampling
main warning: playback way too early (-126525): playing silence
main debug: inserting 6073 zeroes
main warning: playback too early (-47858): down-sampling
main warning: timing screwed (drift: -97495 us): stopping resampling
main warning: playback too early (-96807): down-sampling
main warning: playback way too early (-134672): playing silence
main debug: inserting 6464 zeroes

and after some random time (several minutes) ffmpeg stops working due to following error:

av_interleaved_write_frame(): Cannot allocate memory

How to make it work with CBR UDP bitrate?
I tired changing parameters of buffer_size and fifo_size but with no success.
I've increased OS UDP buffers to improve performance but same memory problem is visible

Przemo
  • 193
  • 2
  • 16

2 Answers2

0

I was having the exact same memory error and I could not figure out why. But I found a workaround that worked for me.

What I did is instead of using the output directly to udp stream, I first send it to a pipe. And then use ffmpeg to read from the pipe and send it to over udp multicast address.

Create the named pipe:

mkfifo pipename.ts

Remove the ffmpeg output from the ffmpeg command:

"udp://239.2.2.2:2222?overrun_nonfatal=1&fifo_size=1000000&buffer_size=10000000&pkt_size=1316&ttl=1&bitrate=40000000" 

and use the following output:

pipe:1 > pipename.ts

So the first command will look like this:

ffmpeg -thread_queue_size 2048 -i "udp://233.0.0.1:4005?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4000?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4001?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4002?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4003?fifo_size=1000000&buffer_size=10000000" -thread_queue_size 2048 -i "udp://233.0.0.1:4004?fifo_size=1000000&buffer_size=10000000" -map 0 -map 1 -map 2 -map 3 -map 4 -map 5 -program title=Program0:st=0:st=1 -program title=Program1:st=2:st=3 -program title=Program2:st=4:st=5 -program title=Program3:st=6:st=7 -program title=Program4:st=8:st=9 -program title=Program5:st=10:st=11 -c copy -metadata service_provider=FILE -f mpegts -muxrate 40000000 -flush_packets 0 pipe:1 > pipename.ts

Then run another ffmpeg process to read from the pipe and output to UDP:

ffmpeg -re -i pipename.ts -c copy -f mpegts "udp://239.2.2.2:2222?overrun_nonfatal=1&fifo_size=1000000&buffer_size=10000000&pkt_size=1316&ttl=1&bitrate=40000000"

I could not explain why doing this way works though.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

I had the same problem on Centos 6.7 (ffmpeg version N-90991-g0736f32). Accidentally I tried this on another server with Ubuntu 18.04.2 (kernel 4.15.0-128-generic) with ffmpeg version 3.4.8-0ubuntu0.2 (installed from apt-get). And it looks stable now.

Cristik
  • 30,989
  • 25
  • 91
  • 127