Avidemux Forum

Avidemux => Windows => Topic started by: SRoy on April 09, 2020, 06:20:48 PM

Title: Error Help for Batch Converting using Python OR suggest better method please
Post by: SRoy on April 09, 2020, 06:20:48 PM
Hello, if you know a better way to batch convert any video formats or some video formats to Nvidia HEVC mp4 please let me know.
(More specifically to: "ffNvEncHEVC", "preset=2", "bitrate=14000", "max_bitrate=16000")

:)  I'd just want to select a folder and all the video contents would be converted and replaced automatically.



I searched Youtube about batch converting and found this video https://youtu.be/pxMeIU-ghXY (https://youtu.be/pxMeIU-ghXY) shows a way which involves using project scripts and python. The video is from 2016 so some things have changed and maybe it's broken.

So, my request to anyone is to find the errors here or suggest a better way. I just copied what he did in py, and here it is.

I suspect the problematic lines are 14 and 20.

I thank you if you help me from the bottom of my heart! (sounds cheesy, but I actually need this) ;D

#
# Load all the files in c:\tmp with .mp4 extension.
# That's it.
#
gui = Gui()
adm = Avidemux()
ext="mp4"
sep = "\\"
#
def convert(filein):
    filename = basename(filein)
    dir = dirname(filein)
    adm.loadVideo("C:/Test/Cut FastMo.mp4")   
    if(0 == adm.loadVideo(filein)):
        gui.displayError("oops","cannot load "+filein)
        raise
    adm.setPostProc(3, 3, 0)
    adm.videoCodec("ffNvEncHEVC", "preset=2", "bitrate=14000", "max_bitrate=16000")
    adm.audioClearTracks()
    adm.setSourceTrackLanguage(0,"und")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy");
    adm.audioSetDrc(0, 0)
    adm.audioSetShift(0, 0, 0)
    adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0")
    adm.save(dir + sep + "HEVC" + filename)
    print("Done")
   
#
# Main
#
list=get_folder_content(inputFolder,ext)
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")

Title: Re: Error Help for Batch Converting using Python OR suggest better method please
Post by: eumagga0x2a on April 10, 2020, 03:40:37 PM
Please try

gui = Gui()
adm = Avidemux()
ext = "mp4"
sep = "\\"
#
def convert(filein):
    filename = basename(filein)
    dir = dirname(filein)
    if 0 == adm.loadVideo(filein):
        gui.displayError("oops","cannot load "+filein)
        return 0
    adm.videoCodec("ffNvEncHEVC", "preset=2", "bitrate=14000", "max_bitrate=16000")
    adm.audioClearTracks()
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy");
    adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")
    return adm.save(dir + sep + "HEVC_" + filename)
#
# Main
#
inputFolder=gui.dirSelect("Select source folder")
if not inputFolder:
    return
list=get_folder_content(inputFolder,ext)
if(list is None):
    gui.displayInfo("Warning", "Selected folder does not seem to contain "+ext+" files")
    return
counter = 0;
for i in list:
    if 1 == convert(i):
        counter = counter+1
if not counter:
    gui.displayInfo("Warning", "No files converted")
    return
text = "Converted "+str(counter)+" file"
if counter > 1:
    text = text+"s"
gui.displayInfo("Done", text)


The higher number of arguments for setContainer results from using a current Avidemux build, not the meanwhile outdated release.
Title: Re: Error Help for Batch Converting using Python OR suggest better method please
Post by: eumagga0x2a on April 10, 2020, 03:45:25 PM
By the way, selected bitrate values are really huge, are you converting 4K / 60 fps videos?

Regarding the options passed to libavcodec in case of the NVENC-accelerated HEVC encoder, I'll try to add a much more useful CRF mode prior to 2.7.6.
Title: Re: Error Help for Batch Converting using Python OR suggest better method please
Post by: QDS850 on August 03, 2020, 03:51:38 PM
Quote from: eumagga0x2a on April 10, 2020, 03:40:37 PM
Please try

gui = Gui()
adm = Avidemux()
ext = "mp4"
sep = "\\"
#
def convert(filein):
    filename = basename(filein)
    dir = dirname(filein)
    if 0 == adm.loadVideo(filein):
        gui.displayError("oops","cannot load "+filein)
        return 0
    adm.videoCodec("ffNvEncHEVC", "preset=2", "bitrate=14000", "max_bitrate=16000")
    adm.audioClearTracks()
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy");
    adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")
    return adm.save(dir + sep + "HEVC_" + filename)
#
# Main
#
inputFolder=gui.dirSelect("Select source folder")
if not inputFolder:
    return
list=get_folder_content(inputFolder,ext)
if(list is None):
    gui.displayInfo("Warning", "Selected folder does not seem to contain "+ext+" files")
    return
counter = 0;
for i in list:
    if 1 == convert(i):
        counter = counter+1
if not counter:
    gui.displayInfo("Warning", "No files converted")
    return
text = "Converted "+str(counter)+" file"
if counter > 1:
    text = text+"s"
gui.displayInfo("Done", text)


The higher number of arguments for setContainer results from using a current Avidemux build, not the meanwhile outdated release.
Title: Re: Error Help for Batch Converting using Python OR suggest better method please
Post by: QDS850 on August 03, 2020, 03:58:53 PM
I am using your code but I keep getting an error as some of the files I am trying to convert have got UTF-8 file names.
Is there a method to get TinyPy to fetch these files?
Title: Re: Error Help for Batch Converting using Python OR suggest better method please
Post by: eumagga0x2a on August 03, 2020, 06:20:35 PM
This definitely works fine for me with UTF-8 file names on Linux. Which build do you use? VC++ or MinGW? It should be at least the latest release, preferably the latest nightly.