pythonopencvimutils

How to read video image from mkv file in python?


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


Solution

  • 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