PyAV
PyAV copied to clipboard
PyAV cannot find ALSA container on Debian 11
Overview
When attempting to use PyAV and an ASLA input device on Debian 11, PyAV claims there is no input container named alsa despite my ffmpeg installation being able to capture from the ALSA device without any issues.
Expected behavior
>>> import av
>>> container = av.open('mic1',format='alsa')
(container opens successfully)
Actual behavior
>>> import av
>>> container = av.open('mic1',format='alsa')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "av/container/core.pyx", line 355, in av.container.core.open
File "av/container/core.pyx", line 132, in av.container.core.Container.__cinit__
File "av/format.pyx", line 90, in av.format.ContainerFormat.__cinit__
ValueError: no container format 'alsa'
Investigation
My FFMPEG installation appears to handle the ALSA device just fine, so I'm not sure why PyAV doesn't recognize ALSA as a valid container.
Below is the console log for a successful FFPMEG recording of the audio from the mic1 device:
$ ffmpeg -f alsa -i 'mic1' output.wav
ffmpeg version 4.3.3-0+deb11u1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'mic1':
Duration: N/A, start: 1648350240.490388, bitrate: 1536 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 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 'output.wav':
Metadata:
ISFT : Lavf58.45.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Metadata:
encoder : Lavc58.91.100 pcm_s16le
size= 372kB time=00:00:02.02 bitrate=1509.2kbits/s speed=0.996x
video:0kB audio:372kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.020458%
Exiting normally, received signal 2.
Reproduction
- Attempt to run
av.open('<device',format='alsa')
Versions
- OS: Debian 11 x64
- PyAV runtime:
PyAV v8.0.3
git origin: [email protected]:PyAV-Org/PyAV
git commit: v8.0.3
library configuration: --disable-doc --disable-static --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-shared --enable-version3 --enable-zlib --prefix=/tmp/vendor
library license: GPL version 3 or later
libavcodec 58. 91.100
libavdevice 58. 10.100
libavfilter 7. 85.100
libavformat 58. 45.100
libavutil 56. 51.100
libswresample 3. 7.100
libswscale 5. 7.100
- PyAV build: N/A (installed via PIP)
- FFmpeg: see above console output
I also attempted a no-binaries build using pip install av --no-binary av, and while the build and install succeeded the result is the same. So I don't believe it's an issue with the ffmpeg setup on my PC.
I also attempted a no-binaries build using
pip install av --no-binary av, and while the build and install succeeded the result is the same. So I don't believe it's an issue with the ffmpeg setup on my PC.
I do believe this is an issue with our binary wheels. I'm on Debian/bookworm, and with the binary wheel of av, "alsa" is not present in av.available_formats. When I build the package from source, it is. I'm suprised that building av yourself doesn't change the issue.
Pulled latest source from Github and installed. Seems to have fixed the issue!
Here's another (possibly basic) python question - how would I go about copying these self-built packages over to an existing venv where I was doing my original development? Or alternatively - how fast can you get a release version onto PyPi so I can install via pip?
I found the answer to question #1 above - just copy the av folder into the root directory of the python venv. All seems to be working.
Thanks for the quick response!
Rebuilding the FFmpeg libraries for all our supported platforms (see https://github.com/PyAV-Org/pyav-ffmpeg) takes about 12 hours. After that I can start a test build of PyAV, and then cut a release which automatically goes to PyPI. So stay tuned it should be happening in a day or so.
Unfortunately things seem to be more complicated than expected. The ALSA libraries apparently use plugins, and obviously the plugins are not bundled with the wheels.. nor at the expected location:
>>> import av
>>> av.__version__
'9.1.0'
>>> container = av.open('default', format='alsa')
ALSA lib conf.c:3558:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib64/alsa-lib/libasound_module_conf_pulse.so: libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default
Hi, I ran into the problem as the OP on Release Linux Mint 20.2 Uma 64-bit with Kernel Linux 5.4.0-110-generic x86_64. Following the readme instructions I tried both, installing from github and via pip without binaries. Both returned the same error:
sudo pip3 install av --no-binary av
Collecting av
Downloading av-9.2.0.tar.gz (2.4 MB)
|████████████████████████████████| 2.4 MB 2.1 MB/s
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Building wheels for collected packages: av
Building wheel for av (PEP 517) ... error
-------------------------------------------8<--------------------------------------------------------------------------
...
-------------------------------------------8<--------------------------------------------------------------------------
src/av/stream.c: In function ‘__pyx_f_2av_6stream_wrap_stream’:
src/av/stream.c:2305:27: error: ‘struct AVStream’ has no member named ‘codec’
2305 | switch (__pyx_v_c_stream->codec->codec_type) {
| ^~
src/av/stream.c: In function ‘__pyx_f_2av_6stream_6Stream__init’:
src/av/stream.c:2923:29: error: ‘struct AVStream’ has no member named ‘codec’
2923 | __pyx_t_1 = __pyx_v_stream->codec;
| ^~
src/av/stream.c:3043:15: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
3043 | __pyx_t_6 = __pyx_v_self->_codec_context->codec;
| ^
src/av/stream.c: In function ‘__pyx_f_2av_6stream_6Stream__finalize_for_output’:
src/av/stream.c:3828:130: error: ‘struct AVStream’ has no member named ‘codec’
3828 | __pyx_t_7 = __pyx_f_2av_5error_err_check(avcodec_parameters_from_context(__pyx_v_self->_stream->codecpar, __pyx_v_self->_stream->codec), 0, NULL); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 150, __pyx_L1_error)
Any advice on how to proceed?
Best Ck
Any updates to this issue? Setting up a new system with my project and ran into the same issue as the first comment in this thread, with the latest pyav installed via pip.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This thing helped for me:
sudo apt-get install libavdevice-dev
pip3 uninstall av
pip3 install av --no-binary av
I really don't know why it ships without libavdevice-dev pkg