News:

--

Main Menu

Separators

Started by TheTooleMan, February 06, 2025, 05:25:34 PM

Previous topic - Next topic

TheTooleMan

A script that once worked is not working now. A possible reason is the recent "upgrade" from Windows 10 to 11.

The script is written to loop through a folder, perform a conversion on video files with a certain extension, then save the files to a different folder. The error occurs when the script constructs a file name for sending to the processing routine.

The file name constructed by the script looks like this:

D:/Videos/Input_folder\input_file.mkv

Obviously, tinypy will not accept the inconsistent slashes.

While the "\" is used by Windows in File Explorer and other processes, Avidemux wants to see "/". The GUI functions I call to build the file names use different formatting, apparently.

There must be a way to clear up this inconsistency and specify the preferred formatting. Please enlighten me. Thanks.

eumagga0x2a

Please enlighten me with details (the script which was used, the Avidemux build you were using which should be the latest official known good one which is currently r241212 or a self-compiled build off the latest git master).

TheTooleMan

I am running Avidemux 2.8.1 (220330_6ae3e4b86ab-fflibs 4.4.1)

Let's see if I can attach the .py file...

You cannot view this attachment.

TheTooleMan

By the way, I am seeing the mismatched slashes when I display the variable i in the loop here:

for i in list:
    total += 1
    ui.displayInfo("This is i", i)
    counter += Converter(i, outputFolder)

eumagga0x2a

Please verify first that the problem persists with the Avidemux 2.8.2 nightly build I mentioned above. 2.8.1 release is outright ancient.

Can't inspect the script yet (need a browser which allows disabling HTTP2).

eumagga0x2a

When trying the 2.8.2 nightly, you might need (unsure) to define the variable sep as "\\" instead of "/" as Avidemux now more consistently uses backslashes on Windows.

TheTooleMan

Quote from: eumagga0x2a on February 06, 2025, 08:54:50 PMWhen trying the 2.8.2 nightly, you might need (unsure) to define the variable sep as "\\" instead of "/" as Avidemux now more consistently uses backslashes on Windows.
I tried a few variations on the value of sep such as "\\", "/", "//", etc. And I installed a later release (not 2.8.2) but saw the same results. I will try 2.8.2 nightly and report back.

eumagga0x2a

There hasn't been any release since 2.8.1 yet, just developer builds (which are most of the time less buggy than the release, but not always).

TheTooleMan

Used the nightly build, but still having the same problem as before.

eumagga0x2a

Okay, I'll try to look into it over the weekend.

eumagga0x2a

I missed how broken the script you provided was. Both forward slashes and backslashes can be used on Windows functionally interchangeably, the issue is purely aesthetical. What matters, is that you must load a video before you try to save audio and that elements of a list containing strings (file paths) cannot be treated as integers. Fixed script below.

Please note that I didn't add a check for the first audio track being supported let alone being AC3 and also didn't modify the script to handle more than 10 videos in the input folder properly (both is possible).

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
sep = "/"
#
# Function to convert an individual video
#
def Converter(Index, filein, fileout):
    leadingZero = ""
    if Index < 10:
        leadingZero = "0"

    ui.displayInfo("Converter", "Fileout= " + fileout)

    if not adm.loadVideo(filein):
        ui.displayError("Error", "Cannot load " + "\"" + filein + "\"")
        return 0

    if not adm.audioTotalTracksCount():
        adm.closeVideo()
        return 0

    adm.audioCodec(0, "copy")

    if not adm.saveAudio(0, fileout + sep + "File_" + leadingZero + str(Index) + ".ac3"):
        ui.displayError("Error", "Error saving audio track")
        adm.closeVideo()
        return 0
    ui.displayInfo("Success", "Track exported")
    adm.closeVideo()
    return 1
#
# Main
#
# -------- select extension --------
extensions = ["mkv","mov","mp4","vob","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 --------
ui.displayInfo("inputFolder", str(inputFolder))
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
    ui.displayInfo("This is i", i)
    counter += Converter(total, 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")

TheTooleMan

Thank you so much for debugging the script for me. Obviously there are a few fundamentals missing from my knowledge.