News:

--

Main Menu

How_To_Batch_File_Proccessing?

Started by pulsarstar, April 14, 2021, 08:57:30 AM

Previous topic - Next topic

pulsarstar

Thanks You, butterw for the info:
I will take a look at your links tomorrow.

eumagga0x2a

I'd like to add that internal Python-like scripting in Avidemux should not be mixed up with external batch / shell scripting. They serve different purposes (e.g. you cannot create directories or arbitrary files or call other executables when using the internal scripting while the external scripting won't give you detailed access to the configuration of Avidemux), but very often you would need (or want) to use both.

pulsarstar

Thank you eumagga0x2a.
That info was helpful.
As this will be a regular program I shall use,
I see I have a learning curve in front of me. ;D
 

butterw

When you load a new file (with default preference setting, "reset_encoder_on_video_load" : false):
- encoder and output container options are not reset.
- markers and filters are reset.

1) setup the output settings in the gui then save the .py project.
2) Modify the script to process all files in a folder:
- get a list of input filepaths.
for each filepath_in:
- adm.load(filepath_in)
- apply filters to the file
- adm.save(filepath_out) #overwrites existing files

pulsarstar

Thank You, butterw for the advice.

chucknolan

Quote from: eumagga0x2a on April 17, 2021, 01:11:59 PM
Quote from: pulsarstar on April 14, 2021, 03:24:13 PMI hope in future update versions of Avidemux the R & D Department include batch file processing in the GUI options.

You can queue tasks for later batch processing using Avidemux Jobs GUI, but the R & D Department doesn't think that inflating GUI is the way to go.

For your task, you could use the following untested script (copy and paste it into the Avidemux script console or save as a .py file and pass to the executable on the command line as the argument of the --run option:

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,out):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    adm.videoCodec("Copy")
    if adm.audioTracksCount() > 0:
        adm.audioClearTracks()
        adm.audioAddTrack(0)
        adm.audioCodec(0, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
        adm.audioSetDrc(0, 0)
        adm.audioSetShift(0, 0, 0)
        adm.audioSetNormalize2(0, 2, 120, -30)
    adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")

    filename = (splitext(filein))[0]
    filename += ".mkv"
    filename = basename(filename)
    return adm.save(out + sep + filename)
#
# Main
#
# -------- select extension --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mx = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mx):
    menuExt.addItem(extensions[entry])
dia = DialogFactory("Filter directory content")
dia.addControl(menuExt)
if not dia.show():
    return

idx = menuExt.index

if idx < 0 or idx >= mx:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idx]

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Oops", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Oops", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

The script processes all files with given extension in a directory.

I will like to say that your python batch script is THE BEST THAT I HAVE EVER USED compared to the DasTactic method located on the avidemux website. Moreover, I have created some of my own python scripts using DasTactic as a template, but with yours, I managed to cut back A LOT of filler concerning the creation of multiple/individual batch scripts for various extension inputs such as a script for mkv to mp4, mkv to mkv, ts to mp4, etc.  However, with yours, in one SINGLE script file, I have the ability of choosing from multiple inputs (mkv, ts, mp4, avi, etc) to output (mkv).  Therefore, I wanted to ask you a question in regards to creating a script for me, if you don't mind?

I have no intensions of converting the video. Only audio conversion. Therefore, the video will be just "Copy."

On the same script, is it possible, just like you had with the script you wrote for pulsarstar, to have multiple INPUT extensions, and as well as multiple OUTPUT extension options?  For example, let's say that my file input choice from the list/menu is ".ts," and I wanted the output extension options to be available for "mkv," "mp4," "mov" with the "mkv" audio being 56 kbps FDK-AAC (HE-AAC); "mp4" audio 128 kbps FDK-AAC (LC-AAC); "mov" audio 192 kbps FDK-AAC (LC-AAC).

The script that I hope that you can create for me, assuming it's possible, is the ability of having the option to choose from a list/menu of INPUTS (mkv, mp4, ts, avi, etc) to a list/menu of OUTPUTS (mkv, mp4, mov), in which I am aware that each output extension has to have their own individual profiles.  Apologies, if my wording is confusing.

eumagga0x2a

Quote from: chucknolan on April 25, 2021, 08:19:40 PMI wanted the output extension options to be available for "mkv," "mp4," "mov" with the "mkv" audio being 56 kbps FDK-AAC (HE-AAC); "mp4" audio 128 kbps FDK-AAC (LC-AAC); "mov" audio 192 kbps FDK-AAC (LC-AAC).

Assuming that you don't need to filter audio, the script below should do it:

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, HE-AAC @ 56 kbps (FDK-AAC)","MP4, AAC LC @ 128 kbps (FDK-AAC)","MOV, AAC LC @ 192 kbps (FDK-AAC)"]
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    adm.videoCodec("Copy")
    if adm.audioTracksCount() > 0:
        adm.audioClearTracks()
        adm.audioAddTrack(0)
        if outidx == 0:
            adm.audioCodec(0, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
        elif outidx == 1:
            adm.audioCodec(0, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
        elif outidx == 2:
            adm.audioCodec(0, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
        else:
            ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
            return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

mxOut = len(outputs)

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

dia = DialogFactory("Configuration")
dia.addControl(menuExt)
dia.addControl(menuOut)
if not dia.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

pulsarstar

Thanks for your input chucknolan.
I have saved your script to my script folder.
I found your question to eumagga0x2a a good read,
and also the script he gave you in response was very good.
I saved that for later use.
Thanks go to eumagga0x2a for the script!

chucknolan

Quote from: eumagga0x2a on April 25, 2021, 11:55:33 PM
Quote from: chucknolan on April 25, 2021, 08:19:40 PMI wanted the output extension options to be available for "mkv," "mp4," "mov" with the "mkv" audio being 56 kbps FDK-AAC (HE-AAC); "mp4" audio 128 kbps FDK-AAC (LC-AAC); "mov" audio 192 kbps FDK-AAC (LC-AAC).

Assuming that you don't need to filter audio, the script below should do it:

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, HE-AAC @ 56 kbps (FDK-AAC)","MP4, AAC LC @ 128 kbps (FDK-AAC)","MOV, AAC LC @ 192 kbps (FDK-AAC)"]
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    adm.videoCodec("Copy")
    if adm.audioTracksCount() > 0:
        adm.audioClearTracks()
        adm.audioAddTrack(0)
        if outidx == 0:
            adm.audioCodec(0, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
        elif outidx == 1:
            adm.audioCodec(0, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
        elif outidx == 2:
            adm.audioCodec(0, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
        else:
            ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
            return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

mxOut = len(outputs)

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

dia = DialogFactory("Configuration")
dia.addControl(menuExt)
dia.addControl(menuOut)
if not dia.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

First off, sir, you're amazing.  THANK YOU.  Unfortunately, the mkv output preset didn't work, but I addressed it by removing the option for the output folder.  Nonetheless, what tutorial or manual did you use to write these scripts because they are incredible, and, by using your template as a backbone, I set the audio filters to my liking and altered the renaming output files according to output preset?

I do, however, have 2 more questions, if you don't mind:

1) For COPY of audio and video, how may I create a python script that will accommodate files with multiple audio tracks because I have to keep creating different profiles for 1 track, 2 tracks, 3 tracks, & 4 tracks for my DBZ anime collection?  I mean is there a variable that I can utilize to do so. Example below:

    adm.videoCodec("Copy")
    if adm.audioTracksCount() > 0:
        adm.audioClearTracks()
        if outidx == 0:
            adm.setSourceTrackLanguage(0,"eng")
            adm.audioAddTrack(0)
            adm.audioCodec(0, "copy")
        elif outidx == 1:
            adm.setSourceTrackLanguage(0,"eng")
            adm.setSourceTrackLanguage(1,"jpn")
            adm.audioAddTrack(0)
            adm.audioAddTrack(1)
            adm.audioCodec(0, "copy")
            adm.audioCodec(1, "copy")
        elif outidx == 2:
            adm.setSourceTrackLanguage(0,"eng")
            adm.setSourceTrackLanguage(1,"jpn")
            adm.setSourceTrackLanguage(2,"spa")
            adm.audioAddTrack(0)
            adm.audioAddTrack(1)
            adm.audioAddTrack(2)
            adm.audioCodec(0, "copy")
            adm.audioCodec(1, "copy")
            adm.audioCodec(2, "copy")


2) Not sure if it's possible, but is there a way for me to choose a specific file apply an "output preset?" Not sure if I'm framing the question correctly.  Therefore, I will try a scenario approach.  For example, if I was batching 8 mkv files to output mkv, but forgot one file, how can I select that SPECIFIC file and apply the preset without having to create a random folder, place that one file, and apply the python script?  Is there something that I have to do BELOW that will allow access to view BOTH FILES and FOLDERS, instead of just the folders?

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

NONETHELESS, THANK YOU AGAIN. YOU ARE TRULY A Lifesaver
 

chucknolan

Quote from: pulsarstar on April 26, 2021, 07:20:16 AMThanks for your input chucknolan.
I have saved your script to my script folder.
I found your question to eumagga0x2a a good read,
and also the script he gave you in response was very good.
I saved that for later use.
Thanks go to eumagga0x2a for the script!

No, I should be thanking you because I wasn't aware that this forum would be this helpful.  I performed the batching from DasTactic youtube video, but it pales in comparison to eumagga0x2a's.  Therefore, thank you for posing the question. Whomever eumagga0x2a is, thank you.

eumagga0x2a

Quote from: chucknolan on April 26, 2021, 08:46:13 PMUnfortunately, the mkv output preset didn't work

Could you please elaborate? It worked for me after I recompiled Avidemux against the proper fdk-aac library (should not be a concern on platforms other than Linux). Regarding MKV muxer configuration, everything I suggest is based on the latest git master, please make sure you use the latest nightly available.

I'll try to address other questions tomorrow.

chucknolan

Quote from: eumagga0x2a on April 26, 2021, 09:33:50 PM
Quote from: chucknolan on April 26, 2021, 08:46:13 PMUnfortunately, the mkv output preset didn't work

Could you please elaborate? It worked for me after I recompiled Avidemux against the proper fdk-aac library (should not be a concern on platforms other than Linux). Regarding MKV muxer configuration, everything I suggest is based on the latest git master, please make sure you use the latest nightly available.

I'll try to address other questions tomorrow.

My apologies.  I just tried it again, and it works. I received an error yesterday for some reason.  Moreover, thank you for taking the time to address my other questions.

eumagga0x2a

I'm sorry, everything slips by a day or two.

It turned out to be that Avidemux...

a) doesn't evaluate language metadata in MP4 files at all and...

b) fails to set language metadata in MOV files for many languages (more precisely for all languages with ISO-639-2/B codes different from their ISO-639-2 codes like "ger" vs "deu" for German).

I've fixed (well, copypasted the code from libavcodec) the first issue in my local code, not yet committed. Will try to fix the second one tomorrow.

eumagga0x2a

The bugs in MP4 demuxer and MOV muxer affecting language metadata are fixed now, the fixes will be in the next round of official nightly builds unless you build Avidemux from source yourself to get them instantly.

Regarding source files with multiple audio tracks, you can use

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, HE-AAC @ 56 kbps (FDK-AAC)","MP4, AAC LC @ 128 kbps (FDK-AAC)","MOV, AAC LC @ 192 kbps (FDK-AAC)"]
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    adm.videoCodec("Copy")
    nbTracks = adm.audioTracksCount()
    if nbTracks > 0:
        adm.audioClearTracks()
        for track in range(nbTracks):
            adm.audioAddTrack(track)
            if outidx == 0:
                adm.audioCodec(track, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
            elif outidx == 1:
                adm.audioCodec(track, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
            elif outidx == 2:
                adm.audioCodec(track, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
            else:
                ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
                return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

mxOut = len(outputs)

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

dia = DialogFactory("Configuration")
dia.addControl(menuExt)
dia.addControl(menuOut)
if not dia.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

to loop over the available audio tracks.

chucknolan

Quote from: eumagga0x2a on April 28, 2021, 08:54:41 PMThe bugs in MP4 demuxer and MOV muxer affecting language metadata are fixed now, the fixes will be in the next round of official nightly builds unless you build Avidemux from source yourself to get them instantly.

Regarding source files with multiple audio tracks, you can use

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, HE-AAC @ 56 kbps (FDK-AAC)","MP4, AAC LC @ 128 kbps (FDK-AAC)","MOV, AAC LC @ 192 kbps (FDK-AAC)"]
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    adm.videoCodec("Copy")
    nbTracks = adm.audioTracksCount()
    if nbTracks > 0:
        adm.audioClearTracks()
        for track in range(nbTracks):
            adm.audioAddTrack(track)
            if outidx == 0:
                adm.audioCodec(track, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
            elif outidx == 1:
                adm.audioCodec(track, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
            elif outidx == 2:
                adm.audioCodec(track, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
            else:
                ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
                return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

mxOut = len(outputs)

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

dia = DialogFactory("Configuration")
dia.addControl(menuExt)
dia.addControl(menuOut)
if not dia.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

to loop over the available audio tracks.

THANK YOU. I actually figured out the audio loop by playing around with the previous template when I changed "if adm.audioTracksCount() > 0" to "if adm.audioTracksCount() < 0".  However, the downside of doing so prevented the ability to assign language sets.  This latest one is amazing.

Can you create one more for me to complete my set of AviDemux conversions presets? I was wondering if you can use the previous template or the current template that you just uploaded yesterday and assign video conversions on them.  I just need 2 to 3 presets, and then I can work from there as I did for your past templates. Please see example below:

Video & Audio Preset/Profile #1:

adm.videoCodec("xvid4", "params=CQ=2", "profile=244", "rdMode=3", "motionEstimation=3", "cqmMode=0", "arMode=1", "maxBFrame=2", "maxKeyFrameInterval=200", "nbThreads=99", "qMin=2", "qMax=25", "rdOnBFrame=True", "hqAcPred=True"
, "optimizeChrome=True", "trellis=True", "useXvidFCC=True", "enableFrameDrop=False", "frameDropRatio=50")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
if adm.audioTotalTracksCount() <= 0:
    raise("Cannot add audio track 0, total tracks: " + str(adm.audioTotalTracksCount()))
adm.audioAddTrack(0)
adm.audioCodec(0, "FDK_AAC", "bitrate=160", "afterburner=False", "profile=2", "sbr=False")
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")


Video & Audio Preset/Profile #2:
adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.poolThreads=99", "general.frameThreads=99", "general.output_bit_depth=0", "general.preset=", "general.tuning=", "general.profile=", "level=-1"
, "vui.sar_idc=0", "vui.sar_height=1", "vui.sar_width=1", "vui.color_primaries=2", "vui.transfer_characteristics=2", "vui.matrix_coeffs=2", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40"
, "MaxBFrame=3", "i_bframe_adaptive=2", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "b_open_gop=False", "interlaced_mode=0", "constrained_intra=False", "b_intra=True", "lookahead=40"
, "weighted_pred=2", "weighted_bipred=True", "rect_inter=False", "amp_inter=False", "limit_modes=False", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "limit_refs=3"
, "rd_level=3", "psy_rd=1.000000", "rdoq_level=0", "psy_rdoq=0.000000", "fast_pskip=True", "dct_decimate=True", "noise_reduction_intra=0", "noise_reduction_inter=0", "strong_intra_smoothing=True", "ratecontrol.rc_method=0"
, "ratecontrol.qp_constant=0", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1", "ratecontrol.ip_factor=1.400000"
, "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=2", "ratecontrol.aq_strength=1.000000", "ratecontrol.cu_tree=True", "ratecontrol.strict_cbr=False")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
if adm.audioTotalTracksCount() <= 0:
    raise("Cannot add audio track 0, total tracks: " + str(adm.audioTotalTracksCount()))
adm.audioAddTrack(0)
adm.audioCodec(0, "FDK_AAC", "bitrate=56", "afterburner=False", "profile=5", "sbr=False")
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")


Thank you!