Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # filename :: video converter using Python ( Based Upon FFMPEG Library )
- print "##"*35
- print "Video Converter Build using Python and FFMPEG library.."
- import os
- import sys
- import tempfile
- import glob
- import subprocess
- import Tkinter as tk
- cwd = '' # Input file to convert
- cwd21a = '' # Output file to Convert
- vlist = set() # Used to create a playlist for converting multiple files simultaneously
- format = '' # file format or extension to which you want to convert
- duration = ''
- size_of_video = ''
- frame_per_sec = ''
- z = 0
- ffmpeg_command = ''
- def tk_gui():
- root = tk.Tk()
- #root.wm_geometry(newGeometry='250x250+10+10')
- root.wm_title("Ffconverter ( Video Converter )")
- # Container Number 1
- myContainer1 = tk.Frame(root)
- myContainer1.pack()
- myLabel1 = tk.Label(myContainer1)
- myLabel1.configure(text=" Select File To Convert :: ", background="yellow")
- myLabel1.pack(side=tk.LEFT)
- entry1 = tk.Entry(myContainer1)
- entry1.configure(width=100)
- entry1.pack(side=tk.LEFT)
- def select_file():
- """
- this code block is used to play a single video file,
- this video file will be added to vlist playlist
- """
- global cwd, vlist
- print "Opening Video File :-)\n\n"
- openfilename = tkFileDialog.askopenfilename()
- cwd = openfilename
- print "You Have Select :: ", cwd
- entry1.insert(0, cwd)
- root.update()
- button1 = tk.Button(myContainer1)
- button1.configure(text="Select", background="green", command=select_file)
- button1.pack(side=tk.LEFT)
- ## Container Number 3
- myContainer3 = tk.Frame(root)
- myContainer3.pack()
- myLabel3 = tk.Label(myContainer3)
- myLabel3.configure(text="Enter Format Name to Convert ::", background="yellow")
- myLabel3.pack(side=tk.LEFT)
- entry3 = tk.Entry(myContainer3)
- entry3.configure(width=20)
- entry3.pack(side=tk.LEFT)
- def get_format():
- global format
- format = tk.StringVar()
- print "Retrieving File Format.."
- entry3.index(0)
- format = entry3.get()
- print "You want to Convert to :: ", format
- print "##"*40, "\n"
- button3 = tk.Button(myContainer3)
- button3.configure(text="OK ", background="cyan", command=get_format)
- button3.pack(side=tk.LEFT)
- ##
- myLabel5 = tk.Label(myContainer3)
- myLabel5.configure(text="Duration, Frame Size, Frame Rate ", background="yellow")
- myLabel5.pack(side=tk.LEFT)
- entry4 = tk.Entry(myContainer3)
- entry4.configure(width=50)
- entry4.pack(side=tk.LEFT)
- def get_size():
- global cwd, duration, size_of_video, frame_per_sec
- print "Checking for Oroginal Size of Video File.."
- filename = cwd
- result = subprocess.Popen(["ffprobe.exe", filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- duration0 = [x for x in result.stdout.readlines() if "Duration" in x]
- duration = duration0[0].split()[1]
- result = subprocess.Popen(["ffprobe.exe", filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- size_of_video0 = [x for x in result.stdout.readlines() if "Video:" in x]
- size_of_video1 = size_of_video0[0].split()
- for i in size_of_video1:
- if "x" in i:
- size_of_video = i
- frame_per_sec0 = size_of_video0[0].split()
- print frame_per_sec0
- frame_per_sec1 = frame_per_sec0.index("fps,")
- frame_per_sec = frame_per_sec0[frame_per_sec1 - 1]
- print "\n", "##"*35
- print "Duration of Video File :: ", duration
- print "Size of Video Frame :: ", size_of_video
- print "Frame Rate of Video :: ", frame_per_sec
- print "\n", "##"*35, "\n"
- contents = duration + " " + size_of_video + " " +frame_per_sec
- entry4.insert(0, contents)
- button5 = tk.Button(myContainer3)
- button5.configure(text="OK ", background="cyan", command=get_size)
- button5.pack(side=tk.LEFT)
- ## Conatiner Number 2
- myContainer2 = tk.Frame(root)
- myContainer2.pack()
- myLabel2 = tk.Label(myContainer2)
- myLabel2.configure(text=" File Converted to :: ", background="yellow")
- myLabel2.pack(side=tk.LEFT)
- entry2 = tk.Entry(myContainer2)
- entry2.configure(width=100)
- entry2.pack(side=tk.LEFT)
- def Converted_file():
- global cwd, vlist, format, cwd21a
- cwd1 = os.path.split(cwd)[0]
- cwd2 = os.path.split(cwd)[1]
- cwd21 = cwd2[:-4]
- cwd21a = cwd1 + cwd21 + "__converted__." + str(format)
- print "File will be Converted to :: ", cwd21a
- entry2.index(0)
- entry2.insert(0, cwd21a)
- text1.index(1.0)
- ffmpeg_command_1 = "ffmpeg.exe" + " -i" + " \""+str(cwd)+"\"" + " \""+str(cwd21a)+"\""+"\n"
- text1.insert(1.0, ffmpeg_command_1)
- button2 = tk.Button(myContainer2)
- button2.configure(text="Save ", background="green", command=Converted_file)
- button2.pack(side=tk.LEFT)
- button7 = tk.Button(myContainer2)
- def clear_entry():
- entry1.delete(0, tk.END)
- entry2.delete(0, tk.END)
- entry3.delete(0, tk.END)
- entry4.delete(0, tk.END)
- button7.configure(text="Clear ", background="red", command=clear_entry)
- button7.pack(side=tk.LEFT)
- ## Container Number 4
- myContainer4 = tk.Frame(root)
- myContainer4.pack()
- #myLabel4 = tk.Label(myContainer4)
- #myLabel4.configure(text="Run Custom FFMPEG Commands", background="red")
- #myLabel4.pack(side=tk.LEFT)
- text1 = tk.Text(myContainer4)
- text1.configure(width=100)
- text1.pack(side=tk.LEFT)
- def get_ffmpeg_command():
- global format, cwd, cwd21a, z, ffmpeg_command
- format = tk.StringVar()
- print "Retrieving File Format.."
- text1.index(1.0)
- #z = 0
- try:
- start = str(z+1)+"."+str(0)
- end = str(z+1)+"."+str("end")
- try:
- if len(text1.get(start, end)) == 0:
- #break
- print "There is No Custom FFMPEG Commands Exists in This Line..!!"
- print "Value of video Index Number z == ", z
- pass
- else:
- z += 1
- ffmpeg_command = text1.get(start, end) # one FFMPEG command must be without a new line character
- print "\n", "@#"*35
- print "You want to run This FFMPEG Command >> \n", ffmpeg_command
- print "\n", "@#"*35
- print "\n\n"
- os.system(ffmpeg_command)
- #p1 = subprocess.Popen([ffmpeg_command])
- except:
- print "No More FFMPEG Custom Commands Found In Text Box.."
- pass
- except:
- print "Error While Running Custom FFMPEG codes.."
- z += 1
- pass
- button4 = tk.Button(myContainer4)
- button4.configure(text="Run Custom FFMPEG Command", background="cyan", command=get_ffmpeg_command)
- button4.pack()
- button5 = tk.Button(myContainer4)
- def ffmpeg_manual():
- print "Opening FFMPEG Manual .."
- try:
- subprocess.Popen(["notepad.exe", "source\\ffmpeg.help.txt"])
- except:
- print "FFMPEG Manual Not Exists.."
- pass
- button5.configure(text=" Help? ", background="green", command=ffmpeg_manual)
- button5.pack()
- button6 = tk.Button(myContainer4)
- def ffmpeg_examples():
- print "Opening FFMPEG Examples .."
- try:
- subprocess.Popen(["notepad.exe", "source\\ffmpeg.examples.txt"])
- except:
- print "FFMPEG Manual Not Exists.."
- pass
- button6.configure(text="Examples", background="green", command=ffmpeg_examples)
- button6.pack()
- ##
- tk_gui()
- while True:
- try:
- exec(raw_input(":: "))
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement