Video Key Frame Extraction With katna data object and its analysis plays an important role in many fields such as video summarization, video browsing, compression, marketing and so on.
Katna is open source tool that automates the boring, error prone task of videos key/best frames extraction. The extracted frames are the most accurate and compact summary of the video content. Katna video module has been written in python 3 and has been successfully tested on mp4,.mov and .avi video formats. Technically, it should work well with other video formats since we have used openCV VideoCapture function. Katna has been written in an API style so that developers with no computer vision experience can use it as well.
The best way to learn about Katnasource activate katna
- Run the setup
python setup.py install
How to use katna
- Import the video module from the katna library
from Katna.video import Video
Instantiate the video class.
vd = Video()
- Call the extract_frames_as_images method of video object. The method accepts two parameters and returns a list of numpy 2D array which are images. The method accepts two parameters
- no_of_frames: Number of key frames to be extracted
- file_path: Video file path.
imgs = vd.extract_frames_as_images(no_of_frames = 10, file_path= <<File Path>>)
- Incase you want to persist the extracted key frames then call the save_frame_to_disk method of video object.. The method accepts three parameters and returns nothing.
- frame: In-menory images generated by extract_frames_as_images method.
- file_name: File name pattern for the persisted image.
- file_path: Folder location where files needs to be saved
- file_ext: File extension indicating the file type for example — ‘.jpg’
vd.save_frame_to_disk(img, file_path=output_folder_video_image, \
file_name="test_"+str(counter), file_ext=".jpeg"
That’s it!! You can find a complete application here.
Frame extraction and selection criteria
- Frame that are sufficiently different from previous ones using absolute differences in LUV color space
- Brightness score filtering of extracted frames
- Entropy/contrast score filtering of extracted frames
- K-Means Clustering of frames using image histogram
- Selection of best frame from clusters based on and variance of laplacian (image blur detection)
High level architecture
What’s next
We are looking at new filters to add. We would like to make the filter addition configurable so that community can add their own or integrate commercial filters.
Wrap up
We have used katna for hero image extractions from videos and has already saved more than 1000 person hours so far. We are thankful to the open source community and especially this project which helped us get started.
Needless to say, you feedback and suggestions are highly appreciated.