Raspberry Pi – stream to YouTube using ffmpeg

  linux, raspberry-pi
#! /bin/bash
#
VBR="3500k"                                    # Bitrate
FPS="35"                                       # FPS
QUAL="fast"                                  # ultrafast superfast veryfast faster fast medium slow slower veryslow

YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"  # URL for YouTube RTMP
SOURCE="http://192.168.0.52:8080/stream/video.mjpeg"              # Source UDP (this rpi ifconfig)


KEY="abcd-1234-????-????"                                     # your YouTube key
ffmpeg \
    -re -threads 4 \
    -i "$SOURCE"  \
    -f lavfi -i anullsrc \
    -acodec libmp3lame -ar 44100 -qscale 3 -b:a 712000 -bufsize 512k \
    -vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \
    -f flv "$YOUTUBE_URL/$KEY"

Also see: https://wiki.lupsha.com/raspberry-pi-raspivid-live-cam-scripts/