PyAV-Org / PyAV

Pythonic bindings for FFmpeg's libraries.
https://pyav.basswood-io.com/
BSD 3-Clause "New" or "Revised" License
2.53k stars 366 forks source link

cv2.imshow freezes after av is imported #1050

Closed samiamlabs closed 2 months ago

samiamlabs commented 2 years ago

Overview

My setup is a docker container with Ubuntu 22.04 and python 3.10 and av installed through pip as a dependency of aiortc.

The python scripts freeze on the cv2.imshow line after av is imported. There is no opencv window either. If I don't import av it works.

Expected behavior

The pip installed version of av should not cause any issues for opencv.

Actual behavior

cv2.imshow does not work after av is imported

Traceback: There is no error print or traceback, and I was not able to find any info additional info through the VSCode debugger.

Investigation

I tried building/installing v10.0.0 of PyAV from the source, which fixed the issue.

Reproduction

import cv2
import numpy as np

import av

def main(args=None):
    img = np.zeros((200, 200, 3), dtype=np.uint8)
    cv2.imshow('ImageWindow', img)
    cv2.waitKey()

if __name__ == '__main__':
    main()

Versions

RemiFabre commented 1 year ago

+1

apirrone commented 1 year ago

+1

HanzCEO commented 1 year ago

So the solution was to upgrade to pyav 10?

jlaine commented 1 year ago

Looks like a re-occurrence of #978 . Is this still current with PyAV 10?

marcusvaltonen commented 1 year ago

Looks like a re-occurrence of #978 . Is this still current with PyAV 10?

With Python 3.9.14 on Ubuntu 20.04 and

av==10.0.0 opencv-python==4.7.0.72

I still get this issue. EDIT: Without building from source.

Linusnie commented 1 year ago

As a temporary fix I found that calling cv2.imshow before import av prevents the freeze:

import numpy as np
import cv2
cv2.imshow('ffmpeg fix', np.array([1], dtype=np.uint8))
cv2.destroyAllWindows()
import av

red = np.ones((256, 256, 3)) * np.array([0, 0, 255])

cv2.imshow("red", red.astype(np.uint8))

cv2.waitKey(0)
cv2.destroyAllWindows()
coder111111 commented 1 year ago

I can verify this issue still happens with opencv-python 4.7.0.72 and av 10.0.0 Running Debian/Sid, x64

hmasum52 commented 5 months ago

I am facing the issue in raspberry pi 4. python 3.11 av==12.1.0 opencv-python==4.10.0.82

What is the fix?

WyattBlue commented 3 months ago

I can't repro. It's probably that I'm using MacOS. Looks like a Linux desktop issue. In fact, it's almost certainly an X11 issue. If someone showed that this can't be reproded in Wayland either, this issue should be closed.

WyattBlue commented 2 months ago

Still can't repo. closing