PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

cv2.imshow freezes after av is imported

Open samiamlabs opened this issue 3 years ago • 9 comments

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

  • OS: Ubuntu 22.04
  • PyAV versions: 9 and greater

samiamlabs avatar Nov 16 '22 13:11 samiamlabs

+1

RemiFabre avatar Dec 20 '22 16:12 RemiFabre

+1

apirrone avatar Dec 20 '22 17:12 apirrone

So the solution was to upgrade to pyav 10?

HanzCEO avatar Dec 25 '22 13:12 HanzCEO

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

jlaine avatar Jan 23 '23 07:01 jlaine

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.

marcusvaltonen avatar Mar 10 '23 12:03 marcusvaltonen

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()

Linusnie avatar May 05 '23 09:05 Linusnie

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

coder111111 avatar May 23 '23 17:05 coder111111

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?

hmasum52 avatar Jun 17 '24 14:06 hmasum52

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 avatar Aug 01 '24 07:08 WyattBlue

Still can't repo. closing

WyattBlue avatar Sep 06 '24 06:09 WyattBlue