I have experimented with a number of different ways of streaming both audio and video from the raspberry pi. The UV4L web server has great webRTC support, and the bi-directional audio/video conferencing is amazing.
I can get a video stream in mjpeg and H264 from the same server.
However, I have not found the ability to stream audio + video from the raspberry pi in a non-webrtc format such as rtmp, and I also do not see how to record audio + video to a file programatically. Has anyone else figured this out? I suspect aconv or ffmpeg in conjunction with the video4linux2 /dev/video0 uv4l device could accomplish both streaming or writing to file, but I have not arrived at the correct command string.
Edit: This command seems to get the job done in terms of recording audio and video to a file. I did notice ALSA buffering issues that caused the audio to crap out, but moving the thread_queue_size progressively higher finally achieved acceptable audio. This command can also be used to stream rtmp by piping to some sort of rtmp server. Is there a better way to do this using pre-existing UV4L functionality?
avconv -thread_queue_size 2000 -f alsa -ac 1 -i hw:1,0 -f video4linux2 -s 320x240 -r 25 -thread_queue_size 2000 -i /dev/video0 -pix_fmt yuv420p -acodec libmp3lame -ar 44100 -r 25 -f mp4 example.mp4
Edit2: This is my second iteration of the command, which records a 10 second clip, syncs audio and video, and uses native h264 copy of video stream. Seems to perform well on the RPI.
avconv -t 10 -thread_queue_size 1024 -f alsa -ac 1 -i hw:1,0 -f video4linux2 -input_format h264 -video_size 1280x720 -r 30 -thread_queue_size 1024 -itsoffset 0.5 -i /dev/video0 -c:v copy -acodec aac -strict experimental -t 10 -y -pix_fmt yuv420p out.mp4