python opencv format not supported

Viewed 5538
import cv2
image_counter = 0
video = cv2.VideoCapture(0)
while True:
    check, frame = video.read()
    gray_f = cv2.flip(frame, 1)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    gray_flip = cv2.flip(frame, 1)
    cv2.imshow("kara", gray_flip)
    key = cv2.waitKey(1)

    if key == ord('q'):
        break
video.release()
cv2.destroyAllWindows()

I have written this code for using my camera using OpenCV python 3 it worked earlier but after I upgraded my python it gives following error:-

[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-j8nxabm_\opencv\modules\videoio\src\cap_msmf.cpp (682) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(unsupported media type)

Python version:3.8.5 x64
OpenCV version: 4.4.0.42
3 Answers

The following code resolved this issue for me:

video = cv2.VideoCapture(0,cv2.CAP_DSHOW)

i had this problem with java and Open Cv the problem is because the format of the video file (video.mp4) has sound and this is the reason why appear the trouble "MFVideoFormat_RGB32(unsupported media type)" the solution i found was use ffmpeg, I remove the audio of the video file with the next comand in cmd:

ffmpeg -i video.mp4 -an -c copy no_sound.mp4

Then I use the no_sound.mp4 in the next code:

VideoCapture cap =  new VideoCapture();
cap.open("no_sound.mp4");

This worked for me.

Related