iizukanao / picam

Audio/video recorder for Raspberry Pi with language agnostic API
GNU Lesser General Public License v2.1
489 stars 78 forks source link

alsadev error: cannot set channel count for microphone (Invalid argument) #201

Closed lt250r93 closed 1 year ago

lt250r93 commented 1 year ago

Hi, I am having an issue running Picam . I am using a Samson Go Mic and a Raspberry Pi Zero W running Bullseye. When setting the ALSA device to hw:1,0 it returns the following: "error: cannot set channel count for microphone (Invalid argument)". How do I resolve this issue? ~/picam $ sudo ./picam --alsadev hw:1,0 error: cannot set channel count for microphone (Invalid argument)

If I run picam without alsadev it will run and start capturing, but will disable audio. ~/picam $ sudo ./picam error: cannot open audio capture device 'hw:0,0': No such file or directory hint: specify correct ALSA device with '--alsadev ' warning: audio capturing is disabled

Also get a warning about mismatch: WARN RPI raspberrypi.cpp:1357 Mismatch between Unicam and CamHelper for embedded data usage!

I did confirm that my microphone is hw:1,0. arecord -l List of CAPTURE Hardware Devices card 1: Mic [Samson Go Mic], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0

iizukanao commented 1 year ago

Please try the following.

lt250r93 commented 1 year ago

thanks plughw:1,0 worked while having -c 2 set.

feacluster commented 10 months ago

I have the same mic, Samson Go Mic . I believe it is a 2-channel stereo condenser mic. Initially I got garbled audio, but changing to plughw:1,0 worked. However, I get audio/video out of sync by one second. I tried adding -c 1 and -c 2 , but both gave the same garbled audio. Is the "virtual ALSA device" the only solution? Or should I experiment with the sampling rate? I believe the mic is 44 khz?, but not sure.

feacluster commented 10 months ago

I tried the virtual ALSA device by creating a file called .asoundrc in the main home directory as follows:

squash@court1:~ $ more .asoundrc
pcm.blaster {
  type plug
  slave {
    pcm "hw:1,0"
    channels 2
  }
  route_policy sum
}

I then called picam with: ~/picam/picam --alsadev blaster ....

I did a reboot but unfortunately still the same delay in the audio of one to two seconds.

feacluster commented 10 months ago

I tried doing all the suggestion, but eventually what worked was using ffmpeg to fix it during the TS to MP4 conversion:

ffmpeg -i $file -itsoffset -1.1 -i $file -map 0:0 -map 1:1 -c:v copy -c:a copy -bsf:a aac_adtstoasc test.mp4 > /dev/null 2>&1

For me 1.1 seconds seems to produce perfectly synced audio/video.

lt250r93 commented 10 months ago

Good to see you got it working. Is there a lag in your video and audio or was it a delay in your audio only?

feacluster commented 10 months ago

Good to see you got it working. Is there a lag in your video and audio or was it a delay in your audio only?

Not sure I follow your question, but I believe the audio was delayed. I would see something happen in the video then hear it a second later.

lt250r93 commented 10 months ago

Good to see you got it working. Is there a lag in your video and audio or was it a delay in your audio only?

Not sure I follow your question, but I believe the audio was delayed. I would see something happen in the video then hear it a second later.

I should have clarified in my previous comment since its not related to your issue. With my setup there is a 5 to 8 second delay from when something moves or makes noise and it playing on VLC or equivalent player. I'm still working on minimizing the delay.

feacluster commented 5 months ago

While my -itsoffset workaround works when converting the video. I can't get it to work with livestreaming on youtube. Here is the command I am trying which does not generate any feed to youtube . It seems to hang on the mic input or something:

ffmpeg -i tcp://127.0.0.1:8181?listen -itsoffset -1.1 -i tcp://127.0.0.1:8181?listen -map 0:0 -map 1:1 -c:v copy -c:a aac -ar 44100 -ab 40000 -f flv rtmp://a.rtmp.youtube.com/live2/xxxxxxxx

feacluster commented 5 months ago

I figured out how to get the youtube streaming to work but with using libcamera-vid instead of picam. Here's the full command if anyone is interested:

nohup libcamera-vid -t 0 --width 1920 --height 1080 --bitrate 2000000 --framerate 30 --autofocus-mode default --codec libav --libav-format flv --libav-audio --audio-source alsa --audio-device hw:1,0 --audio-bitrate 192000 --av-sync 200000 -n -o rtmp://a.rtmp.youtube.com/live2/xxxxxxxxx> /tmp/error.out 2>&1 &