Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyAV does not build with ffmpeg 5.x #817

Closed
4 of 6 tasks
zzjjbb opened this issue Sep 27, 2021 · 21 comments
Closed
4 of 6 tasks

PyAV does not build with ffmpeg 5.x #817

zzjjbb opened this issue Sep 27, 2021 · 21 comments
Labels
build help wanted The maintainer could use help here.

Comments

@zzjjbb
Copy link
Contributor

zzjjbb commented Sep 27, 2021

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 zzjjbb added the build label Sep 27, 2021
@dianyo
Copy link

dianyo commented Oct 13, 2021

@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

@jlaine
Copy link
Collaborator

jlaine commented Nov 3, 2021

PR is welcome.

@RayanWang
Copy link

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

@jlaine
Copy link
Collaborator

jlaine commented Jan 25, 2022

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

@coreyti
Copy link

coreyti commented Feb 9, 2022

I'm experiencing similar.

  • OS: macOS on arm64
  • FFmpeg: version 5.0

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

@jlaine jlaine changed the title av/stream.c does not build. PyAV does not build with ffmpeg 5.x Feb 9, 2022
@slhck
Copy link

slhck commented Feb 10, 2022

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

@jlaine
Copy link
Collaborator

jlaine commented Feb 10, 2022

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.

@zupatisc
Copy link

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

@jlaine
Copy link
Collaborator

jlaine commented Feb 12, 2022

@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 jlaine added the help wanted The maintainer could use help here. label Feb 12, 2022
hubutui added a commit to archlinuxcn/repo that referenced this issue Mar 8, 2022
@jlaine
Copy link
Collaborator

jlaine commented Mar 12, 2022

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
Copy link
Collaborator

jlaine commented Mar 15, 2022

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

@bschollnick
Copy link

bschollnick commented May 8, 2022

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!

@github-actions
Copy link

github-actions bot commented Sep 6, 2022

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 github-actions bot added the stale label Sep 6, 2022
@slhck
Copy link

slhck commented Sep 6, 2022

Not stale, see #910.

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

@slhck
Copy link

slhck commented Sep 6, 2022

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

@jonassmedegaard
Copy link

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

@github-actions github-actions bot removed the stale label Sep 7, 2022
@nikky4D
Copy link

nikky4D commented Sep 28, 2022

Has this been updated as yet?

@theoparis
Copy link

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

@jlaine
Copy link
Collaborator

jlaine commented Oct 16, 2022

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

@uvjustin
Copy link
Contributor

I think we should at least make the changes mentioned in #1007 (comment) before the next release. I'll put together a quick PR.

@jlaine
Copy link
Collaborator

jlaine commented Oct 17, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build help wanted The maintainer could use help here.
Projects
None yet
Development

No branches or pull requests