PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

PyAV does not build with ffmpeg 5.x

Open zzjjbb opened this issue 4 years ago • 16 comments

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:

zzjjbb avatar Sep 27 '21 03:09 zzjjbb

@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

dianyo avatar Oct 13 '21 15:10 dianyo

PR is welcome.

jlaine avatar Nov 03 '21 23:11 jlaine

@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

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.

RayanWang avatar Nov 11 '21 08:11 RayanWang

What version was this tested against, FFmpeg 5.x?

jlaine avatar Jan 25 '22 12:01 jlaine

I'm experiencing similar.

  • OS: macOS on arm64
  • FFmpeg: version 5.0

pip install av fails with our without --no-binary av

coreyti avatar Feb 09 '22 17:02 coreyti

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

slhck avatar Feb 10 '22 09:02 slhck

I'm experiencing similar.

* OS: macOS on arm64

* FFmpeg: version 5.0

pip install av fails 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.

jlaine avatar Feb 10 '22 17:02 jlaine

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 avatar Feb 11 '22 12:02 zupatisc

@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.

jlaine avatar Feb 12 '22 16:02 jlaine

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:

jlaine avatar Mar 12 '22 16:03 jlaine

I have a very rough patch in #910, but there seem to be some unexpected consequences so it might be a while.

jlaine avatar Mar 15 '22 20:03 jlaine

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

Haven't tested yet, but could this be added to the Documentation?!? For example, in a trouble shooting section?

Tested, and works!

bschollnick avatar May 08 '22 20:05 bschollnick

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.

github-actions[bot] avatar Sep 06 '22 04:09 github-actions[bot]

Not stale, see #910.

(Sorry for the noise, making stalebot go away.)

slhck avatar Sep 06 '22 06:09 slhck

Wait, this was already merged, so I guess this issue can be closed? @jlaine

slhck avatar Sep 06 '22 06:09 slhck

Not yet in a release (I've cherry-picked it for Debian for now)

jonassmedegaard avatar Sep 06 '22 16:09 jonassmedegaard

Has this been updated as yet?

nikky4D avatar Sep 28 '22 18:09 nikky4D

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

theoparis avatar Oct 16 '22 04:10 theoparis

@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.

jlaine avatar Oct 16 '22 09:10 jlaine

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.

uvjustin avatar Oct 16 '22 11:10 uvjustin

I've tagged the release, so the wheels will be hitting PyPI as soon as CI completes (probably in ~4 hours)!

jlaine avatar Oct 17 '22 20:10 jlaine