4
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
1
  • ı'm using the same opencv-python==4.4.0.42, but I don't have any issue. Try reinstall opencv-python==4.4.0.42. Commented Aug 20, 2020 at 12:58

3 Answers 3

18

The following code resolved this issue for me:

video = cv2.VideoCapture(0,cv2.CAP_DSHOW)
Sign up to request clarification or add additional context in comments.

4 Comments

I think I also had to disable and then enable the webcam from Device Manager (otherwise I would get only a black image. No there wasn't a fly on my webcam), but I am not sure.
Had the same issue under Java + opencv 4.51. Adding the "CAP_DSHOW" argument fixed it: grabber = new VideoCapture(cameraIdx, Videoio.CAP_DSHOW);
An absolute lifesaver!
Thanks! In c++ it is: VideoCapture capture(0, CAP_DSHOW);
1

It's a reported issue, See the details: https://github.com/opencv/opencv/issues/16711

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.