Repository: PyAV-Org/PyAV

Issue #1140: Pip install is failing to build due to av/logging.pyx error
Created: 2023-07-18T06:54:00Z
Overview
I'm currently using the stable version of PyAV (v9.0.2) in a docker container, and building in a docker image for a while with no issue. Recently, my docker image failed due to build errors in pyav when installing pyav using pip.
I'm building on a TX2NX dev kit, running Jetpack 4.6 with an arm64 compiled version of FFMPEG 4.3.2(https://launchpad.net/~jonathonf/+archive/ubuntu/ffmpeg-4), on python v3.6.9
Expected behavior
It should build without error
Actual behavior
It's now building with error, when nothing in the environment has changed due to it being in a docker container.
Build report:
python3 setup.py build_ext --inplace                                                                                                                                                                           
Compiling av/logging.pyx because it changed.                                                                                                                                                                                                  
[1/1] Cythonizing av/logging.pyx                                                                                                                                                                                                              
                                                                                                                                                                                                                                              
Error compiling Cython file:                                                                                                                                                                                                                  
------------------------------------------------------------                                                                                                                                                                                  
...                                                                                                                                                                                                                                           
cdef const char *log_context_name(void *ptr) nogil:                                                                                                                                                                                           
    cdef log_context *obj = <log_context*>ptr                                                                                                                                                                                                 
    return obj.name                                                                                                                                                                                                                           
                                                                                                                                                                                                                                              
cdef lib.AVClass log_class                                                                                                                                                                                                                    
log_class.item_name = log_context_name                                                                                                                                                                                                        
                      ^                                                                                                                                                                                                                       
------------------------------------------------------------                                                                                                                                                                                  
                                                                                                                                                                                                                                              
av/logging.pyx:216:22: Cannot assign type 'const char *(void *) except? NULL nogil' to 'const char *(*)(void *) noexcept nogil'                                                                                                               
                                                                                                                                                                                                                                              
Error compiling Cython file:                                                                                                                                                                                                                  
------------------------------------------------------------                                                                                                                                                                                  
...                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                              
# Start the magic!                                                                                                                                                                                                                            
# We allow the user to fully disable the logging system as it will not play                                                                                                                                                                   
# nicely with subinterpreters due to FFmpeg-created threads.                                                                                                                                                                                  
if os.environ.get('PYAV_LOGGING') != 'off':                                                                                                                                                                                                   
    lib.av_log_set_callback(log_callback)                                                                                                                                                                                                     
                            ^                                                                                                                                                                                                                 
------------------------------------------------------------                                                                                                                                                                                  
                                                                                                                                                                                                                                              
av/logging.pyx:351:28: Cannot assign type 'void (void *, int, const char *, va_list) except * nogil' to 'av_log_callback'                                                                                                                     
Traceback (most recent call last):                                                                                                                                                                                                            
  File "setup.py", line 163, in <module>                                                                                                                                                                                                      
    include_path=["include"],                                                                                                                                                                                                                 
  File "/home/presien/.local/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize                                                                                                                               
    cythonize_one(*args)                                                                                                                                                                                                                      
  File "/home/presien/.local/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one                                                                                                                           
    raise CompileError(None, pyx_file)                                                                                                                                                                                                        
Cython.Compiler.Errors.CompileError: av/logging.pyx

Investigation
I've tried to run the build natively on the host using the python3 setup.py method, at branch v9.0.2, and I'm getting the same issue
Reproduction
This might be hard to reproduce since its ran on a Nvidia TX2NX Hardware

Jetpack OS version 4.6.1
Install ffmpeg 4.3.2 from https://launchpad.net/~jonathonf/+archive/ubuntu/ffmpeg-4, along with all of the dev libs shown below

libavformat-dev 
libavcodec-dev 
libavdevice-dev 
libavutil-dev 
libavfilter-dev 
libswscale-dev 
libswresample-dev


clone pyav
checkout tag v9.0.2
follow installation guide in readme

Versions

OS: Nvidia Jetpack 4.6.1
PyAV runtime:

n/a


PyAV build:

python3 setup.py config --verbose
Compiling av/logging.pyx because it changed.
[1/1] Cythonizing av/logging.pyx

Error compiling Cython file:
------------------------------------------------------------
...
cdef const char *log_context_name(void *ptr) nogil:
    cdef log_context *obj = <log_context*>ptr
    return obj.name

cdef lib.AVClass log_class
log_class.item_name = log_context_name
                      ^
------------------------------------------------------------

av/logging.pyx:216:22: Cannot assign type 'const char *(void *) except? NULL nogil' to 'const char *(*)(void *) noexcept nogil'

Error compiling Cython file:
------------------------------------------------------------
...

# Start the magic!
# We allow the user to fully disable the logging system as it will not play
# nicely with subinterpreters due to FFmpeg-created threads.
if os.environ.get('PYAV_LOGGING') != 'off':
    lib.av_log_set_callback(log_callback)
                            ^
------------------------------------------------------------

av/logging.pyx:351:28: Cannot assign type 'void (void *, int, const char *, va_list) except * nogil' to 'av_log_callback'
Traceback (most recent call last):
  File "setup.py", line 163, in <module>
    include_path=["include"],
  File "/home/presien/.local/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
    cythonize_one(*args)
  File "/home/presien/.local/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: av/logging.pyx


FFmpeg:

ffmpeg -version
ffmpeg version 4.3.2-0york0~18.04 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version='0york0~18.04' --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --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-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-libzimg --enable-pocketsphinx --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

Research
I have done the following:

 Checked the PyAV documentation
 Searched on Google
 Searched on Stack Overflow
 Looked through old GitHub issues
 Asked on PyAV Gitter
 ... and waited 72 hours for a response.

Duplicate issue #1160: CompileError: av/logging.pyx on main branch
Created: 2023-09-01T18:43:02Z
Overview
logging.pyx can not be compiled.
Expected behavior
Main should build without issues.
Actual behavior
Build report:
$ python setup.py build
Compiling av/logging.pyx because it changed.
[1/1] Cythonizing av/logging.pyx

Error compiling Cython file:
------------------------------------------------------------
...
cdef const char *log_context_name(void *ptr) nogil:
    cdef log_context *obj = <log_context*>ptr
    return obj.name

cdef lib.AVClass log_class
log_class.item_name = log_context_name
                      ^
------------------------------------------------------------

av/logging.pyx:216:22: Cannot assign type 'const char *(void *) except? NULL nogil' to 'const char *(*)(void *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to type 'const char *(void *) except? NULL nogil'.

Error compiling Cython file:
------------------------------------------------------------
...

# Start the magic!
# We allow the user to fully disable the logging system as it will not play
# nicely with subinterpreters due to FFmpeg-created threads.
if os.environ.get('PYAV_LOGGING') != 'off':
    lib.av_log_set_callback(log_callback)
                            ^
------------------------------------------------------------

av/logging.pyx:351:28: Cannot assign type 'void (void *, int, const char *, va_list) except * nogil' to 'av_log_callback'. Exception values are incompatible. Suggest adding 'noexcept' to type 'void (void *, int, const char *, va_list) except * nogil'.
Traceback (most recent call last):
  File "/home/moi/Development/PyAV/PyAV/setup.py", line 157, in <module>
    ext_modules += cythonize(
  File "/home/moi/Development/PyAV/PyAV/venvs/Linux.5.15.0-79-generic.cpython3.10/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
    cythonize_one(*args)
  File "/home/moi/Development/PyAV/PyAV/venvs/Linux.5.15.0-79-generic.cpython3.10/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: av/logging.pyx

Versions

OS: Ubuntu 22.04.3 LTS
PyAV runtime: /
PyAV build: /
Python: 3.10.12 (venv)
Cython: 3.0.2 (venv)
FFmpeg: (venv)

$ ffmpeg -version
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04)
configuration: --disable-doc --disable-mmx --disable-optimizations --disable-static --disable-stripping --enable-debug=3 --enable-gpl --enable-libx264 --enable-libxml2 --enable-shared --prefix=/home/moi/Development/PyAV/PyAV/vendor/build/ffmpeg-4.2
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

Research
I have done the following:

 Checked the PyAV documentation
 Searched on Google
 Searched on Stack Overflow
 Looked through old GitHub issues
 Asked on PyAV Gitter (Link does not work.)
 ... and waited 72 hours for a response.

Closing comment (2023-09-03T08:27:40Z): Oh, this is a duplicate of: #1140