Batch file that accounts for the following options in the UI

Started by timaavid, December 17, 2021, 08:51:43 AM

Previous topic - Next topic

timaavid

Hello All,

I attached a screenshot with the settings which I would like to use in a Batch file (vs the UI).
Below is the latest code I am using in my batch file to attempt to accomplish the conversion.
I tried with the 'videocodec' set to 'NVIDIA HEVC' (with and without quotation marks)
I tried with the 'outputformat' set to 'NVIDIA HEVC' with and without quotation marks;  as well as being set to 'MP4'

Each time I try to run the batch file, the process does create a new file, however, it is never as compressed as when I use the GUI.

Can anyone look at the image I attached and tell me the right way to modify my batch file where I would get the same output as the GUI?

Thanks a ton!


set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=Lavcodec
set audiocodec=Copy
set outputformat=Nvidia HEVC
for %%f in (*.mp4) do %avidemux% --output-format %outputformat% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --save "%%f_HEVC.MP4" --quit

timaavid

I forgot to mention, I also tried with/without
--force-alt-h264

eumagga0x2a

You might want to try

set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=ffNvEncHEVC
set audiocodec=Copy
set outputformat=MP4
for %%f in (*.mp4) do %avidemux% --load "%%f" --output-format %outputformat% --video-codec %videocodec% --audio-codec %audiocodec% --save "%%f_HEVC.MP4" --quit

Quote from: timaavid on December 17, 2021, 08:53:25 AMI forgot to mention, I also tried with/without
--force-alt-h264

This doesn't matter as invalid arguments like this one are ignored. What matters is that nearly everything else in the command line was wrong.

If you would like to use some non-default parameters for the NVENC HEVC encoder, you would need to use a project script to pass the encoder and its configuration to the executable as argument for the --run option, i.e. create a text file with ending .py with content e.g.

adm = Avidemux()
adm.videoCodec("ffNvEncHEVC", "preset=5", "profile=0", "rc_mode=1", "quality=25", "bitrate=5000", "max_bitrate=10000", "gopsize=100", "bframes=0", "b_ref_mode=2", "lookahead=0", "aq_strength=1", "spatial_aq=False", "temporal_aq=False"
, "weighted_pred=True")

for the constant quantization mode and provide the path to this file as argument to --run. The option --video-codec should be dropped then.

timaavid

I just got back from the holidays and will try your recommendation.

timaavid

Quote from: eumagga0x2a on December 17, 2021, 02:45:52 PMYou might want to try

set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=ffNvEncHEVC
set audiocodec=Copy
set outputformat=MP4
for %%f in (*.mp4) do %avidemux% --load "%%f" --output-format %outputformat% --video-codec %videocodec% --audio-codec %audiocodec% --save "%%f_HEVC.MP4" --quit

Quote from: timaavid on December 17, 2021, 08:53:25 AMI forgot to mention, I also tried with/without
--force-alt-h264

This doesn't matter as invalid arguments like this one are ignored. What matters is that nearly everything else in the command line was wrong.

If you would like to use some non-default parameters for the NVENC HEVC encoder, you would need to use a project script to pass the encoder and its configuration to the executable as argument for the --run option, i.e. create a text file with ending .py with content e.g.

adm = Avidemux()
adm.videoCodec("ffNvEncHEVC", "preset=5", "profile=0", "rc_mode=1", "quality=25", "bitrate=5000", "max_bitrate=10000", "gopsize=100", "bframes=0", "b_ref_mode=2", "lookahead=0", "aq_strength=1", "spatial_aq=False", "temporal_aq=False"
, "weighted_pred=True")

for the constant quantization mode and provide the path to this file as argument to --run. The option --video-codec should be dropped then.



I tried modifying my bat file and it looks like this now:
set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=ffNvEncHEVC
set audiocodec=Copy
set outputformat=MP4
for %%f in (*.mp4) do %avidemux% --load "%%f" --output-format %outputformat% --video-codec %videocodec% --audio-codec %audiocodec% --save "%%f_HEVC.MP4" --quit


I then ran the convert. The new file was actually larger than the original:


When running the convert with the UI, the size is less than half:



I deleted the file created via the batch file and took a screenshot of the UI that pops up (when executing the batch file). I think the issue here is that the Video Codec says Lavcodec, vs. when I use the UI it says DXVA2:




If you know what I need to change within my bat file to get that codec, I think we're golden.

eumagga0x2a

Quote from: timaavid on January 04, 2022, 01:59:36 PMset avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"

We are at 2.8.0 now, please update.

Quote from: timaavid on January 04, 2022, 01:59:36 PMThe new file was actually larger than the original:

Sure, this is why I wrote

Quote from: eumagga0x2a on December 17, 2021, 02:45:52 PMIf you would like to use some non-default parameters for the NVENC HEVC encoder, you would need to use a project script to pass the encoder and its configuration to the executable as argument for the --run option

The default bitrate results in very large files (to maintain good quality).

Quote from: timaavid on January 04, 2022, 01:59:36 PMI think the issue here is that the Video Codec says Lavcodec, vs. when I use the UI it says DXVA2:

The video is decoded in software ("Lavcodec"), it is displayed via the DirectX ("DXVA2" is actually just DirectX) interface. It depends on your hardware, codec and video resolution whether it might be beneficial to disable libavcodec multi-threading and enable DXVA2 hardware accelerated video decoding.

timaavid

Sorry, I tried to reply the other day, but I got a message that said that my post looked like spam.

1st thing I want to say is, Thanks for your quick replies each time @eumagga0x2a (you da best).



I did just download the latest 2.8.0 (soon to be installed on my system).

I see your repost about 'non-default parameters'.

To me I was making a big assumption that there are corresponding syntax (for instance when you posted to use "ffNvEncHEVC") that relates to each of the codecs (see attach image).
Meaning, there would be some syntax that would match my Nvidia H264 in the drop down of my attachment.


It also made me wonder if there is a log for each of the conversions I made which also may tell me what Codec (syntax) was used.


Lastly, I looked around to try to find where I could contribute monetarily to this project. Let me know. Thanks

eumagga0x2a

Quote from: timaavid on January 05, 2022, 11:35:41 PMIt also made me wonder if there is a log for each of the conversions I made which also may tell me what Codec (syntax) was used.

Configure an encoder to your needs / liking. File --> Save As Project. Open the created .py file in a text editor, use the line(s) starting with adm.videoCodec for a project script as I already described 3 weeks ago.

timaavid

Funny thing about 'saving as a project', it tells me to use the same codec you first gave me.


it looks like this


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

adm = Avidemux()
if not adm.loadVideo("E:/Video.mp4"):
    raise("Cannot load E:/Video.mp4")
adm.clearSegments()
adm.addSegment(0, 0, 2089504000)
adm.markerA = 0
adm.markerB = 2089504000
adm.setHDRConfig(1, 1, 1)

adm.videoCodec("ffNvEncHEVC", "preset=5", "profile=0", "rc_mode=0", "quality=20", "bitrate=5000", "max_bitrate=10000", "gopsize=100", "bframes=0", "b_ref_mode=2", "lookahead=0", "aq_strength=0", "spatial_aq=False", "temporal_aq=False"
, "weighted_pred=True")

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, "copy")
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")