News:

--

Main Menu

How_To_Batch_File_Proccessing?

Started by pulsarstar, April 14, 2021, 08:57:30 AM

Previous topic - Next topic

pulsarstar

Hi Guys,
I am a newbie to this forum,
I just installed Avidemux 2.7.8 the other day.
I have never worked with this program before.
I have been editing video films to change their volume.
I loaded in a video film titled "Taboo.mp4"
I changed Audio Output to AAC (FDK)
I changed Filters Gain Manual (DB)
And put Gain Value: 10
I changed the FDK-AAC configuration Bitrate from 128 to 192 (in the hope of improving the sound quality) ( not sure about that)?
Output Format was set for MKV Muxer
Then I saved my Video File as"Taboo.mkv"
On playing back the video I found the gain in the volume to be perfect for my needs.
I then looked at the software to process multiple video one after the other, so I could go to bed and leave it running overnight.
In the GUI interface I could not find this option! But I understand from reading online that a *.Bat file or script can be written to accomplish this task.
So here is my question to you Guys:
Can someone write me an example down, that I can cut and paste into my Windows 10 Notepad and save it as a *.Bat file ?
Thank you for your help:

butterw

Quote from: pulsarstar on April 14, 2021, 08:57:30 AMI have been editing video films to change their volume.
I loaded in a video film titled "Taboo.mp4"
I changed Audio Output to AAC (FDK)
I changed Filters Gain Manual (DB)
And put Gain Value: 10
I changed the FDK-AAC configuration Bitrate from 128 to 192 (in the hope of improving the sound quality) ( not sure about that)?

You are re-encoding the audio (to add 10dB Gain).
- Quality is degraded vs the original. By increasing the bitrate you limit this degradation. 192kbps in FDK-AAC should achieve near transparency for stereo.
- Also be aware that applying gain blindly could lead to saturation of peaks.

IMO it would be preferable to use something like replaygain which normalizes the audio perceived loudness (foobar2K can modify mp4/m4a files without re-encoding them).

 

pulsarstar

Thanks Butterw for the info on bitrate,
and on the advice of use of software foobar2k.
I will take a look at it.
If anyone else can answer the rest of my the question on batch file processing please do!
I would appreciate that.
Thanks for your contributions.


butterw

#3
for batch processing in Avidemux (ex: process all files in a directory):
- load one file, setup your filters/encoders/muxer as desired, save as project script.

Then modify the project script (.py) for batch processing with automated output filename save.

pulsarstar

Hi butterw,
I have created my script (.py) file.
I don't understand the last line of your advice ?

Then modify the project script (.py) for batch processing with automated output filename save?

Is it an option on the GUI I have missed or should I edit the script file in notepad ?
this is my script (.py).

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
if not adm.loadVideo("G:/TABOO/Taboo_1._Episode_1.mp4"):
    raise("Cannot load G:/TABOO/Taboo_1._Episode_1.mp4")
adm.clearSegments()
adm.addSegment(0, 0, 3302200000)
adm.markerA = 0
adm.markerB = 3302200000
adm.setPostProc(3, 3, 0)
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, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.audioSetNormalize2(0, 2, 120, -30)
adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")



butterw

there are 2 different possible approaches:
- the first uses avidemux_cli and a bat file (I'm not familiar with this)
- the second is based on Tinypy scripting https://avidemux.org/smif/index.php/topic,19390.0.html : you need to edit the script to load the input files and save the output with the command adm.save(filepath).


pulsarstar

OK.Thank you for your assistance.
I will give that a try, and see where it lands me.
I hope in future update versions of Avidemux the R & D Department include batch file processing in the GUI options.
This takes me back to the days of D.O.S. :'(  :'(  :'(

eumagga0x2a

Quote from: pulsarstar on April 14, 2021, 03:24:13 PMI hope in future update versions of Avidemux the R & D Department include batch file processing in the GUI options.

You can queue tasks for later batch processing using Avidemux Jobs GUI, but the R & D Department doesn't think that inflating GUI is the way to go.

For your task, you could use the following untested script (copy and paste it into the Avidemux script console or save as a .py file and pass to the executable on the command line as the argument of the --run option:

#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("Copy")
    if adm.audioTracksCount() > 0:
        adm.audioClearTracks()
        adm.audioAddTrack(0)
        adm.audioCodec(0, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
        adm.audioSetDrc(0, 0)
        adm.audioSetShift(0, 0, 0)
        adm.audioSetNormalize2(0, 2, 120, -30)
    adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")

    filename = (splitext(filein))[0]
    filename += ".mkv"
    filename = basename(filename)
    return adm.save(out + sep + filename)
#
# Main
#
# -------- select extension --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","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 --------
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")

The script processes all files with given extension in a directory.

pulsarstar

Thank you for the advise eumagga0x2a.
I appreciate that.
I will give that a try when I get chance.

pulsarstar

Hi, eumagga0x2a
The script works perfectly, it does exactly what I wanted it to do.
I pasted the script into Tools> Script shell> in the Evaluate box.
I Evaluated it. Beautiful.
Could you tell me how to change the Gain mode: Manual (dB)
In the script to lower or raise the manual (dB)?
As I have never written any script in my entire life, I am guessing
If I change the values in
adm.audioSetNormalize2(0, 2, 120, -30)    ?
Or am I barking up the wrong tree ?
Thanks again for the script,
I would have never done it on my own.

eumagga0x2a

Quote from: pulsarstar on April 19, 2021, 07:39:01 AMThe script works perfectly, it does exactly what I wanted it to do.
I pasted the script into Tools> Script shell> in the Evaluate box.
I Evaluated it. Beautiful.

Glad that it worked, you can save the script as a .py file and put it into the folder %appdata%\avidemux\custom for easy access. After restarting Avidemux, it should be available via the "Custom" menu.

Quote from: pulsarstar on April 19, 2021, 07:39:01 AMCould you tell me how to change the Gain mode: Manual (dB)
In the script to lower or raise the manual (dB)?
As I have never written any script in my entire life, I am guessing
If I change the values in
adm.audioSetNormalize2(0, 2, 120, -30)    ?

Absolutely correct. The first argument is the track index (counted from zero – "0" means the first audio track), the second one represents the gain mode (valid values are ADM_NO_GAIN = 0, ADM_GAIN_AUTOMATIC = 1, ADM_GAIN_MANUAL = 2 so that "2" means manual), the third is the gain value in 10*dB (e.g. "120" = +12 dB, "18" would be +1.8 dB), the last one is the maximum level in 10*dB ("-30" = -3 dB), evaluated only in automatic mode. All parameters must be integers (no fractions, no decimal point).

pulsarstar

Thank You eumagga0x2a for such a clear and precise answer.
I shall enjoy working with this script.
I would like to teach myself this programming language.
The Script language used in Avidemux, is Python I believe?
Is there any good web pages that show all commands and examples of how to use the Script in Avidemux?
I found this web page (http://avidemux.sourceforge.net/doc/en/script.xml.html)
I was looking for a lot more info. Especially for beginners/Newbies.
I was looking for something like the old DOS manual,
With command and example of use underneath.

butterw

#12
Current Avidemux uses TinyPy (.py) for scripting, which is a very limited subset of Python.
There is no complete updated documentation, but a number of example scripts are available.
The page you linked to is likely out of date.

A feature to generate a batch script from the current configuration would be useful for casual users and could be added (in c++) to the GUI in the project script submenu. Manually modifying an existing .py script isn't difficult but there is a bit of a learning curve.

pulsarstar

Thanks for your thoughts Butterw.
Can you point me to useful links,
where I can find these existing scripts.py
that I can as you say modify ?
Cheers!

butterw

Search for: Tinypy Avidemux
or Tinypy on this forum
The most up to date info is in the thread I already linked to: https://avidemux.org/smif/index.php/topic,19390.0.html 

there are a also number of scripts in the source code repo:
https://github.com/mean00/avidemux2/search?p=2&q=extension%3Apy

my own scripts are listed in this thread: https://avidemux.org/smif/index.php/topic,19404.0.html