No description, website, or topics provided.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

page title tags date
Raspberry Pi Camera Stream to YouTube Live
ffmpeg raspberry pi youtube stream


Forward video and audio from Raspberry PI to Youtube live stream


Install ffmpeg binaries. Possibly from my ffmpeg-raspi project


  • Raspberry Pi 3B+
  • Pi Camera Module v2 NOIR
  • USB microphone


Enable bcm2835-v4l2 and have it loaded on startup

As root:

modprobe bcm2835-v4l2
echo bcm2835-v4l2 >> /etc/modules

raspivid preview

Test camera working correctly on raspivid:

Note: The camera preview renders directly to the display. It will NOT show up on VNC

raspivid -t 0


Customize as preferred. --overlay=1 enables display of the video on the monitor connected to the PI. Useful for debugging, but can be set to 0 most of the time.

-p set the target FPS

pixelformat=4 sets the PI to output frames in H264 mode directly

Other params are self explanatory.

v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=4
v4l2-ctl --overlay=1
v4l2-ctl -p 30
v4l2-ctl --set-ctrl=video_bitrate=1000000

Capture to file

Test recording to file with ffmpeg. Copy the file off the device and play it to test it works as expected

ffmpeg -y -ac 1 -f alsa -i hw:1 -f h264 -framerate 30 -i /dev/video0 -vcodec copy -acodec aac -ab 128k out.mp4


With default encoding

ffmpeg -ac 1 -f alsa -i hw:1 -f h264 -framerate 30 -i /dev/video0 -vcodec copy -acodec aac -ab 128k -f flv rtmp://$ID

With ffmpeg encoding

ffmpeg -ac 1 -f alsa -i hw:1 -f video4linux2 -framerate 30 -i /dev/video0 -fflags nobuffer -vcodec h264_omx -g 5 -b:v 1000k -tune zerolatency -acodec aac -ab 128k -f flv rtmp://$ID

Replace $ID with an ID generated from a new Youtube Live Event created here:

Throw that command in an upstart, systemd, or other process manager script and you are good to go.


It's possible to skip bcm2835-v4l2 and instead pipe raspivid into ffmpeg. The problem is that audio and video will be very out of sync. For reference this is the command:

raspivid -t 0 -o - -b 1000000 -md 4 -w 1280 -h 720 -fps 30 -awb auto -ex nightpreview -ev -2 -drc med -pts | \
  ffmpeg -thread_queue_size 128 -y -f h264 -r 30 -i - -ac 1 -f alsa -i hw:1  -c:v copy -c:a aac out.mp4