January 21, 2021, 12:02:14 PM

News:

--


[Help] Enconding full folder.

Started by luizcardoz, October 30, 2020, 03:53:05 PM

Previous topic - Next topic

luizcardoz

Hello,

When I want to reduce the size of a video, I encode it with Nvidia HEVC. I simply drag and drop a file, in the video section I select Nvidia HEVC and on audio I leave it as default (copy).

But now I need to encode 2 folders with several files, doing this file by file is going to take me a long, long time.

I already reed the topic on batch processing and many other posts, but I can't find any examples with Nvidia HEVC. All my attempts were in failure.

Can anyone help me with a CMD or batch code so I can process a full folder with Nvidia HEVC?

Thank you very much for your time.

eumagga0x2a

October 30, 2020, 08:28:14 PM #1 Last Edit: October 30, 2020, 08:30:31 PM by eumagga0x2a
If all files to convert have filename extension "mp4", you might try

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

    adm.videoCodec("ffNvEncHEVC", "rc_mode=0", "preset=5", "quality=20", "gopsize=200", "bframes=0", "bitrate=5000", "max_bitrate=10000", "twopass=False")
    adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

    filename = basename(filein)
    return adm.save(out + sep + filename)
#
# Main
#
# -------- select directories --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Oops", "No source folder selected")
    return

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

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No files to convert")
    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")

(entirely untested). Save it e.g. as "convert.py" and run in Avidemux from "File" --> "Project Script" --> "Run script".

If input files have a different filename extension (or the same extension, but with a different case), you will need to adjust the value of the "ext" variable at the beginning of the script.

The same applies to your preferred encoder settings. In doubt save your current settings as a project script and replace the line "adm.videoCodec" with whatever suits your needs best.