User Tools

Site Tools


tinypy:tinypybatch2

This is an old revision of the document!


Batch Processing 2

The first step is to process one file manually and save the corresponding tinypy project.

A typical file would look like this :

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.loadVideo("/work/samples/avi/3mn.avi")
adm.clearSegments()
adm.addSegment(0, 0, 109025495)
adm.markerA = 0
adm.markerB = 109025495
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.threads=99",     "general.preset=", "general.tuning=", "general.profile=", "general.fast_decode=False",\
 "general.zero_latency=False", "general.fast_first_pass=True" \
, "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=-1", \
...
...
"ratecontrol.lookahead=40")
adm.addVideoFilter("swscale", "width=1280", "height=960", "algo=2", "sourceAR=1", "targetAR=1")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"unknown")
adm.audioAddTrack(0)
adm.audioCodec(0, "Faac");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True")

We'll remove the beginning where we load the file and set the markers to only keep the settings part. It becomes :

adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.threads=99",     "general.preset=", "general.tuning=", "general.profile=", "general.fast_decode=False",\
 "general.zero_latency=False", "general.fast_first_pass=True" \
, "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=-1", \
...
...
"ratecontrol.lookahead=40")
adm.addVideoFilter("swscale", "width=1280", "height=960", "algo=2", "sourceAR=1", "targetAR=1")
adm.audioCodec(0, "Faac");
adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True")

We'll reinject that part in the convert function we defined in the skeleton. It is now :

#
# 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
    # manual file insert
    adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=20",\
     "general.threads=99",     "general.preset=", "general.tuning=", "general.profile=",\
     "general.fast_decode=False",\
     "general.zero_latency=False", "general.fast_first_pass=True", \
     "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=-1", \
     ...
     ...
     "ratecontrol.lookahead=40")
    adm.addVideoFilter("swscale", "width=1280", "height=960", "algo=2", "sourceAR=1", "targetAR=1")
    adm.audioCodec(0, "Faac");
    adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True")
    # manual insert end
    adm.save(filein+".converted.mp4")
    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")

A couple of pitfalls :

  • The script is invalid, the x264 configuration line has been truncated. You must put a complete and valid line.
  • Dont forget that a line cannot exceed 200 chars, split it and add “\” at the end of each split line.
tinypy/tinypybatch2.1466403487.txt.gz · Last modified: 2016/06/20 08:18 by mean