Hello and welcome back, if you have already read the previous article about the creation of the video resizing application then this one is the improved version. In this revised version, I have included a combo box where the user can select the new size of the video which needs to be resized. The new sizes of the video in the combo box are as follow, the aspect ratio of that original video will remain unchanged after it has been resized.
| 1920×1080 | 1080p |
| 1280×720 | 720p |
| 854×480 | 480p |
| 640×360 | 360p |
If you have not yet read the old version of the project then you can do so through this link. The revise program is as follow.
from tkinter import *
from tkinter import filedialog
import os
import subprocess
import tkinter.ttk as tk
win = Tk() # Create instance
win.title("Manipulate Video") # Add a title
win.resizable(0, 0) # Disable resizing the GUI
win.configure(background='white') # change background color
# Create a label
aLabel = Label(win, text="Select video size and video", anchor="center", padx=13, pady=10, relief=RAISED)
aLabel.grid(column=0, row=0, sticky=W+E)
aLabel.configure(foreground="black")
aLabel.configure(background="white")
aLabel.configure(wraplength=110)
# Create a combo box
vid_size = StringVar() # create a string variable
preferSize = tk.Combobox(win, textvariable=vid_size)
preferSize['values'] = (1920, 1280, 854, 640) # video width in pixels
preferSize.grid(column=0, row=1) # the position of combo box
preferSize.current(0) # select item one
# Open a video file
def openVideo():
fullfilename = filedialog.askopenfilename(initialdir="/", title="Select a file", filetypes=[("Video file", "*.mp4; *.avi ")]) # select a video file from the hard drive
if(fullfilename != ''):
scale_vid = preferSize.get() # retrieve value in the comno box
new_size = str(scale_vid)
dir_path = os.path.dirname(os.path.realpath(fullfilename))
os.chdir(dir_path)
f = new_size + '.mp4' # the new output file name and format
subprocess.call(['ffmpeg', '-i', fullfilename, '-vf', 'scale=' + new_size + ':-1', f]) # resizing the video with ffmpeg
action_vid = Button(win, text="Open Video", command=openVideo, padx=2)
action_vid.grid(column=0, row=2, sticky=E+W)
action_vid.configure(background='black')
action_vid.configure(foreground='white')
win.mainloop()
Nothing much has changed from the previous example except now the user will be able to select the desired size of the resized video. The ffmpeg tool allows us to use -1 as the new height argument for the new video which will then get resized as according to its width to height aspect ratio. We will continue to develop this video editing application so if you like this topic then do visit this site every day to look for a new post or you can click on the red bell button to subscribe to the new post notification message.
from Planet Python
via read more
No comments:
Post a Comment