[FFmpeg-user] No Audio from ALSA device on Raspberry Pi
Mark L
mvlambiase at gmail.com
Mon Jan 31 04:53:54 EET 2022
I built a camera out of a Raspberry Pi and added a microphone.
https://lambiaselightindustries.com/raspberry-pi-outdoor-security-camera-build-overview/
This command works great with the camera and streams to YT at 30 fps:
ffmpeg -hide_banner -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i
/dev/zero -f video4linux2 -input_format h264 -video_size 1280x720
-framerate 30 -i /dev/video0 -vcodec copy -acodec aac -ab 128k -g 50
-strict experimental -f flv rtmp://a.rtmp.youtube.com/live/xxxxxxxxxxxxxx
But notice the audio is nulled out.
I found two resources that seem to indicate how to get ffmepg to grab an
alsa device: https://ffmpeg.org/ffmpeg-devices.html#alsa
https://trac.ffmpeg.org/wiki/Capture/ALSA
Listing my capture devices shows this:
pi at cam-08:~/scripts $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: sndrpii2scard [snd_rpi_i2s_card], device 0: simple-card_codec_link
snd-soc-dummy-dai-0 [simple-card_codec_link snd-soc-dummy-dai-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
pi at cam-08:~/scripts $ arecord -L
null
Discard all samples (playback) or generate zero samples (capture)
dmic_hw
dmic_sv
default
sysdefault:CARD=sndrpii2scard
snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
Default Audio Device
dmix:CARD=sndrpii2scard,DEV=0
snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
Direct sample mixing device
dsnoop:CARD=sndrpii2scard,DEV=0
snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
Direct sample snooping device
hw:CARD=sndrpii2scard,DEV=0
snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
Direct hardware device without any conversions
plughw:CARD=sndrpii2scard,DEV=0
snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
Hardware device with all software conversions
Using 'arecord' I am able to record audio. I have a .asoundrc file in my
home dir and reference the device by the name in there ("-D dmic_sv").
But, when I try to record with ffmpeg, nothing.
If I use the device "hw:0" it fails, but if I used the device
"sysdefault:CARD=sndrpii2scard" I do not get an error, but it does not
record output.
Here is the output of my ffmpeg commands. And assistance or hints
appreciated.
pi at cam-08:~/scripts $ ffmpeg -hide_banner -f alsa -channels 1 -sample_rate
44100 -i hw:0 -t 30 out.wav
[alsa @ 0x1997210] cannot open audio device hw:0 (No such file or directory)
hw:0: Input/output error
pi at cam-08:~/scripts $ ffmpeg -hide_banner -f alsa -channels 1 -sample_rate
44100 -i sysdefault:CARD=sndrpii2scard -t 30 out.wav
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, alsa, from 'sysdefault:CARD=sndrpii2scard':
Duration: N/A, start: 1643579124.318478, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to 'out.wav':
Metadata:
ISFT : Lavf58.20.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono,
s16, 705 kb/s
Metadata:
encoder : Lavc58.35.100 pcm_s16le
size= 2584kB time=00:00:30.00 bitrate= 705.6kbits/s speed= 1x
video:0kB audio:2584kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.002948%
Again, I get a file, but when I play it it seems to have no audio.
Thanks in advance.
More information about the ffmpeg-user
mailing list