Avidemux Forum

Participate => Documentation & Tips => Topic started by: mosiclover on November 03, 2022, 01:41:18 AM

Title: Script error in Avidemux 2.8 - 2.7
Post by: mosiclover on November 03, 2022, 01:41:18 AM
Hello, I wrote a script to crop and resize all mp4 files in directory based on a eumagga0x2a mod script in a topic
as below:
#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("x264")
    adm.addVideoFilter("crop", "top=148", "bottom=300", "left=0", "right=0", "ar_select=0")
adm.addVideoFilter("swscale", "width=1080", "height=1080", "algo=1", "sourceAR=0", "targetAR=0", "lockAR=True", "roundup=0")

adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")


  filename = (splitext(filein))[0]
    filename += ".mp4"
    filename = basename(filename)
    return adm.save(out + sep + "OK" + filename)
#
# Main
#


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


ERROR:
 Invalid statement 22:  filename = (splitext(filein))[0]

PLEASE HELP!!!



Title: Re: Script error in Avidemux 2.8 - 2.7
Post by: eumagga0x2a on November 03, 2022, 08:32:08 AM
First of all, Python uses indentation for code nesting, so you may not deliberately modify indentation in the script, e.g. adm.addVideoFilter("swscale", and adm.setContainer etc. below must be indented by exactly the same number of spaces as the previous statement.

Regarding the error you get, you probably use an old version of Avidemux which doesn't support splitext method.
Title: Re: Script error in Avidemux 2.8 - 2.7
Post by: mosiclover on November 18, 2022, 12:42:00 PM
Quote from: eumagga0x2a on November 03, 2022, 08:32:08 AMFirst of all, Python uses indentation for code nesting, so you may not deliberately modify indentation in the script, e.g. adm.addVideoFilter("swscale", and adm.setContainer etc. below must be indented by exactly the same number of spaces as the previous statement.

Regarding the error you get, you probably use an old version of Avidemux which doesn't support splitext method.
Thanks. Done
Title: Re: Script error in Avidemux 2.8 - 2.7
Post by: justausername on June 23, 2023, 01:16:02 PM
I have tried every single python script on this that I can find, but I get an error every time I try to run it. Is there a simple one that I could put in that would work that can process files in a folder and I can work off that?