- Install SubtitleEdit.
- Install Python 3.
- Set
subtitleedit
variable in bothsub_format.bat
andsubstationalpha2srt.bat
to the path of the executable of SubtitleEdit.
Last active
January 8, 2024 23:34
-
-
Save nadhirxz/ceae6431a1176aa7280d65b78889d7cb to your computer and use it in GitHub Desktop.
Scripts to convert and format subtitles using SubtitleEdit on windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os, re | |
if (len(sys.argv) > 1 and sys.argv[1] == '-en'): LANGUAGE = 'en' | |
else: LANGUAGE = 'ar' | |
STYLE = {'ar': 'Adobe Arabic,28', 'en': 'Open Sans Semibold,24'} | |
SUBS_FOLDER='subs' | |
for file_name in os.listdir(SUBS_FOLDER): | |
if (file_name.endswith('.ass')): | |
file_name = f'{SUBS_FOLDER}/{file_name}' | |
lines = open(file_name, 'r', encoding='utf-8').read() | |
lines = re.sub(r'Style:[^\n]+', f'Style: Default,{STYLE[LANGUAGE]},&H00FFFFFF,&H0300FFFF,&H00000000,&H02000000,-1,0,0,0,100,100,0,0,1,1.8,0,2,10,10,15,1', lines) | |
open(file_name, 'w', encoding='utf-8').write(lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set subtitleedit="C:\Program Files\Subtitle Edit\SubtitleEdit.exe" | |
if not exist srt call substationalpha2srt | |
set output=subs | |
if not exist %output% mkdir %output% | |
%subtitleedit% /convert srt/*.srt AdvancedSubStationAlpha /outputfolder:"%output%" /overwrite %* | |
style_subs.py %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set subtitleedit="C:\Program Files\Subtitle Edit\SubtitleEdit.exe" | |
set output=srt | |
if not exist %output% mkdir %output% | |
%subtitleedit% /convert *.srt subrip /RemoveFormatting /MergeSameTexts /outputfolder:%output% /overwrite | |
%subtitleedit% /convert *.ass subrip /RemoveFormatting /MergeSameTexts /outputfolder:%output% /overwrite | |
if exist *.srt ( | |
xcopy *.srt original-subs\ | |
del *.srt | |
) | |
if exist *.ass ( | |
xcopy *.ass original-subs\ | |
del *.ass | |
) |
is it possible for a script that shifts subtitles 1 second backwards or forwards?
You can do that by using /offset:hh:mm:ss:ms
, so if I want to shift subs forward by let's say 1 minute and 3 seconds, I'd do it like this:
subtitleedit /offset:00:01:03:00
To shift backward you just add a -
sign to the offset
subtitleedit /offset:-00:00:05:00
It's also supported by the script:
sub_format /offset:00:00:01:00
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is it possible for a script that shifts subtitles 1 second backwards or forwards?