Author Topic: batch converting hard code subs help!!  (Read 2538 times)

lordfenixnc

  • Newbie
  • *
  • Posts: 6
batch converting hard code subs help!!
« on: May 02, 2017, 05:13:24 PM »
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

Code: [Select]
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
Code: [Select]
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.audioClearTracks()
adm.setSourceTrackLanguage(0,"")
adm.setSourceTrackLanguage(1,"jpn")
adm.audioAddTrack(1)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MP4V2", "optimize=0", "add_itunes_metadata=0")

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 6060
Re: batch converting hard code subs help!!
« Reply #1 on: May 02, 2017, 06:04:09 PM »
Need to name matching subtitle file with the same filename as the .mkv videofile with extension .ssa .
Example:
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.

lordfenixnc

  • Newbie
  • *
  • Posts: 6
Re: batch converting hard code subs help!!
« Reply #2 on: May 02, 2017, 06:11:31 PM »
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

  • Hero Member
  • *****
  • Posts: 6060
Re: batch converting hard code subs help!!
« Reply #3 on: May 03, 2017, 05:01:23 AM »
somehow you need to get this changed in py code to reflect to the batch loaded video :
"subtitleFile=C:/Users/LordFenixNC/Downloads/Videofile01.ssa"

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
« Last Edit: May 03, 2017, 07:42:18 AM by Jan Gruuthuse »

lordfenixnc

  • Newbie
  • *
  • Posts: 6
Re: batch converting hard code subs help!!
« Reply #4 on: May 03, 2017, 06:33:14 AM »
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

  • Hero Member
  • *****
  • Posts: 6060
Re: batch converting hard code subs help!!
« Reply #5 on: May 03, 2017, 07:50:53 AM »
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


lordfenixnc

  • Newbie
  • *
  • Posts: 6
Re: batch converting hard code subs help!!
« Reply #6 on: May 03, 2017, 01:20:00 PM »
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

  • Hero Member
  • *****
  • Posts: 6060
Re: batch converting hard code subs help!!
« Reply #7 on: May 03, 2017, 03:22:24 PM »
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:

C:/Users/LordFenixNC/Downloads/Videofile01.ssa

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.


lordfenixnc

  • Newbie
  • *
  • Posts: 6
Re: batch converting hard code subs help!!
« Reply #8 on: May 04, 2017, 05:59:40 AM »
Tried it with no success sadly

lordfenixnc

  • Newbie
  • *
  • Posts: 6
Re: batch converting hard code subs help!!
« Reply #9 on: May 07, 2017, 04:08:16 AM »
here is what i get every time  only when trying to load subs

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 6060
developers
« Reply #10 on: May 07, 2017, 04:39:09 AM »
Developers:
Python raises a KeyError whenever a dict() object is requested (using the format a = adict[key]) and the key is not in the dictionary.

@lordfenixnc
- 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/
« Last Edit: May 07, 2017, 04:56:02 AM by Jan Gruuthuse »