I realise this is an idiotic question, how to change a Project Script to process

Started by pinnocchio, June 27, 2024, 08:34:33 PM

Previous topic - Next topic

pinnocchio

I've googled and can't find the answer to this, quite possibly because of the phraseology difference between script and project script.....

I have a large number of files in a directory, that I want to run a NVENC x265 compress on, while also changing their size, I expect the job to take 3-4 days in total.

I did one manually successfully, and using the

File -> Project Script

option have saved a project script that seems to have the required parameters, but obviously using the single filename used for the example/test.

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

adm = Avidemux()
if not adm.loadVideo("/path/filename01.mkv"):
    raise("Cannot load /path/filename01.mkv")
adm.clearSegments()
adm.addSegment(0, 42209, 3698736708)
adm.markerA = 0
adm.markerB = 3698736708
adm.setHDRConfig(1, 1, 1, 1, 0)
adm.videoCodec("ffNvEncHEVC", "preset=5", "profile=0", "rc_mode=0", "quality=20", "bitrate=2000", "max_bitrate=10000", "gopsize=100", "refs=0", "bframes=0", "b_ref_mode=2", "lookahead=0", "aq_strength=1", "spatial_aq=False", "temporal_aq=False"
, "weighted_pred=False")
adm.addVideoFilter("vdpauResize", "targetWidth=1920", "targetHeight=1080")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"eng")
adm.setSourceTrackLanguage(1,"eng")
if adm.audioTotalTracksCount() <= 0:
    raise("Cannot add audio track 0, total tracks: " + str(adm.audioTotalTracksCount()))
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAC3", "bitrate=384")
adm.audioSetDrc2(0, 0, 1, 0.001, 0.2, 1, 2, -12)
adm.audioSetEq(0, 0, 0, 0, 0, 880, 5000)
adm.audioSetChannelGains(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
adm.audioSetChannelDelays(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
adm.audioSetChannelRemap(0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")

So, my question is what would be the correct command to replace

/path/filename01.mkv in the autogenerated script above

with the equivalent of a bash

>for FILENAME in *; do

>process assorted batch commands on "$FILENAME"

>done

loop?

Sorry to have to ask, but as I don't use python at all, many of the examples I've read seem to then refer to the version of Avidemux (2.8.1 release) as well, so it's a little confusing to say the least, any help appreciated and I do realise I shouldn't have to ask for this.

eumagga0x2a

You might find some ideas here. A note: from the code from your project script you will need to include into the function analog to processVideo(vidin, outdir) in the example, you should drop

adm.clearSegments()
adm.addSegment(0, 42209, 3698736708)
adm.markerA = 0
adm.markerB = 3698736708

and rethink the audio part depending on the number of audio tracks you need to handle (what should happen when you have more than a single audio track?).

A project script is a script for internal Python-like scripting in Avidemux. It is always a script :-)

pinnocchio

Thanks for the quick response and the link, however reading it isn't helping as my understanding of Python is literally zero, while I can try to take the concepts onboard the problem is that I have no understanding of any external dependencies so reading it is just opening more questions that I then have to do a lot more research to try to understand.

For example, in the extra info you kindly provided there's references like...

adm.clearSegments()

these 'adm' statements, are they function calls within avidemux?

The script I want doesn't need to run from the GUI frontend if that's not a specific requirement, I'm quite happy to let it run in a Command Prompt till it's finished.

Sorry to be a pest, but I'm floundering here for something I hoped would be pretty simple question on changing a single filename to instead choosing all the files in the directory.

eumagga0x2a

Quote from: pinnocchio on June 30, 2024, 09:58:23 AMthe problem is that I have no understanding of any external dependencies

There are none.

Quote from: pinnocchio on June 30, 2024, 09:58:23 AMFor example, in the extra info you kindly provided there's references like...

adm.clearSegments()

these 'adm' statements, are they function calls within avidemux?

Earlier in the script, there is an assignment

adm = Avidemux()
of adm to the constructor of the class which makes it simply a way to save keystrokes, else we would have to write

Avidemux().clearSegments()
each time we need to call a method within Avidemux class. The list of methods available in this class is printed to the script console in Avidemux (not to an operating system command prompt!) by executing there a command

Avidemux.help()
(the same is valid for the Editor class etc.).

When the script is ready, you can pass it to the Avidemux command-line executable by means of

/path/to/avidemux3_cli --run /path/to/your/projectScript.py
However, an example script I linked to makes use of interactive GUI features to select source and output folders, not applicable to the CLI version of Avidemux, i.e. you would need to pass appropriate input and output files by other means, either from a bash (shell) script

for i in *mkv; do /path/to/avidemux3_cli --load "$i" --run /path/to/your/projectScript.py --save /path/to/output/directory/"$i" --quit; done
or by hardcoding the paths in the project script itself. The main limitation of the CLI version is that many (all?) hw accelerated features are not available there, thus unsure you would be able to use NVENC HEVC encoder (the x265 HEVC encoder will be fine, of course). In this sense, the GUI Avidemux executable is needed both for simplicity and for your specific choice of encoder.

Quote from: pinnocchio on June 30, 2024, 09:58:23 AMI'm floundering here for something I hoped would be pretty simple question on changing a single filename to instead choosing all the files in the directory.

I believe the script I linked to comes as close to your requirements as possible. To tailor it even more to your specific needs, I would need an answer to my specific question...