Skip to content

Commit b8fb783

Browse files
committed
added readme
1 parent 429f1bd commit b8fb783

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Thumbnail Extractor
2+
3+
This Python function extracts a thumbnail frame from a video and saves it as an image file. It utilizes the OpenCV library to perform these operations. This README provides an overview of the function, its usage, and the required packages.
4+
5+
## Table of Contents
6+
- [Function Description](#function-description)
7+
- [Usage](#usage)
8+
- [Required Packages](#required-packages)
9+
10+
## Function Description
11+
12+
The `extract_thumbnail` function takes two parameters:
13+
14+
- `video_path` (str): The path to the input video file.
15+
- `frame_size` (tuple): A tuple containing the desired dimensions (width, height) for the thumbnail frame.
16+
17+
The function will raise an `Exception` if it fails to extract a frame from the video.
18+
19+
### Function Logic
20+
21+
1. The function opens the specified video file using OpenCV.
22+
2. It seeks to the middle frame by calculating the middle frame index.
23+
3. The frame is resized to the specified dimensions.
24+
4. The resized frame is saved as an image file with a filename derived from the video's base name.
25+
26+
## Usage
27+
28+
Here's an example of how to use the function:
29+
30+
```python
31+
from thumbnail_extractor import extract_thumbnail
32+
33+
# Extract a thumbnail from 'my_video.mp4' with dimensions (320, 240)
34+
extract_thumbnail('my_video.mp4', (320, 240))
35+
# Replace 'my_video.mp4' with the path to your own video file and (320, 240) with your desired thumbnail dimensions.
36+
37+
## Required Packages
38+
```
39+
To use this function, you need the following package:
40+
41+
- **OpenCV (cv2)**: You can install it using `pip`:
42+
43+
```shell
44+
pip install opencv-python
45+
```
46+
47+
This function is useful for generating thumbnail images from videos. It simplifies the process of creating video thumbnails for various applications.
48+
49+

0 commit comments

Comments
 (0)