Go To https://sourceforge.net/projects/ffplayer-and-converter/
## For Binary Download
## fastest Video player Build Using Python and Tkinter and FFMPEG + FFPLAY
#FFplayer Python code
###@ http://pastebin.com/RGqeup3A
## FFconverter Python Code
## For Binary Download
## fastest Video player Build Using Python and Tkinter and FFMPEG + FFPLAY
#FFplayer Python code
###@ http://pastebin.com/RGqeup3A
#!/usr/bin/env python
# file name = ffplayer ( build using ffmpeg multimedia library )
# developer :: Shishtpal
import os, glob, shutil, sys, tempfile, subprocess, ctypes, time
import Tkinter as tk
import tkFileDialog
vlist = set()
index_no = 0
# < Program Code #10001@ >
# Code Block used to add files to vlist, that we use as an argument with this script.
try:
        if len(sys.argv) == 1:
                cwd = ''
        else:
                cwd = sys.argv[1:]
        for i in cwd:
                print i
                vlist.add(i)
        print "\n\n"
except:
        print "Error in Program Code #10001@"
def tk_gui():
        global root, cwd
        global  index_no
        root = tk.Tk()
        root.wm_geometry(newGeometry='250x0+10+10')   
        root.wm_title("Ffplayer ( Video Player )")
        menubar = tk.Menu(root)
        root.config(menu=menubar)
        # Creating a menu button
        filemenu1 = tk.Menu(menubar)
        filemenu2 = tk.Menu(menubar)
        filemenu3 = tk.Menu(menubar)
        menubar.add_cascade(label='Player', menu=filemenu1)
        menubar.add_cascade(label='Control', menu=filemenu2)
        menubar.add_cascade(label='Help', menu=filemenu3)
        def button1Click():     
                """
                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(title="Select Video/Mp3 File..", initialdir="C:\\")
                cwd = openfilename
                vlist.add(cwd)
                vid_player(cwd)
        def button2Click():
                """
                this code block is used to open a window dialog box asked you to select
                a folder and filter all video files in your defined location,
                and add all of them to your vlist
                """
                global cwd
                print "Open a folder with Video File :-)\n\n"
                openfoldername = tkFileDialog.askdirectory()
                b = openfoldername.split("/")
                cwd = ''
                for i in range(len(b)):
                        cwd = cwd + "\\" + b[i]
                cwd = cwd[1:]
                print cwd
                vid_player(cwd)
                play_video()
        """                     
        def button3Click():
                print "Open Settings Panel :-)\n\n\n"
                #p1 = subproecess.call([])
        """
        def button4Click():
                print "Bye Bye!!"
                sys.exit()
        # create action for button 'Quit'
        filemenu1.add_command(label='Open File (o)', command=button1Click)
        filemenu1.add_command(label='Open Folder (f)', command=button2Click)
        #filemenu1.add_command(label='Settings', command=button3Click)  
        filemenu1.add_separator()
        filemenu1.add_command(label='Quit (q)', command=button4Click) # bind a event using command method
        #
        root.bind("<o>", lambda e: button1Click()) # bind a shortcut using lambda method
        root.bind("<O>", lambda e: button1Click())
        root.bind("<f>", lambda e: button2Click())
        root.bind("<F>", lambda e: button2Click())
        root.bind("<Q>", lambda e: button4Click())
        root.bind("<q>", lambda e: button4Click())
        #
        def next_video():
                global p1
                try:
                        p1.kill()
                except:
                        print "\n\nThere is NO ffplay.exe subprocess Exists!!\n\n"
                play_video()
        def play_video():
                global index_no, p1
                print "\n", "##"*35
                print "vlist contents :: ", len(vlist)
                print "    # Current Video file Index Number Is :: ", index_no, "\n"
                if len(vlist) > 0:
                        try:
                                print "##"*35, "\n\n"
                                p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no]])
                        except:
                                pass
                else:
                        print "\n\nHello, There is no Video File in your PlayList !!!\n\n\n"
                if index_no <= len(vlist):
                        index_no += 1
        def read_manual():
                try:
                        subprocess.call(["notepad.exe", "source\\ffplay.help.txt"])
                except:
                        print "Manual for ffplay Not Exists!!!"
        def start_ffmpeg_web():
                root1 = tk.Tk()
                myContainer2 = tk.Frame(root1)
                myContainer2.pack()
                myLabel1 = tk.Label(myContainer2)
                myLabel1.configure(text="Go to http://trac.ffmpeg.org", background="yellow")
                myLabel1.pack()
                button1 = tk.Button(myContainer2)
                button1.configure(text="OK", background="green")
                button1.pack()
                root1.update()
                time.sleep(2)
                root1.destroy()
        def about_ffplayer():
                print "\n  FFPLAYER is a video player build using ffmpeg library..\n\t Build By ( Shishtpal )"
                root1 = tk.Tk()
                myContainer2 = tk.Frame(root1)
                myContainer2.pack()
                myLabel1 = tk.Label(myContainer2)
                myLabel1.configure(text="\n  FFPLAYER is a video player build using ffmpeg library..\n\t Build By ( Shishtpal )", background="cyan")
                myLabel1.pack()
                button1 = tk.Button(myContainer2)
                button1.configure(text="OK", background="green")
                button1.pack()
                root1.update()
                time.sleep(4)
                root1.destroy()
        def explore_video_folder():
                loop_player()
                global index_no, vlist, cwd, p1
                print "\n##"*10
                print "\n    ## After Exploring Video Folder I Found", len(vlist), "Files.."
                print "    # Current Video file Index Number Is :: ", index_no
                print "    # Your Working Directory is ::", cwd, "\n\n"
                if len(vlist) > 0:
                        index_no = 0
                        if p1.poll() == None:
                                p1.kill()
                        if True:
                                for i in range(len(vlist)):
                                        print "\n", "##"*35
                                        print "\n   #Playing Video File :: ", list(vlist)[index_no], "\n"
                                        p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no]])
                                        print "\n    # Current Video file Index Number Is :: ", index_no, "\n"
                                        print "\n", "##"*35
                                        index_no += 1
                                        p1.wait()
                        else:
                                pass
        def loop_video():
                global index_no, p1, vlist
                try:
                        if p1.poll() == None:
                                p1.kill()
                                print "\n", "##"*35
                                print "\n    # Current Video file Index Number Is :: ", index_no-1, "\n\n"
                                p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-1]])
                        elif len(vlist) == 1:
                                print "\n", "##"*35
                                print "\n    # Current Video file Index Number Is :: ", index_no, "\n\n"
                                p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no]])
                        else:
                                print "\n", "##"*35
                                print "\n    # Current Video file Index Number Is :: ", index_no-1, "\n\n"
                                p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-1]])
                except:
                        print "  # Error in loop_video Function. #"
        def previous_video():
                global index_no, p1, vlist
                if index_no > 1:
                        try:
                                if p1.poll() == None:
                                        p1.kill()
                                        p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-2]])
                                else:
                                        p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-2]])
                                print "\n    # Current Video file Index Number Is :: ", index_no-2, "\n"
                                print "##"*35, "\n"
                                if index_no != 0:
                                        index_no -= 1
                        except:
                                print "Error While playing Previous Video File.."
                else:
                        print "There is No Previous Video File Exists..."
                        index_no = 0
        root.bind("<m>", lambda e: play_video())
        root.bind("<M>", lambda e: play_video())
        root.bind("<n>", lambda e: next_video())
        root.bind("<N>", lambda e: next_video())
        root.bind("<k>", lambda e: previous_video())
        root.bind("<K>", lambda e: previous_video())
        root.bind("<l>", lambda e: loop_video())
        root.bind("<L>", lambda e: loop_video())
        filemenu2.add_command(label='Play Video (m)', command=play_video)
        filemenu2.add_command(label='Next Video (n)', command=next_video)
        filemenu2.add_command(label='Previous Video (k)', command=previous_video)
        filemenu2.add_command(label='Loop Video (l)', command=loop_video)
        filemenu2.add_separator()
        def print_playlist():
                print "\n", "@#"*30
                print "Play-list Contents :: ", "\n"
                for i, j  in enumerate(vlist, 1):
                        print i, j
                print "@#"*30, "\n"
        filemenu2.add_command(label='Print Playlist', command=print_playlist)
        def open_playlist_file():
                global vlist, index_no, p1
                print "Opening Play-list File :: "
                try:
                        openfilename = tkFileDialog.askopenfilename(filetypes=[("PLT", "*.plt" )], title="Select Your Playlist File..", initialdir="C:\\")
                        print "\n", "@#"*30
                        print "You Select :: \n(", openfilename, ") \n\tPlay-list File..", "\n"
                        y = open(openfilename)
                        while True:
                                a = y.readline()[:-1]
                                if len(a) == 0:
                                        break
                                else:
                                        vlist.add(a)
                        y.close()
                        print "\n", "@#"*30, "\n"
                except:
                        print "No Play-List has been Selected..\n"
        filemenu2.add_command(label='Open Playlist File', command=open_playlist_file)
        def write_playlist_file():
                global vlist
                print "\n", "**"*30
                print "We have Write your Current Play-List File To Disk.."
                print "ffplayer_current_playlist.plt", "\n"
                x = open("ffplayer_current_playlist.plt", "w")
                for i in vlist:
                        w = i+"\n"
                        x.write(w)
                x.close()
                print "**"*30, "\n"
        filemenu2.add_command(label='Write Playlist File', command=write_playlist_file)
        def custom_playlist():
                print "Customizing Play-list Contents :: "
        #filemenu2.add_command(label='Custom Playlist', command=custom_playlist)
        filemenu2.add_separator()
        filemenu2.add_command(label='Explore Video Folder', command=explore_video_folder)
        filemenu3.add_command(label='Manual', command=read_manual)
        filemenu3.add_command(label='About FFMPEG', command=start_ffmpeg_web)
        def ffmpeg_howto():
                try:
                        subprocess.Popen(["notepad.exe", "source\\ffmpeg.howto.txt"])
                except:
                        print "FFMPEG How To Documentation File Not Exists.."
        filemenu3.add_command(label='FFMPEG How TO ', command=ffmpeg_howto)     
        filemenu3.add_command(label='About ffplayer', command=about_ffplayer)
def screen_resolution():
        """
        this code block is used to get Screen resolution of your desktop Screen.        
        """
        global screensize
        user32 = ctypes.windll.user32
        screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
        print "Screen Resolution is :: ", screensize, "\n\n"
screen_resolution()
def vid_filter(filename):
        if os.path.isdir(filename) | filename.endswith(".jpg") | \
                filename.endswith(".png") | filename.endswith(".jpeg") | \
                filename.endswith(".JPG") | filename.endswith(".PNG") | \
                filename.endswith(".JPEG") | filename.endswith(".txt") | \
                filename.endswith(".tar.gz") | filename.endswith(".zip") | \
                filename.endswith(".7z") | filename.endswith(".exe") | \
                filename.endswith(".pdf") | filename.endswith(".htm") | \
                filename.endswith(".html") | filename.endswith(".mhtm") | \
                filename.endswith(".mhtml") | filename.endswith(".lnk") | \
                filename.endswith(".mht") | filename.endswith(".ini") | \
                filename.endswith(".db") | filename.endswith(".img") | \
                filename.endswith(".iso") | filename.endswith(".pkg") | \
                filename.endswith(".sh") | filename.endswith(".tgz") | \
                filename.endswith(".css") | filename.endswith(".gif") | \
                filename.endswith(".c4d") | filename.endswith(".xml") | \
                filename.endswith(".apk") | filename.endswith(".dat") | \
                filename.endswith(".doc") | filename.endswith(".docx") | \
                filename.endswith(".ppt") | filename.endswith(".pptx") | \
                filename.endswith(".xls") | filename.endswith(".xlsx") | \
                filename.endswith(".py") | filename.endswith(".pyw") | \
                filename.endswith(".pyc") | filename.endswith(".pyo") | \
                filename.endswith(".chm") | filename.endswith(".js")  | \
                filename.endswith(".gz") | filename.endswith(".cfg")  | \
                filename.endswith(".inf") | filename.endswith(".sys")  | \
                filename.endswith(".dll"):
                return True
def vid_player(cwd): 
        global p1, vlist
        if os.path.isfile(cwd):
                vlist.add(cwd)
                p1 = subprocess.Popen(["ffplay.exe", "-autoexit", cwd])
        elif os.path.isdir(cwd):
                for i in os.listdir(cwd):
                        try:
                                filename = os.path.join(cwd, i)
                                if vid_filter(filename):
                                        pass
                                else:
                                        vlist.add(filename)
                        except:
                                print "Error While Filtering File Formats..\n\t In vid_player Function..\n"
                                pass
        else:
                print "Hi, I Do not Know, what you Defined !!\n\t as a video file or a folder which contains video files..\n"
def loop_player():
        """
        This code Block create a list of each and every file recursively,
        But we have used a filter So that wrong File Formats will not be used with
        ffplayer, because this just gives you an error, 
        we can also use ffrpobe to know if supplied file is a video file, but this is just
        time consuming process, this would be great if you just use a filter.
        """
        global files, vlist, index_no, cwd
        files = []   
        for i in zip(os.walk(cwd)):
                files.append(i)
        for i in range(len(files)): 
                for j in files[i][0][2]:
                        try:
                                filename = os.path.join(files[i][0][0], str(j))
                                if vid_filter(filename):
                                        pass
                                else:
                                        vlist.add(filename)
                        except:
                                print "Error While Filtering File Formats !! In explore video folder Function !!"
                                pass
#
tk_gui()
root.mainloop()
## FFconverter Python Code
# 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
No comments:
Post a Comment