8

I am using a Pi Zero W with the Pi camera (noir) to stream live to Youtube using ffmpeg. The command line I am using is:

raspivid -o - -t 0 -h 720 -w 1296 -fps 24 -b 6000000 | ./ffmpeg -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -thread_queue_size 512 -i - -vcodec copy -acodec aac -ab 128k -g 50 -preset ultrafast -crf 32 -strict experimental -f flv rtmp://173.194.183.168/live2/<MY_YOUTUBE_KEY>

When this starts running, I initially get a speed of ~1.5x/45 FPS. I assume that this reported speed is the rate at which ffmpeg is able to encode and send the output of raspivid. After this command has been running for a few minutes, the speed will (always) monotonically degrade until the FPS is less than the input (24), and the stream starts to lag. I have tried a number of changes to the command, including smaller video, lower frame-rate, lower quality, and even streaming to a local file instead of YouTube. The behaviour remains in all cases, and it seems as if ffmpeg itself is getting slower the longer it runs.

Does anyone have any idea what might be going on here, and how I can resolve this?

Matt
  • 181
  • 1
  • 4

2 Answers2

0

How much RAM do you have? I'm wondering if you are running out of memory room the longer you stream.

If this is the problem, do this:

sudo dd if=/dev/zero of=/swap1 bs=1M count=2048
sudo mkswap /swap1
sudo vim /etc/fstab

This will open up your fstab file. You may or may not have a swap file. If you see something like,

/swap0 swap swap

You already had a swap so replace that line with the following( if the line is absent add the following line to your fstab file)

/swap1 swap swap

Reboot your Pi.

g3holliday
  • 72
  • 1
  • 2
  • 9
0

You could try increasing the thread_queue_size to something like 4096 or even higher. I've seen it as high as 12000. I had a similar problem with my stream lagging and this seemed to fix it.