From a86c45319436391558d43c332c5651022e1575a9 Mon Sep 17 00:00:00 2001 From: Amr Mohamed Zaki Date: Fri, 26 Mar 2021 01:58:30 +0200 Subject: [PATCH 1/5] added video to audio converter gui --- Video-Audio-Converter-GUI/converter.py | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Video-Audio-Converter-GUI/converter.py diff --git a/Video-Audio-Converter-GUI/converter.py b/Video-Audio-Converter-GUI/converter.py new file mode 100644 index 0000000000..7d462e59bf --- /dev/null +++ b/Video-Audio-Converter-GUI/converter.py @@ -0,0 +1,81 @@ +from tkinter import * +from moviepy.editor import * +from tkinter import filedialog +from tkinter import messagebox +from tkinter import ttk + + +# Variables for video and audio files +video_file = '' +audio_file = '' + + +def get_video_file(): + """ + Function that gets the video file that needs to be converted + """ + global video_filepath, video_file + + video_filepath.set(filedialog.askopenfilename(title="Select your video file", filetypes=[ + ('MP4 (mp4, m4a, m4v, f4v, f4a, m4b, m4r, f4b, mov)','*.mp4 *.m4a *.m4v *.f4v *.f4a *.m4b *.m4r *.f4b *.mov'), + ('3GP (3gp, 3gp2, 3g2, 3gpp, 3gpp2)','*.3gp *.3gp2 *.3g2 *.3gpp *.3gpp2'), + ('OGG (ogg, oga, ogv, ogx)','*.ogg *.oga *.ogv *.ogx'), + ('WMV (wmv, wma)','*.wmv *.wma'), + ('FLV','*.flv'), ('AVI','*.avi'), ('MPEG-1 (mpg, mp2, mpeg, mpe, mpv )','*.mpg *.mp2 *.mpeg *.mpe *.mpv'), + ('MPEG-2','*.mpg *.mpeg *.m2v')])) + video_file = VideoFileClip(str(video_filepath.get())) + + + +def save_audio_file(): + """ + Function that converts video file into audio file in a path that the user chooses + + """ + global audio_filepath, audio_file + + audio_filepath.set(filedialog.asksaveasfilename(defaultextension='.mp3', title="Select your audio file directory", filetypes=[ + ('MP3 File','*.mp3'), ('Wave File','*.wav')])) + + try: + audio_file = video_file.audio + audio_file.write_audiofile(str(audio_filepath.get())) + video_file.close() + audio_file.close() + messagebox.showinfo(message="File converted successfully") + except: + messagebox.showerror(message="File could not be converted", title="File Error") + + # Resetting the video and audio paths + video_filepath.set('') + audio_filepath.set('') + + + + +# Intializing main program settings +main_prog = Tk() +main_prog.title("Video to Audio Converter") +main_prog.maxsize(800, 400) +main_prog.minsize(500,200) +main_prog.config(bg="ivory") + + +# Variables for file paths +video_filepath = StringVar() +audio_filepath = StringVar() + +# Creating UI Frame +UI_frame = Frame(main_prog, width=500, height=500, bg="ivory") +UI_frame.grid(row=0, column=0) + +# Labels and buttons of the program +Label(UI_frame, text="Choose your video file", bg="ivory").grid(row=1, column=1, padx=5, pady=5, sticky=W) +Button(UI_frame, text="Browse", command=get_video_file, bg="grey").grid(row=1, column=2, padx=5, pady=5) +Button(UI_frame, text="Convert", command=save_audio_file, bg="green").grid(row=2, column=2, padx=5, pady=5) +Label(UI_frame, textvariable=video_filepath, bg="ivory").grid(row=1, column=3, padx=5, pady=5, sticky=W) + + + +# Calling main program +main_prog.mainloop() From ca00b72a64659d1da6a8ab8780577dd3dc2ec787 Mon Sep 17 00:00:00 2001 From: Amr Zaki <62449903+amrzaki2000@users.noreply.github.com> Date: Fri, 26 Mar 2021 02:04:26 +0200 Subject: [PATCH 2/5] Created README.md file --- Video-Audio-Converter-GUI/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Video-Audio-Converter-GUI/README.md diff --git a/Video-Audio-Converter-GUI/README.md b/Video-Audio-Converter-GUI/README.md new file mode 100644 index 0000000000..0edeeeeaed --- /dev/null +++ b/Video-Audio-Converter-GUI/README.md @@ -0,0 +1,16 @@ +# Welcome + +This is a video to audio converter created with python. The script extracts the audio from video files. + +# Requirments +- Install the following library +- Moviepy is a library that deals with video and audio files +```shell +pip install moviepy +``` +# How to use ? +- Just choose the file you want to extract audio from. +- Click convert and choose your save path. + +# Screenshots +![image](https://user-images.githubusercontent.com/62449903/112558472-85f76480-8dd7-11eb-90cd-c27903a9f551.png) From bbfbe4dceaf62bdc307c737ce7b2b6cbe34f6261 Mon Sep 17 00:00:00 2001 From: Amr Mohamed Zaki Date: Fri, 26 Mar 2021 02:23:11 +0200 Subject: [PATCH 3/5] Fixed pylint errors --- Video-Audio-Converter-GUI/converter.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Video-Audio-Converter-GUI/converter.py b/Video-Audio-Converter-GUI/converter.py index 7d462e59bf..07d6322d1c 100644 --- a/Video-Audio-Converter-GUI/converter.py +++ b/Video-Audio-Converter-GUI/converter.py @@ -1,5 +1,5 @@ from tkinter import * -from moviepy.editor import * +from moviepy.editor import VideoFileClip from tkinter import filedialog from tkinter import messagebox from tkinter import ttk @@ -33,26 +33,22 @@ def save_audio_file(): """ global audio_filepath, audio_file - - audio_filepath.set(filedialog.asksaveasfilename(defaultextension='.mp3', title="Select your audio file directory", filetypes=[ - ('MP3 File','*.mp3'), ('Wave File','*.wav')])) - + audio_filepath.set(filedialog.asksaveasfilename(defaultextension='.mp3', + title="Select your audio file directory", filetypes=[ + ('MP3 File','*.mp3'), ('Wave File','*.wav')])) try: audio_file = video_file.audio audio_file.write_audiofile(str(audio_filepath.get())) video_file.close() audio_file.close() messagebox.showinfo(message="File converted successfully") - except: - messagebox.showerror(message="File could not be converted", title="File Error") - + except AssertionError: + messagebox.showerror(message="File could not be converted", title="File Error") # Resetting the video and audio paths video_filepath.set('') audio_filepath.set('') - - # Intializing main program settings main_prog = Tk() main_prog.title("Video to Audio Converter") From 0c530337c67b4a5d12ee26c9c3aac2cb7eb38d96 Mon Sep 17 00:00:00 2001 From: Amr Mohamed Zaki Date: Fri, 26 Mar 2021 15:33:51 +0200 Subject: [PATCH 4/5] Added loading bar --- Video-Audio-Converter-GUI/README.md | 2 +- Video-Audio-Converter-GUI/converter.py | 35 ++++++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Video-Audio-Converter-GUI/README.md b/Video-Audio-Converter-GUI/README.md index 0edeeeeaed..1e755e68f2 100644 --- a/Video-Audio-Converter-GUI/README.md +++ b/Video-Audio-Converter-GUI/README.md @@ -1,4 +1,4 @@ -# Welcome +# Video to Audio Converter with GUI This is a video to audio converter created with python. The script extracts the audio from video files. diff --git a/Video-Audio-Converter-GUI/converter.py b/Video-Audio-Converter-GUI/converter.py index 07d6322d1c..47ff4803a3 100644 --- a/Video-Audio-Converter-GUI/converter.py +++ b/Video-Audio-Converter-GUI/converter.py @@ -1,15 +1,17 @@ from tkinter import * from moviepy.editor import VideoFileClip +from moviepy.editor import AudioFileClip from tkinter import filedialog from tkinter import messagebox from tkinter import ttk - +import threading # Variables for video and audio files video_file = '' audio_file = '' + def get_video_file(): """ Function that gets the video file that needs to be converted @@ -25,29 +27,46 @@ def get_video_file(): ('MPEG-2','*.mpg *.mpeg *.m2v')])) video_file = VideoFileClip(str(video_filepath.get())) - + + def save_audio_file(): """ Function that converts video file into audio file in a path that the user chooses """ - global audio_filepath, audio_file + global audio_filepath, audio_file, progress_bar audio_filepath.set(filedialog.asksaveasfilename(defaultextension='.mp3', title="Select your audio file directory", filetypes=[ - ('MP3 File','*.mp3'), ('Wave File','*.wav')])) + ('MP3 File','*.mp3'), ('Wave File','*.wav')])) try: audio_file = video_file.audio audio_file.write_audiofile(str(audio_filepath.get())) video_file.close() audio_file.close() messagebox.showinfo(message="File converted successfully") - except AssertionError: - messagebox.showerror(message="File could not be converted", title="File Error") + except: + messagebox.showerror(message="File could not be converted", title="File Error") + # Resetting the video and audio paths video_filepath.set('') audio_filepath.set('') + + # Resetting the progressbar after function execution + progress_bar['value'] = 0 + progress_bar.stop() +def run_program(): + """ + Function that runs the process of conversion and loading bar concurrently + + """ + global progress_bar + t1 = threading.Thread(target=progress_bar.start) + t2 = threading.Thread(target=save_audio_file) + t2.start() + t1.start() + # Intializing main program settings main_prog = Tk() @@ -68,10 +87,12 @@ def save_audio_file(): # Labels and buttons of the program Label(UI_frame, text="Choose your video file", bg="ivory").grid(row=1, column=1, padx=5, pady=5, sticky=W) Button(UI_frame, text="Browse", command=get_video_file, bg="grey").grid(row=1, column=2, padx=5, pady=5) -Button(UI_frame, text="Convert", command=save_audio_file, bg="green").grid(row=2, column=2, padx=5, pady=5) +Button(UI_frame, text="Convert", command=run_program, bg="green").grid(row=2, column=2, padx=5, pady=5) Label(UI_frame, textvariable=video_filepath, bg="ivory").grid(row=1, column=3, padx=5, pady=5, sticky=W) +progress_bar = ttk.Progressbar(main_prog, orient=HORIZONTAL, mode='indeterminate', length=500) +progress_bar.grid(padx=25,pady=25) # Calling main program main_prog.mainloop() From 6aa80ea6a486634612fc4ff2c47c94616698501b Mon Sep 17 00:00:00 2001 From: Amr Mohamed Zaki Date: Sat, 27 Mar 2021 14:06:38 +0200 Subject: [PATCH 5/5] Removed whitespaces --- Video-Audio-Converter-GUI/converter.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Video-Audio-Converter-GUI/converter.py b/Video-Audio-Converter-GUI/converter.py index 47ff4803a3..76882fcf25 100644 --- a/Video-Audio-Converter-GUI/converter.py +++ b/Video-Audio-Converter-GUI/converter.py @@ -16,8 +16,7 @@ def get_video_file(): """ Function that gets the video file that needs to be converted """ - global video_filepath, video_file - + global video_filepath, video_file video_filepath.set(filedialog.askopenfilename(title="Select your video file", filetypes=[ ('MP4 (mp4, m4a, m4v, f4v, f4a, m4b, m4r, f4b, mov)','*.mp4 *.m4a *.m4v *.f4v *.f4a *.m4b *.m4r *.f4b *.mov'), ('3GP (3gp, 3gp2, 3g2, 3gpp, 3gpp2)','*.3gp *.3gp2 *.3g2 *.3gpp *.3gpp2'), @@ -26,17 +25,13 @@ def get_video_file(): ('FLV','*.flv'), ('AVI','*.avi'), ('MPEG-1 (mpg, mp2, mpeg, mpe, mpv )','*.mpg *.mp2 *.mpeg *.mpe *.mpv'), ('MPEG-2','*.mpg *.mpeg *.m2v')])) video_file = VideoFileClip(str(video_filepath.get())) - - - def save_audio_file(): """ Function that converts video file into audio file in a path that the user chooses - """ global audio_filepath, audio_file, progress_bar - audio_filepath.set(filedialog.asksaveasfilename(defaultextension='.mp3', + audio_filepath.set(filedialog.asksaveasfilename(defaultextension='.mp3', title="Select your audio file directory", filetypes=[ ('MP3 File','*.mp3'), ('Wave File','*.wav')])) try: @@ -47,11 +42,9 @@ def save_audio_file(): messagebox.showinfo(message="File converted successfully") except: messagebox.showerror(message="File could not be converted", title="File Error") - # Resetting the video and audio paths video_filepath.set('') audio_filepath.set('') - # Resetting the progressbar after function execution progress_bar['value'] = 0 progress_bar.stop() @@ -59,14 +52,12 @@ def save_audio_file(): def run_program(): """ Function that runs the process of conversion and loading bar concurrently - """ global progress_bar t1 = threading.Thread(target=progress_bar.start) t2 = threading.Thread(target=save_audio_file) t2.start() t1.start() - # Intializing main program settings main_prog = Tk()