Skip to content

Commit 47a55d2

Browse files
authored
Merge pull request #278 from kiranbaby14/video_to_gif
Video to gif
2 parents f2dc02f + 8247b7c commit 47a55d2

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ Once you are done working on your script edit this `README.md` file and add the
7878
52| Battery Alert | Notifies after threshold unit of battery change | [Find me here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Battery-Notifier) |
7979
53| Text To Handwriting Converter | Converts a text or a text file to handwritten images | [Find me here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/text_to_handwriting_converter) |
8080
54| Typing Speed Tester | Calculates the typing speed of users. | [Find me here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/typing_speed_test) |
81-
81+
55| Video To GIF Converter | Converts video to GIF | [Find me here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Video_to_GIF_Converter) |
8282

8383
### Good Luck and don't forget to have fun with Open Source 🚀
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Video to GIF Converter
2+
3+
![built by developers](http://ForTheBadge.com/images/badges/built-by-developers.svg)
4+
![python](https://img.shields.io/badge/language-Python-orange?style=for-the-badge)
5+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=plasitc)](https://github.com/psf/black)
6+
7+
### About
8+
9+
A Python3 script to convert video to GIF.
10+
11+
### GIF Examples
12+
![mygif5](https://user-images.githubusercontent.com/50899339/136929374-94e8784f-102b-4225-ae29-0087930b7f35.gif)
13+
![mygif3](https://user-images.githubusercontent.com/50899339/136928157-bc6efc3b-8618-4f76-a3f4-edf747a4fcbc.gif)
14+
![mygif4](https://user-images.githubusercontent.com/50899339/136928164-14d5dd8f-636b-4d39-948a-d2ebda9e8e4c.gif)
15+
![mygif6](https://user-images.githubusercontent.com/50899339/136929902-39dcee65-1ac6-4e38-8f34-a1114a420dd4.gif)
16+
![mygif2](https://user-images.githubusercontent.com/50899339/136928102-7c44384f-ac50-4415-8794-48089fbad981.gif)
17+
![mygif1](https://user-images.githubusercontent.com/50899339/136928184-6c63d074-135b-4536-856b-06d0c566dbf0.gif)
18+
19+
20+
21+
22+
### Setup
23+
24+
* Install Python3 for Windows from [here](https://python.org).
25+
* Open Windows Command Prompt
26+
* Clone the repository
27+
```bash
28+
git clone https://github.com/GDSC-RCCIIT/General-Purpose-Scripts.git
29+
```
30+
* Navigate inside the ```scripts\Video_to_GIF_Converter``` directory.
31+
```bash
32+
cd General-Purpose-Scripts\scripts\Video_to_GIF_Converter
33+
```
34+
* Run using Python
35+
```bash
36+
python video_to_gif_converter.py
37+
```
38+
39+
40+
### Steps to convert video to GIF
41+
42+
* Once the script has run the user will be asked to select the video file.
43+
* After the file has been selected the user should give:
44+
1) GIF start time
45+
2) GIF end time
46+
3) GIF size
47+
* After giving the inputs the GIF file will get automatically generated with the name "mygif.gif" in the directory.
48+
49+
50+
51+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
moviepy==1.0.3
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from moviepy.editor import VideoFileClip
2+
from tkinter.filedialog import *
3+
4+
5+
# ---------------function to get the time frames for the GIF----------
6+
def gif_time():
7+
print(
8+
"\nEnter time in the format: minutes seconds (Example: 2 2.5 --> 2 minutes 2.5 seconds)"
9+
)
10+
start = list(map(float, input("GIF start time: --> ").split()))
11+
end = list(map(float, input("GIF end time: --> ").split()))
12+
if len(start) == 1:
13+
start.append(0)
14+
if len(end) == 1:
15+
end.append(0)
16+
17+
return start, end
18+
19+
20+
try:
21+
video = askopenfilename()
22+
23+
while not video:
24+
video = askopenfilename()
25+
26+
# ---------calls the function------------
27+
clip_start, clip_end = gif_time()
28+
29+
# -------condition to check if start time in minutes > end time------
30+
while clip_start[0] > clip_end[0]:
31+
print("\nYou have entered start time > end time, which is not supported\n")
32+
clip_start, clip_end = gif_time()
33+
34+
# -------2nd condition to check if start time in seconds> end time------
35+
while clip_start[0] == clip_end[0] and clip_start[1] > clip_end[1]:
36+
print("\nYou have entered start time > end time, which is not supported\n")
37+
clip_start, clip_end = gif_time()
38+
39+
# -------condition to check if start time is equal to end time------
40+
while "".join(str(clip_start)) == "".join(str(clip_end)):
41+
print("\nYou have entered start time == end time, which is not supported\n")
42+
clip_start, clip_end = gif_time()
43+
44+
# ----------Get the size of the GIF image from user----------------
45+
resize = float(input("\nGIF size ( > 0 and < 1 preferred )(Example: 0.2): --> "))
46+
47+
print("\nProcessing...")
48+
49+
# ----------convert video to GIF with the given time frames----------------
50+
clip = (
51+
VideoFileClip(video)
52+
.subclip((clip_start[0], clip_start[1]), (clip_end[0], clip_end[1]))
53+
.resize(resize)
54+
)
55+
56+
clip.write_gif("mygif.gif")
57+
58+
print(
59+
"""
60+
***************************************
61+
mygif.gif created (check the .gif file)
62+
***************************************"""
63+
)
64+
65+
# -------------print exceptions-----------------
66+
except Exception as e:
67+
print("\nError occurred: ", e)
68+
69+
# -------------Keyboard exception-----------------
70+
except KeyboardInterrupt:
71+
print("\nError occurred: KeyboardInterrupt")

0 commit comments

Comments
 (0)