Streaming audio and video to youtube

I have the following script to stream video to youtube. It uses null audio input. I can record audio with the microphone. How do I combine it to stream both audio and video


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 <youtube rtmp>

you need to inentify your recording device:

arecord -l

Example output for a mono mic:

yaml

card 2: dmiccard [dmic-codec], device 0: fe203000.i2s-dmic-codec-0 dmic-hifi-0
Subdevices: 1/1

That gives you hw:2,0 (card 2, device 0).

then your command should looke something like this (haven’t tried)


libcamera-vid \
  --inline --nopreview -t 0 \
  --width 640 --height 480 --framerate 15 --codec h264 -o - | \
ffmpeg \
  -f alsa -thread_queue_size 1024 \
  -ar 48000 -ac 1 -i plughw:2,0 \          # 48 kHz mono from the I²S ADC
  -thread_queue_size 1024 -use_wallclock_as_timestamps 1 -i pipe:0 \
  -map 1:v:0 -map 0:a:0 \                  # video from libcamera, audio from I²S
  -c:v copy \
  -c:a aac -b:a 128k -sample_fmt s16 \     # 48 kHz AAC; YouTube loves it
  -f flv "rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY"