Search code examples
raspberry-picameravideo-streamingpiraspivid

Raspberry Pi libcamera-vid to Youtube


I'm setting up a nature cam using a Raspberry Pi 4 livestreaming to Youtube. I can live stream video to Youtube using:

raspivid -o - -t 0 -w 1280 -h 720 -fps 25 -b 4000000 -g 50 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f vs16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<mykey>

but this requires legacy support to be enabled - which means I can't remote to my pi using VNC. I can use Putty to run the raspivid command, but I then need to have another computer running Youtube in a browser to enable the live stream. I'd rather just have the Pi do this, but I can't open Chromium from the Putty command line. If I turn off legacy support, I can use VNC and run Chromium, but I can't run Raspivid. libcamera-vid is meant to replace Raspivid, but I have not found anything that tells me what settings to use.

libcamera-vid -o - -t 0 --width 854 --height 480 --brightness 0.1 --inline --autofocus --framerate 25 -g 50 | ffmpeg -f lavfi -i anullsrc -thread_queue_size 1024 -use_wallclock_as_timestamps 1 -i pipe:0 -c:v copy -b:v 2500k -f flv rtmp://a.rtmp.youtube.com/live2/mykey

gives errors, particularly around audio settings (my Pi isn't recording audio).

I'd be grateful if someone could give me a newbies guide to converting Raspivid commands to Libcamera-vid!

Thanks

Thanks


Solution

  • Yes, you have to define null audio like this -i anullsrc=channel_layout=stereo:sample_rate=44100

    So I have something similar to you:

    libcamera-vid --inline --nopreview -t 0 --width 640 --height 480 --framerate 15 --codec h264 -o - | ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -thread_queue_size 1024 -use_wallclock_as_timestamps 1 -i pipe:0 -c:v copy -c:a aac -preset fast -strict experimental -f flv rtmp://0.0.0.0:1935/live/1