August 13, 2020, 11:51:56 am



Slight naming issue when batch converting videos

Started by nosix, June 19, 2019, 04:31:38 am

Previous topic - Next topic


I am trying to convert a series of videos (all different file types) to x265 mp4 format and everything seems to be working correctly except when the files are saved they are named with the file extension of the file that was converted as part of the output filename. I know this sounds slightly confusing so here are a few examples to show what I am talking about.

video1.mpg <--conversion--> video1.mpg.mp4
video2.avi <--conversion-->  video2.avi.mp4
video3.mkv <--conversion--> video3.mkv.mp4

As you can see the output file has the file extension of the input file as part of it's name and I am not sure why.

Here is the code I am using in my bat file which references a .py file with the same name

set avidemux="C:\Users\Null\Desktop\Portable Apps\AvidemuxPortable\avidemux_cli.exe"
for %%f in (*.*) do %avidemux% --load "%%f" --run "" --save "./converted/%%f.mp4" --quit

and this is the code that is being used in the .py file

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

adm = Avidemux()
adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.poolThreads=99", "general.frameThreads=99", "general.preset=", "general.tuning=", "general.profile=", "level=-1", "vui.sar_height=1"
, "vui.sar_width=1", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40", "MaxBFrame=3", "i_bframe_adaptive=1", "i_bframe_bias=0", "i_bframe_pyramid=2", "b_deblocking_filter=True", "interlaced_mode=0"
, "constrained_intra=False", "lookahead=40", "weighted_pred=2", "weighted_bipred=True", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "trellis=1", "psy_rd=1.000000"
, "fast_pskip=True", "dct_decimate=True", "noise_reduction=0", "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.rate_tolerance=1.000000", "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.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True", "forceAspectRatio=False", "aspectRatio=1")

Any help would be appreciated.


June 19, 2019, 11:21:47 am #1 Last Edit: June 19, 2019, 12:22:11 pm by dosdan
You need to read up on parameter extensions and FOR loops:

The 2nd line of your batch file should be (change in bold):

for %%f in (*.*) do %avidemux% --load "%%f" --run "" --save "./converted/%%~nf.mp4" --quit

The "~n" part in %%~nf will supply the filename without the file extension.

Here's a simple experiment. Take a group of any files for which you wish to show a different file extension. I'm going to use a FOR loop to "process" these and "change" their displayed file extensions. I'll take a group of .MTS files:

dir *.mts
C:\Filename_test>dir *.mts
Volume in drive C has no label.
Volume Serial Number is 1B09-09C2

Directory of C:\Filename_test

09/07/2017  08:43 PM        64,296,960 00000.MTS
09/07/2017  08:43 PM        64,296,960 new test1.mts
09/07/2017  08:43 PM        64,296,960 new test2.mts
09/07/2017  08:43 PM        64,296,960 test1.MTS
09/07/2017  08:43 PM        64,296,960 test2.MTS
01/04/2019  06:50 AM               325 test3.mts
09/07/2017  08:43 PM        64,296,960 test4.MTS
01/04/2019  06:50 AM               325 test5.mts
09/07/2017  08:43 PM        64,296,960 test6.mts

This command defaults to showing extra info about each file. To just see the filenames themselves use dir /b *.mts

C:\Filename_test>dir /b *.mts
new test1.mts
new test2.mts

I'm running a FOR loop from the cmd line, not inside a batch file. So, in this example I need to use a single "%" with my parameter (I'll use "x" as the parameter). Inside a batchfile you double up the "%" i.e. %%x

for %x in (*.mts) do @echo %~nx.mp4

Since there are 9 .MTS files in this directory, the FOR loop will execute the "@echo %~nx.mp4" portion 9 times, showing ("echoing") a different filename each time.

The "@" symbol stops this command line being shown 9 times as it executes repeatedly, so you just see the result. (In a batch file, the first line normally is "@echo off". The "@" stops the first line being shown when executed, while "echo off" stops all further batch lines being shown.)

C:\Filename_test>for %x in (*.mts) do @echo %~nx.mp4
new test1.mp4
new test2.mp4



Quote from: nosix on June 19, 2019, 04:31:38 am
this is the code that is being used in the .py file

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

adm = Avidemux()

####### skipped ########

adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True", "forceAspectRatio=False", "aspectRatio=1")

On Avidemux part, I would recommend using a recent nightly (it requires a different MP4 muxer configuration, however) because of support for moving the index to the beginning of the file (streaming compatibility) finally available on Windows. It uses also a different label for HEVC in mp4, compatible with QuickTime.