Author Topic: Slight naming issue when batch converting videos  (Read 309 times)

nosix

  • Newbie
  • *
  • Posts: 2
Slight naming issue when batch converting videos
« on: June 19, 2019, 04:31:38 AM »
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

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

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

Code: [Select]
#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.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
adm.audioAddTrack(0)
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.

dosdan

  • Full Member
  • ***
  • Posts: 147
Re: Slight naming issue when batch converting videos
« Reply #1 on: June 19, 2019, 11:21:47 AM »
You need to read up on parameter extensions and FOR loops:

https://ss64.com/nt/for.html
https://ss64.com/nt/syntax-args.html

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

for %%f in (*.*) do %avidemux% --load "%%f" --run "convert-all-x265.py" --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
Code: [Select]
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

Code: [Select]
C:\Filename_test>dir /b *.mts
00000.MTS
new test1.mts
new test2.mts
test1.MTS
test2.MTS
test3.mts
test4.MTS
test5.mts
test6.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.)

Code: [Select]
C:\Filename_test>for %x in (*.mts) do @echo %~nx.mp4
00000.mp4
new test1.mp4
new test2.mp4
test1.mp4
test2.mp4
test3.mp4
test4.mp4
test5.mp4
test6.mp4


Dan.


« Last Edit: June 19, 2019, 12:22:11 PM by dosdan »

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3186
Re: Slight naming issue when batch converting videos
« Reply #2 on: June 19, 2019, 12:03:07 PM »
this is the code that is being used in the .py file

Code: [Select]
#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.

nosix

  • Newbie
  • *
  • Posts: 2
Re: Slight naming issue when batch converting videos
« Reply #3 on: June 19, 2019, 08:47:33 PM »
Much appreciated to both of you.