1

I want to read each frame from a mkv file to loop over and apply my object detection algorithm. However i cant find any way to read the video from the mkv file.

I want a similar function to the imutils.video.FileVideoStream, but for mkv file.

vs = FileVideoStream('C:/Users/hedeg/Documents/TRN-pytorch/sample_data/Lift.mp4').start()

Masilila
  • 504
  • 4
  • 9
  • Have you tried reading using OpenCV: `cap = cv2.VideoCapture(intput_filename)`, `while True:`, `ret, frame = cap.read()`, `if not ret:`, `break`... ? – Rotem Apr 14 '20 at 12:36

1 Answers1

3

It's possible imutils (and/or the underlying OpenCV library) doesn't know how to handle MKV containers even if the data contained within would be fine.

Assuming the MKV file contains data that OpenCV can read, you can just re-container the video (without re-encoding) into an .mp4 using e.g. ffmpeg:

ffmpeg -i my_mkv.mkv -codec copy my_mkv.mp4
AKX
  • 152,115
  • 15
  • 115
  • 172
  • I have had problems with python opencv reading mkv files and processing it further. With this easy way of conversion though I can use opencv now with the better supported .mp4 format. Thank you! – Caruso33 Mar 19 '21 at 13:59