soyersoyer / fmp4streamer

Fmp4streamer streams your V4L2 camera directly to any browser and media player as MP4 (H264).
Apache License 2.0
78 stars 7 forks source link

Add audio from USB microphone #1

Open lestrozi opened 2 years ago

lestrozi commented 2 years ago

Great project! Any chance of adding audio from the USB microphone when creating the mp4 frames? If you have some pointers on how to do that I can do some coding and submit a PR.

soyersoyer commented 2 years ago

Thanks! I am not very experienced in audio, but adding audio from usb seems to a bit complicated. Reading from the microphone maybe easy. We can use alsa with python3-pyalsa. But we have to encode the sound into AAC(-LC) because of the mp4 format. But encoding is a bit hard, because there aren't any decent aac encoder library there. The ffmpeg aac comes inside libavcodec and it is very big. The libfdk_aac is not in the raspbian repository, so the users have to build it, it's not user friendly. Maybe we can use the libvo-aacenc0, but it's not a very good quality codec and there are no python bindings. So we have to write bindings too. I am working to replace the raspivid with v4l2. After I can dig deeper into this.

lestrozi commented 2 years ago

TBH I think ffmpeg is the safest bet. Apparently some people can combine video and audio piping raspivid to ffmpeg -i - -f alsa -ac 1 -i hw:0,0 -map 0:0 -map 1:0 -vcodec copy -acodec aac. I recently ordered a USB microphone and will play a bit with it when it arrives :)

spookyfirehorse commented 2 years ago

Hi !

great work

yess please add audio

for me is opus the best choise. it is in the ffmpeg and has better performance than libfdk

-c:a libopus -application lowdelay -b:a 32k -movflags +faststart -async 1

and sorry but is it possible to be come an option for rtsp streaming ?

can you tell me how i can do that for my own to add audio and rtsp in your files