News:

--

Main Menu

Help with scripting a windows batch file

Started by dako44, June 23, 2023, 08:49:41 AM

Previous topic - Next topic

dako44

Hello!

I have a .bat file I have been using to convert any video file within the same directory to a x265 .mkv file, I am doing this just so everything is the same. Some of the videos need to be resized however, so I was wondering if it is possible to do swsresize via CLI? The code is attached below.

@echo off
setlocal enabledelayedexpansion

set avidemux="C:\Program Files\Avidemux 2.8 VC++ 64bits\avidemux.exe"
set videocodec=x265
set audiocodec=AAC

for /r "%~dp0" %%F in (*.avi *.mp4 *.mov *.wmv *.flv *.m4v *.mpg) do (
    start "" /wait %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%F" --save "%%~dpnF.mkv" --quit
)

echo Conversion completed.
pause

I tried to insert --swsresize between "--load "%%F" and "--save" but that was only a wild guess. Thanks in advance!

eumagga0x2a

It is amazing how obsolete since over a decade options like --force-alt-h264 refuse to die.

You need to save the Avidemux session with the video loaded and the desired video filter chain as a project script, then remove all the parts except for

adm = Avidemux()
adm.setContainer(...)
adm.addVideoFilter(...)

as you load video on command line (--load must always come first in the command line!) and pass the path to the script as argument for the --run command line option.

If you are not happy with default x265 configuration, you need to pass it within the project script.

dako44

Oh man, thank you so much! I knew I was close, I had tried to make a py script to run in conjunction with the batch but I am not very well versed in scripting. I left the video codec part in the PY because it seemed way more in depth than what I was doing in the batch.

FIXED BATCH

@echo off
setlocal enabledelayedexpansion

set avidemux="C:\Program Files\Avidemux 2.8 VC++ 64bits\avidemux.exe"
set videocodec=x265
set audiocodec=AAC

for /r "%~dp0" %%F in (*.avi *.mp4 *.mov *.wmv *.flv *.m4v *.mpg) do (
    start "" /wait %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%F" --run "X:\{DOWNLOADS}\resize.py" --save "%%~dpnF.mkv" --quit
)

echo Conversion completed.
pause

CROP AND RESIZE SCRIPT

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

adm = Avidemux()
adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.poolThreads=99", "general.frameThreads=99", "general.output_bit_depth=0", "general.preset=", "general.tuning=", "general.profile=", "level=-1"
, "vui.sar_idc=0", "vui.sar_height=1", "vui.sar_width=1", "vui.color_primaries=2", "vui.transfer_characteristics=2", "vui.matrix_coeffs=2", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40"
, "MaxBFrame=3", "i_bframe_adaptive=2", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "b_open_gop=False", "interlaced_mode=0", "constrained_intra=False", "b_intra=True", "lookahead=40"
, "weighted_pred=2", "weighted_bipred=True", "rect_inter=False", "amp_inter=False", "limit_modes=False", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "limit_refs=3"
, "rd_level=3", "psy_rd=1.000000", "rdoq_level=0", "psy_rdoq=0.000000", "fast_pskip=True", "dct_decimate=True", "noise_reduction_intra=0", "noise_reduction_inter=0", "strong_intra_smoothing=True", "ratecontrol.rc_method=0"
, "ratecontrol.qp_constant=0", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1", "ratecontrol.ip_factor=1.400000"
, "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=2", "ratecontrol.aq_strength=1.000000", "ratecontrol.cu_tree=True", "ratecontrol.strict_cbr=False")
adm.addVideoFilter("crop", "top=0", "bottom=2", "left=0", "right=2", "ar_select=0")
adm.addVideoFilter("swscale", "width=640", "height=480", "algo=1", "sourceAR=0", "targetAR=0", "lockAR=False", "roundup=0")
adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")