October 24, 2020, 03:59:55 am



batch converting hard code subs help!!

Started by lordfenixnc, May 02, 2017, 05:13:24 pm

Previous topic - Next topic


need some help   got it sorta working    just cant get it to hardcode subs in a batch   maybe someone can help me 

my .bat code

set avidemux="C:\Program Files (x86)\Avidemux 2.6 - 32 bits\avidemux.exe"
set videocodec=Nvidia H264
set audiocodec=Copy
for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --run test.py  --save "%%f.mp4" --quit

my py code
adm = Avidemux()
adm.videoCodec("ffNvEnc", "preset=2", "bitrate=1600", "max_bitrate=4000")
adm.addVideoFilter("ssa", "font_scale=1.000000", "line_spacing=0.100000", "subtitleFile=", "fontDirectory=c:", "extractEmbeddedFonts=1"
, "topMargin=0", "bottomMargin=0")
adm.addVideoFilter("partial", "filterName=addLogo", "startBlack=1000", "endBlack=65000", "x=0", "y=0", "alpha=255", "logoImageFile=C:/Users/LordFenixNC/Downloads/encodelogo.png")
adm.addVideoFilter("partial", "filterName=addLogo", "startBlack=1261000", "endBlack=1325000", "x=0", "y=0", "alpha=255", "logoImageFile=C:/Users/LordFenixNC/Downloads/encodelogo.png")
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MP4V2", "optimize=0", "add_itunes_metadata=0")

Jan Gruuthuse

Need to name matching subtitle file with the same filename as the .mkv videofile with extension .ssa .
Videofile01.mkv: subtitle file becomes Videofile01.ssa .
Then using %%f to get current filename and use this to load filename.ssa . Probably something like "subtitlefile="%%f&".ssa" . Not so familiar with scripting these days. Hope this gets you on the way loading the .ssa file.


im a idiot with code   i threw this together using google....   thank you for the input  jan.   hope someone can help me fill in the blank for the bat and py   cause i know both need to be fixed

Jan Gruuthuse

May 03, 2017, 05:01:23 am #3 Last Edit: May 03, 2017, 07:42:18 am by Jan Gruuthuse
somehow you need to get this changed in py code to reflect to the batch loaded video :

You need to test or a windows user needs to confirm what is working. And if using %%f is passing the needed filename to into py
- "subtitleFile=C:/Users/LordFenixNC/Downloads/"&"%%f&".ssa"
- "subtitleFile=C:/Users/LordFenixNC/Downloads/"+"%%f+".ssa"
- "subtitleFile=C:/Users/LordFenixNC/Downloads/""%%f".ssa"
- ...

"fontDirectory="&%WINDIR%&"/Fonts" with the understanding you are using an installed font, if using none installed font, like a downloaded, you must point to that location.

more info found @ Using tinypy scripting


I'll play with the code in the am thank you!!   the files are found fine... Just not the subs...  Everything is in the same Directory on my n drive.. The dl folder just has the logo i made

Jan Gruuthuse

You need to change of course to your correct folder and not the one shown in the example (C:/Users/LordFenixNC/Downloads/).

also pointing and using the fontfile could be important.

Use the avidemux gui to load a test case (small video, sample subtitle file) set up font and usage if needed in avidemux filter.
check preview play, if al works:

Avidemux Menu: File:
- Project Script
-- Save As Project
save with subtitletest as filename in your video folder.
look in video folder for subtitletest.py, open with editor
you will find saved settings like subtitleFile, fontDirectory and many more


see here is the thing...  that directory is just for the LOGO I was placing on the video..  if you look up you will see my Sub code has no directory... because I was trying to figure out a way to get the Bat file to do for the Subtitles  what it did for video files..   RIGHT NOW  I can load the PY and Bat in the same folder  as lets say a show with 200+ eps...  and it will encode all of them  just WONT hardcode the subtitles.   if I have to add the directory each time that is fine   I don't mind having to tweak it each time I move the files to a dif folder.

Jan Gruuthuse

you are confused and not reading what I write
example: C:/Users/LordFenixNC/Downloads/ <= don't use that, I have no knowledge of your system and layout of your folders !!!!

subtitle file info must be passed somehow into the tinypy script.
subtitleFile is a string (text) and should contain reference to folder where the .ssa file resides and it should also have the name of the subtitle file!
I suppose each video has its own subtitle file.
example: Videofile01.mkv then you should name the subtitle file for that video Videofile01.ssa
end goal would be Example: subtitleFile=C:/Users/LordFenixNC/Downloads/"&"%%f&".ssa"
echo subtitleFile
would display:


then you would be able to use the subtitle file matching the current processed video Videofile01.mkv

I'll leave you at it and hope someone else will jump in to this.



here is what i get every time  only when trying to load subs

Jan Gruuthuse

May 07, 2017, 04:39:09 am #10 Last Edit: May 07, 2017, 04:56:02 am by Jan Gruuthuse
Python raises a KeyError whenever a dict() object is requested (using the format a = adict[key]) and the key is not in the dictionary.

- When loading the first subtitle file? or is this further onwards in batch processing?
- Try installing again with avidemux installer (.exe) form here: http://www.avidemux.org/nightly/