Skip to content

Commit 404fb49

Browse files
authored
Merge pull request #666 from RaveenaBhasin/mp4
MP4 to MP3 convertor added
2 parents df94ad0 + db61b5a commit 404fb49

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

mp4_to_mp3_convertor/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ✔ MP4 TO MP3 CONVERTER
2+
- ### A MP4 to MP3 Converter is an application created in python with tkinter gui.
3+
- ### In this application user will be able to convert any mp4 video file to audio file.
4+
- ### After conversion is successful, file will be saved automatically with file_name.mp3.
5+
6+
****
7+
8+
# REQUIREMENTS :
9+
- ### python 3
10+
- ### tkinter module
11+
- ### from tkinter messagebox module
12+
- ### PIL
13+
- ### os
14+
- ### moviepy
15+
16+
****
17+
18+
# How this Script works :
19+
- ### User just need to download the file and run the mp4_to_mp3_converter.py on their local system.
20+
- ### Now on the main window of the application user needs to select the mp4 file from the local system using SELECT button which he/she wants to convert to audio.
21+
- ### After selecting the mp4 file, user will be able to see the filename of the video selected in the textarea.
22+
- ### After that when user click on CONVERT MP4 To MP3, conversion will takes place and after a success messgae will be displayed on the screen.
23+
- ### And the audio file will be saved automatically in the project folder.
24+
25+
# Purpose :
26+
- ### This scripts helps user to easily convert any mp4 files to mp3 files.
27+
28+
# Compilation Steps :
29+
1. Clone/Download this repository
30+
```
31+
git clone clone_path
32+
```
33+
2. Install the requirements using the command
34+
```
35+
pip install -r requirements.txt
36+
```
37+
3. Run the program using command
38+
```
39+
python main.py
40+
```
41+
****
42+
43+

mp4_to_mp3_convertor/main.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# MP4 to MP3 Converter
2+
3+
# imported necessary library
4+
from tkinter import Tk, Button, Text, END
5+
import tkinter as tk
6+
from tkinter import filedialog
7+
import tkinter.messagebox as mbox
8+
from PIL import Image, ImageTk
9+
import moviepy
10+
import moviepy.editor
11+
import os
12+
13+
# created a main window
14+
window = Tk()
15+
window.title('MP4 to MP3 Converter')
16+
window.geometry("1000x700")
17+
18+
# top label
19+
start1 = tk.Label(text="MP4 to MP3 Converter",
20+
font=("Arial", 50),
21+
fg="magenta")
22+
start1.place(x=130, y=10)
23+
24+
# image on the main window
25+
path = "Images/convert.jpg"
26+
# Creates a Tkinter-compatible photo image
27+
# which can be used everywhere Tkinter expects an image object.
28+
img1 = ImageTk.PhotoImage(Image.open(path))
29+
# The Label widget is a standard Tkinter widget used to display
30+
# a text or image on the screen.
31+
panel = tk.Label(window, image=img1)
32+
panel.place(x=170, y=120)
33+
34+
35+
def mp4_choose():
36+
global filename, onlyfilename
37+
filename = filedialog.askopenfilename(initialdir="/",
38+
title="Choose MP4",
39+
filetypes=(("Text files", "*.Mp4*"),
40+
("all files", "*.*")))
41+
# Change label contents
42+
# label_file_explorer.configure(text="File : " + filename)
43+
onlyfilename = os.path.basename(filename)
44+
fname.delete('1.0', END)
45+
fname.insert(END, onlyfilename)
46+
47+
48+
# select label
49+
select1 = tk.Label(text="Select MP4 File : ", font=("Arial", 30), fg="brown")
50+
select1.place(x=50, y=500)
51+
52+
# textarea for file name only
53+
fname = Text(window,
54+
height=1,
55+
width=23,
56+
font=("Arial", 25),
57+
bg="light yellow",
58+
fg="brown",
59+
borderwidth=2,
60+
relief="solid")
61+
fname.place(x=360, y=505)
62+
63+
# created a choose button , to choose the image from the local system
64+
chooseb = Button(window,
65+
text='SELECT',
66+
command=mp4_choose,
67+
font=("Arial", 17),
68+
bg="light green",
69+
fg="blue",
70+
borderwidth=3,
71+
relief="raised")
72+
chooseb.place(x=800, y=500)
73+
74+
75+
# Function for convert Mp4 to Mp3
76+
def convert():
77+
video = moviepy.editor.VideoFileClip(filename)
78+
# Convert video to audio
79+
audio = video.audio
80+
81+
aud_fname = ""
82+
for i in onlyfilename:
83+
if i == '.':
84+
break
85+
else:
86+
aud_fname = aud_fname + i
87+
print(aud_fname)
88+
audio.write_audiofile(f'{aud_fname}.mp3')
89+
mbox.showinfo("Success",
90+
"Video converted to Audio.\n\nAudio Saved Successfully")
91+
92+
93+
# created a choose button , to choose the image from the local system
94+
convertb = Button(window,
95+
text='CONVERT MP4 To MP3',
96+
command=convert, font=("Arial", 20),
97+
bg="light green",
98+
fg="blue",
99+
borderwidth=3,
100+
relief="raised")
101+
convertb.place(x=150, y=600)
102+
103+
104+
# defined exit_win function, to show a exit dialog box when tried to exit
105+
def exit_win():
106+
if mbox.askokcancel("Exit", "Do you want to exit?"):
107+
window.destroy()
108+
109+
110+
# creating an exit button
111+
exitB = Button(window,
112+
text='EXIT',
113+
command=exit_win,
114+
font=("Arial", 20),
115+
bg="red",
116+
fg="blue",
117+
borderwidth=3,
118+
relief="raised")
119+
exitB.place(x=750, y=600)
120+
121+
# this is done to show the exit dialog box when tried to exit from
122+
# main window using the top-roght close button of titlebar
123+
window.protocol("WM_DELETE_WINDOW", exit_win)
124+
window.mainloop()

mp4_to_mp3_convertor/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
libraries used : tkinter
2+
messagebox
3+
PIL
4+
moviepy
5+
os

0 commit comments

Comments
 (0)