Skeleton for batch processing

Here is a simple tinypy script that will load all files with a mp4 extension in a folder.

#
# Load all the files in c:\tmp with .mp4 extension.
# That's it.
#
ext="mp4"
inputFolder="c:\\tmp\\"
#
def convert(filein):   
    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    print("Done")
    
#
# Main
#
ui=Gui()
adm=Avidemux()
#
list=get_folder_content(inputFolder,ext)
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")

The first part is the initialization. We set the input folder (beware, on windows the \ must be put twice, so c:\tmp\ becomes c:\\tmp\\) and extension '.mp4' here. Ending the path with a '\\' is a good idea.

ext="mp4"
inputFolder="c:\\tmp\\"

The we create the object that enables tinypy to interact with avidemux

ui=Gui()
adm=Avidemux()

All avidemux commands will be performed on the 'adm' object. Next, get the list of files with the given extension and call the 'convert' function for all of them

list=get_folder_content(inputFolder,ext)
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")

You'll note that “list” is the list of files with full path to them, i.e. c:\\tmp\\foobar.mp4

def convert(filein):   
  if(0 == adm.loadVideo(filein)):
      ui.displayError("oops","cannot load "+filein)
      raise
  print("Done")

That's where everything happens. For this simple example, we just load the file, and raise an error if we cannot.

If you try this script, it will load all files ending with mp4 from the c:\\tmp
folder.

Using the skeleton