I used ffmpeg to batch convert some ttml/vtt subtitles to srt. I then noticed that there are random indents at the beginning of some lines in the SRT file.
For example:
I would like it to be:Code:1 00:00:01,000 --> 00:00:05,000 one two three 2 00:00:06,000 --> 00:00:10,000 one two three
I've been using Subtitle Edit 4.0.4, but can't find a setting to remove indentation.Code:1 00:00:01,000 --> 00:00:05,000 one two three 2 00:00:06,000 --> 00:00:10,000 one two three
Is there a way to batch it in Subtitle Edit or another way to batch remove the indentations?
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 7 of 7
Thread
-
-
I don't know about a batch convert but I would use MS Word to make changes. SE can do it under Edit > Replace but you might have a hard time removing a single space at the beginning of a line since there are single spaces throughout the SRT. In Word just add a ^p in front of the spaces ("^p ") without the quotes. In SE I don't know how you signify a CR/LF. The ^p would make it a unique search since it follows a line.
Sorry, I keep editing this reply.
When you replace just replace with a ^p. So find "^p ", replace "^p".Last edited by Moralez; 11th Apr 2024 at 10:46.
-
I found the option in Subtitle Edit. I'll post it here in case anyone else has the same issue.
Tools --> Fix common errors --> Remove unneeded spaces
Thanks for the helpful suggestion Moralez. I have too many files to do each one manually so I need to do it batch. But your method would work great for someone who only has to make a few edits. Thanks. -
Many advanced text editors have search and replace commands that would allow you to replace a newline followed by a space (or several spaces) with just a newline. Since SRT files are plain text you can use any of those editors.
Even Notepad can do this:
Search for:
Code:Shift+RightArrow Space
Code:Shift+RightArrow
Last edited by jagabo; 12th Apr 2024 at 17:14.
-
I use this, it's tiny 263KB. http://findandreplace.io/
It has a built in GUI, just run it to see.
It also works in command line mode (--cl)
This is my batch file. Each of the 3 iterations removes one space from the beginning of a line. If you set it to do 5, then all leading spaces should be removed.
no_spaces.cmdCode:@echo off for %%a in ("*.txt") do ( fnr.exe --cl --dir "%CD%" --fileMask "*.srt" --silent --useRegEx --useEscapeChars --find "^ " --replace "" fnr.exe --cl --dir "%CD%" --fileMask "*.srt" --silent --useRegEx --useEscapeChars --find "^ " --replace "" fnr.exe --cl --dir "%CD%" --fileMask "*.srt" --silent --useRegEx --useEscapeChars --find "^ " --replace "" ) pause
Code:fnr.exe --cl --dir "%CD%" --fileMask "*.srt" --silent --useRegEx --useEscapeChars --find "\</font\>" --replace "" fnr.exe --cl --dir "%CD%" --fileMask "*.srt" --silent --useRegEx --useEscapeChars --find "\<font color.{10,}\>" --replace ""
Cheers.Last edited by pcspeak; 12th Apr 2024 at 23:52.
-
You may find this useful. Consider this, not as a humbug but, as an opportunity to learn something new.
Create a loop that will capture all your subtitle files. There are numerous examples of doing this in this very forum.
For each file found execute
Code:sed -e "s#^ *##"
this code will find all lines that begin with one or multiple spaces and delete all the spaces.
I suspect this question was asked and answered multiple times before.
Although sed is not shipped with windows, it is a free download.
This should take no more than 5 lines of code and you will be quite happy with your accomplishment. -
To widen a collection of solutions, using python to remove leading space characters in srt files in a directory:
Code:from pathlib import Path import sys def main(directory): #batch remove leading space characters for a srt files in a directory print(f'changed files:') for text_file in Path(directory).glob("*.srt"): if process_text(text_file): print(f' {text_file}') def process_text(text_file): #remove leading space characters from a text file text_file = str(text_file) with open(text_file) as f: is_change = False lines=list(f) for i, line in enumerate(lines): if line.startswith(" "): is_change = True lines[i]=line.lstrip() if is_change: with open(text_file,'w') as f: f.write(''.join(lines)) return is_change if __name__ == '__main__': """ Usage: python "delete_leading_spaces.py" "D:/my_directory" """ try: main(sys.argv[1]) except IndexError: raise IndexError('No directory argument passed') from None
Similar Threads
-
Convert SRT to SUP?
By lazyturbo in forum SubtitleReplies: 14Last Post: 28th Dec 2022, 13:05 -
Many srt files into usf-8 srt files
By fits79 in forum SubtitleReplies: 3Last Post: 18th Aug 2022, 11:32 -
ASS to SRT
By agon024 in forum SubtitleReplies: 6Last Post: 11th Apr 2021, 16:26 -
Remove hdr without converting. Just remove hdr from mkv files
By fits79 in forum Video ConversionReplies: 9Last Post: 12th Jun 2020, 12:02 -
editing srt with mkvtoolnix
By David Banner in forum EditingReplies: 3Last Post: 20th Apr 2020, 11:01