How can I extract video into frames using python only. I got plenty of solutions but they all are using OpenCV. But in my case I want to do it using python only.
Your help will be highly appreciated.
How can I extract video into frames using python only. I got plenty of solutions but they all are using OpenCV. But in my case I want to do it using python only.
Your help will be highly appreciated.
First you should understand that there are many different video codecs and even different video containers in common use, currently. Any library that offers video decoding usually has a multitude of different sub-libraries, to be able to read all the codecs.
But even for single codec/container variants you will not find any Python implementations, beyond toy or research projects. Video decoders are written in C, C++ or similar languages, as the process is computationally very expensive.
The video decoding in OpenCV is a relatively thin wrapper of ffmpeg/libav functionality. All the heavy lifting is done by ffmpeg. So if you want to do without OpenCV, that's possible by finding another video decoding library wrapper in Python. But you will not find a pure-Python implementation of video decoding for common video files.
I had the same problem with a specific video family that OpenCV have problem reading. I used the subprocess module to call ffmpeg but eventually I wanted to remove the use of the subprocess module. Eventually I did implement a pure-python reading script for my specific video family.
The easy part is to read the video file:
video_file_pipe = open("video.avi", mode="rb") data = video_file_pipe.read(number_of_bytes) On top of that you need to understand what is the video compression used for your specific case and decode your video. There are different level of complexity so it really depends on which video compression you want to extract frames from. As mentioned above you can used already made video decoder that are implemented in c/c++ (I didn't find any good one in python) but you will need to write python binding for it.
Last note, there are some good reasons not to use OpenCV but in practice it can be really resourceful to replace it. However if you can use C++ instead of python I wouldn't waste my time to implement the video decoding on my own.