Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 71fa076

Browse files
Merge pull request avinashkranjan#1145 from tanvi355/issue#1035
Video to PDF (GUI)
2 parents b78fac2 + e8249ef commit 71fa076

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

‎Video to PDF/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Video to PDF Converter
2+
3+
Using this tool, you can convert any video of your choice into a PDF.
4+
5+
To run the script, install the dependencies using
6+
``
7+
pip install -r requirements.txt
8+
``
9+
10+
[Sample Video Link](https://www.youtube.com/watch?v=rGHrKkieqCY)
11+
12+
13+
## Author
14+
[Tanvi Bugdani](https://github.com/tanvi355)

‎Video to PDF/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fpdf==1.7.2
2+
speech_recognition==3.7.1
3+
moviepy==1.0.1

‎Video to PDF/script.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
from tkinter import *
2+
from moviepy.editor import VideoFileClip
3+
from moviepy.editor import AudioFileClip
4+
from tkinter import filedialog
5+
from tkinter import messagebox
6+
from tkinter import ttk
7+
from fpdf import FPDF
8+
import threading
9+
import speech_recognition as sr
10+
import os
11+
12+
13+
#variables
14+
video_clip = ''
15+
audio_clip = ''
16+
17+
#function to get video
18+
def get_video():
19+
global video_filepath, video_clip
20+
try:
21+
video_filepath.set(filedialog.askopenfilename(title="Select your video file"))
22+
video_clip = VideoFileClip(str(video_filepath.get()))
23+
except:
24+
messagebox.showerror("Error", "No video selected")
25+
26+
27+
#function to convert audio to pdf
28+
def audio_to_pdf():
29+
global audio_clip
30+
try :
31+
audio_clip = video_clip.audio.write_audiofile(r"my_audio.wav")
32+
r = sr.Recognizer()
33+
with sr.AudioFile("my_audio.wav") as source:
34+
audio_data = r.record(source)
35+
text = r.recognize_google(audio_data)
36+
write_file = open('my_text.txt', 'w')
37+
write_file.write(text)
38+
write_file.close()
39+
text_to_pdf('my_text.txt')
40+
messagebox.showinfo("Message", "Conversion Successfull")
41+
except :
42+
messagebox.showerror( "Error", "Conversion not performed")
43+
44+
video_filepath.set('')
45+
46+
progress_bar['value'] = 0
47+
progress_bar.stop()
48+
49+
os.remove("my_audio.wav")
50+
os.remove("my_text.txt")
51+
52+
#function to convert text to pdf
53+
def text_to_pdf(file):
54+
pdf = FPDF(format='letter', unit='in')
55+
pdf.add_page()
56+
pdf.set_font("Arial", size = 12)
57+
effective_page_width = pdf.w - 2*pdf.l_margin
58+
59+
f = open(file, "r")
60+
61+
for x in f:
62+
pdf.multi_cell(effective_page_width, 0.15, x)
63+
pdf.ln(0.5)
64+
65+
pdf.output("../Video to PDF/my_pdf.pdf")
66+
67+
68+
69+
#function to run the script
70+
def run():
71+
global progress_bar
72+
t1 = threading.Thread(target = progress_bar.start)
73+
t2 = threading.Thread(target = audio_to_pdf)
74+
t2.start()
75+
t1.start()
76+
77+
78+
# GUI CODE
79+
# Intializing main program settings
80+
root = Tk()
81+
root.title("Video to PDF Converter")
82+
83+
# Variables for file paths
84+
video_filepath = StringVar()
85+
86+
# Creating UI Frame
87+
UI_frame = Frame(root, width=500, height=500, relief = "raised")
88+
UI_frame.grid(row=0, column=0)
89+
90+
convert_frame = Frame(root, width=500, height=500, relief="raised")
91+
convert_frame.grid(row=1, column=0)
92+
93+
# Labels and buttons
94+
select = Label(UI_frame, text="Select Video : ", font = ("Arial", 12))
95+
select.grid(row=1, column=1, padx=5, pady=5, sticky=W)
96+
97+
browse = Button(UI_frame, text="Browse", command = get_video, font = ("Arial", 12))
98+
browse.grid(row=1, column=2, padx=5, pady=5)
99+
100+
video_selected = Label(UI_frame, text = "Selected video : ", font = ("Arial", 12))
101+
video_selected.grid(row = 2, column = 1, padx = 5, pady = 5, sticky = E)
102+
103+
video_path = Label(UI_frame, textvariable=video_filepath)
104+
video_path.grid(row=2, column=2, padx=2, pady=5, sticky=W)
105+
106+
convert = Button(convert_frame, text="Convert", command = run, font = ("Arial", 12))
107+
convert.grid(row=3, column=1, pady=5)
108+
109+
progress_bar = ttk.Progressbar(root, orient=HORIZONTAL, mode='indeterminate', length=500)
110+
progress_bar.grid(padx=25, pady=25)
111+
112+
# Calling main program
113+
root.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /