PyAV does not build with ffmpeg 5.x
Overview
av/stream.c uses __pyx_v_c_stream->codec->codec_type, but it is deprecated ~4 years ago and will be removed in next ffmpeg version (libavformat>58).
In https://trac.ffmpeg.org/wiki/Bump59
... libavformat - AVFormatContext.open_cb replaced by io_open/io_close - AVStream.codec removed; stream information is now exported through AVStream.codecpar; for decoding/encoding the users should allocate a separate codec context - HTTP and RTSP protocol's 'user-agent' option renamed to 'user_agent' - ...
Expected behavior
pip install av --no-binary av works with the latest FFmpeg version
Actual behavior
Build failed due to the above compile error
Build report:
...
src/av/stream.c: In function ‘__pyx_f_2av_6stream_wrap_stream’:
src/av/stream.c:2257:27: error: ‘struct AVStream’ has no member named ‘codec’
2257 | switch (__pyx_v_c_stream->codec->codec_type) {
| ^~
src/av/stream.c: In function ‘__pyx_f_2av_6stream_6Stream__init’:
src/av/stream.c:2875:29: error: ‘struct AVStream’ has no member named ‘codec’
2875 | __pyx_t_1 = __pyx_v_stream->codec;
| ^~
src/av/stream.c:2995:15: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
2995 | __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:3688:130: error: ‘struct AVStream’ has no member named ‘codec’
3688 | __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, 144, __pyx_L1_error)
| ^~
error: command '<here is my_gcc_path>' failed with exit code 1
...
Reproduction
build pyAV with latest ffmpeg library
Versions
-
OS: Linux
-
FFmpeg:
ffmpeg version N-102619-gebedd26eef Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.2.0 (GCC)
configuration: --prefix=<my path> --extra-cflags='-fPIC -m64' --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libvpx --enable-libmp3lame --enable-libopus --enable-libwebp --enable-libass --enable-cuda-nvcc --enable-libnpp --enable-cuvid --enable-nvenc --nvccflags='-gencode arch=compute_60,code=sm_60 -O2' --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libwebp --enable-openssl --enable-libsvtav1 --enable-libvorbis --enable-fontconfig --enable-pic
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 1.100 / 59. 1.100
libavformat 59. 2.101 / 59. 2.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.101 / 8. 0.101
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
Research
I have done the following:
- [x] Checked the PyAV documentation
- [x] Searched on Google
- [x] Searched on Stack Overflow
- [x] Looked through old GitHub issues
- [ ] Asked on PyAV Gitter
- [ ] ... and waited 72 hours for a response.
@zzjjbb I just build both ffmpeg and pyAV from source, and it works.
ffmpeg using branch origin/release/4.4
pyAV using tag v8.0.3
you can build PyAV from source using the Makefile in the repo
PR is welcome.
@zzjjbb I just build both ffmpeg and pyAV from source, and it works. ffmpeg using branch
origin/release/4.4pyAV using tagv8.0.3you can build PyAV from source using the Makefile in the repo
Hello @dianyo , I have built according to the version you provided, but still encounter the same problem above. Could you please elaborate on your build process? thanks in advance.
What version was this tested against, FFmpeg 5.x?
I'm experiencing similar.
- OS: macOS on arm64
- FFmpeg: version 5.0
pip install av fails with our without --no-binary av
For those looking to use ffmpeg 4.x under macOS, you can still install it via brew, but you need to tell pkg_config where to locate the libraries:
brew install ffmpeg@4
export PKG_CONFIG_PATH="/opt/homebrew/opt/ffmpeg@4/lib/pkgconfig"
pip3 install av
I'm experiencing similar.
* OS: macOS on arm64 * FFmpeg: version 5.0
pip install avfails with our without--no-binary av
That's a slightly different issue. If we had binary wheels for arm64 you would not need to build PyAV yourself.
FWIW I am getting the same error on x86_64 GNU/Linux with ffmpeg 5.0, sadly blocking a rebuild of mine.
ffmpeg -version:
ffmpeg version n5.0 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.1.0 (GCC)
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb
--enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-shared --enable-version3
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
@zupatisc not productive, we know PyAV doesn't build with FFmpeg 5. I'm still waiting for someone to step up and provide a pull request.
OK, I've had a look and the main breaking change in FFmpeg seems to be that AVStream.codec, a pointer to an AVCodecContext is gone. This member has been deprecated since at least FFmpeg 4, so no surprise there.
AFAICT this means that in our Stream class, we are going to need to have our own pointer to an AVCodecContext, which we allocate and free. There is a AVStream.codecpar structure which holds information about the codec in the context of the stream. To the best of my understand the logic is as follows:
- For input: we use AVStream.codecpar configure our AVCodecContext using avcodec_parameters_to_context
- For output: we need to copy parameters from AVCodecContext to AVStream.codecpar using avcodec_parameters_from_context (which we already do)
I have a very rough patch in #910, but there seem to be some unexpected consequences so it might be a while.
For those looking to use ffmpeg 4.x under macOS, you can still install it via brew, but you need to tell
pkg_configwhere to locate the libraries:brew install ffmpeg@4 export PKG_CONFIG_PATH="/opt/homebrew/opt/ffmpeg@4/lib/pkgconfig" pip3 install av
Haven't tested yet, but could this be added to the Documentation?!? For example, in a trouble shooting section?
Tested, and works!
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.
Not stale, see #910.
(Sorry for the noise, making stalebot go away.)
Wait, this was already merged, so I guess this issue can be closed? @jlaine
Not yet in a release (I've cherry-picked it for Debian for now)
Has this been updated as yet?
I was able to install it using this for now, although it'd be nice if it was released.
pip3 install git+https://github.com/PyAV-Org/PyAV
@uvjustin how do you feel about pushing out a PyAV release as-is? I had been hoping to bundle the API changes we mentioned in #1005 but I'm just too short on spare time. I feel the community would be best served by immediately having an FFmpeg5-compatible PyAV now.
I think we should at least make the changes mentioned in https://github.com/PyAV-Org/PyAV/pull/1007#issuecomment-1187706065 before the next release. I'll put together a quick PR.
I've tagged the release, so the wheels will be hitting PyPI as soon as CI completes (probably in ~4 hours)!