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 f214513

Browse files
committed
video to pdf
1 parent b6c6188 commit f214513

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

‎Video to PDF/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Video to PDF Converter
2+
3+
Using this tool, you can convert any video of your choice into a PDF.
4+
5+
## Modules used :
6+
- Tkinter
7+
- MoviePy
8+
- Speech Recognition
9+
- OS
10+
- FPDF
11+
12+
[Sample Video Link](https://www.youtube.com/watch?v=rGHrKkieqCY)
13+
14+
15+
## Author
16+
[Tanvi Bugdani](https://github.com/tanvi355)

‎Video to PDF/my_pdf.pdf

1.14 KB
Binary file not shown.

‎Video to PDF/script.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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.write('\n')
39+
write_file.write('abcdefg')
40+
write_file.close()
41+
text_to_pdf('my_text.txt')
42+
messagebox.showinfo("Message", "Conversion Successfull")
43+
except :
44+
messagebox.showerror( "Error", "Conversion not performed")
45+
46+
video_filepath.set('')
47+
48+
progress_bar['value'] = 0
49+
progress_bar.stop()
50+
51+
os.remove("my_audio.wav")
52+
os.remove("my_text.txt")
53+
54+
#function to convert text to pdf
55+
def text_to_pdf(file):
56+
pdf = FPDF(format='letter', unit='in')
57+
pdf.add_page()
58+
pdf.set_font("Arial", size = 12)
59+
effective_page_width = pdf.w - 2*pdf.l_margin
60+
61+
f = open(file, "r")
62+
63+
for x in f:
64+
pdf.multi_cell(effective_page_width, 0.15, x)
65+
pdf.ln(0.5)
66+
67+
68+
pdf.output("my_pdf.pdf")
69+
70+
71+
72+
#function to run the script
73+
def run():
74+
global progress_bar
75+
t1 = threading.Thread(target = progress_bar.start)
76+
t2 = threading.Thread(target = audio_to_pdf)
77+
t2.start()
78+
t1.start()
79+
80+
81+
# GUI CODE
82+
# Intializing main program settings
83+
root = Tk()
84+
root.title("Video to PDF Converter")
85+
86+
# Variables for file paths
87+
video_filepath = StringVar()
88+
89+
# Creating UI Frame
90+
UI_frame = Frame(root, width=500, height=500, relief = "raised")
91+
UI_frame.grid(row=0, column=0)
92+
93+
convert_frame = Frame(root, width=500, height=500, relief="raised")
94+
convert_frame.grid(row=1, column=0)
95+
96+
# Labels and buttons
97+
select = Label(UI_frame, text="Select Video : ", font = ("Arial", 12))
98+
select.grid(row=1, column=1, padx=5, pady=5, sticky=W)
99+
100+
browse = Button(UI_frame, text="Browse", command = get_video, font = ("Arial", 12))
101+
browse.grid(row=1, column=2, padx=5, pady=5)
102+
103+
video_selected = Label(UI_frame, text = "Selected video : ", font = ("Arial", 12))
104+
video_selected.grid(row = 2, column = 1, padx = 5, pady = 5, sticky = E)
105+
106+
video_path = Label(UI_frame, textvariable=video_filepath)
107+
video_path.grid(row=2, column=2, padx=2, pady=5, sticky=W)
108+
109+
convert = Button(convert_frame, text="Convert", command = run, font = ("Arial", 12))
110+
convert.grid(row=3, column=1, pady=5)
111+
112+
progress_bar = ttk.Progressbar(root, orient=HORIZONTAL, mode='indeterminate', length=500)
113+
progress_bar.grid(padx=25, pady=25)
114+
115+
# Calling main program
116+
root.mainloop()

0 commit comments

Comments
(0)

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