News:

--

Main Menu

Batch Script but need to change save location

Started by cxxm00, January 02, 2026, 04:17:25 PM

Previous topic - Next topic

cxxm00

Working script, but I need to change the output location to a different folder other than the input folder (c:\tmp).

Since it will be saved to a different folder, I want to use the same filename that is being loaded (like in this one), but without the ".edit.mp4"


ext="mp4"
inputFolder="c:\\tmp\\"
#
def convert(filein):
    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    adm.videoCodec("Copy")
    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, "Lame")
    adm.audioSetDrc(0, 1)
    adm.audioSetShift(0, 0, 0)
    adm.audioSetNormalize2(0, 2, 150, -30)
    adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
    adm.save(filein+".edit.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")


eumagga0x2a

Usually, inconsistent indentation in Python should not work, at least, one should not use it ;-)

What is the purpose of encoding the audio track with LAME in default configuration to MP3 when better codecs (AAC) are available?

Is throwing an exception on encountering a file without an audio track while ignoring a possible failure of save() deliberate or just a blind copy from other people's old scripts?

Anyway, you could use something like

# -------- 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

To strip directory from filein, use

filein = basename(filein)
and pass outputFolder + "\\" + filein as argument to save().