Title: | Adjust Srt File to Get Better Experience when Watching Movie |
---|---|
Description: | Srt file is a common subtitle format for videos, it contains subtitle and when the subtitle showed. This package is for align time of srt file, and also change color, style and position of subtitle in videos, the srt file will be read as a vector into R, and can be write into srt file after modified using this package. |
Authors: | Jim Chen [aut, cre] |
Maintainer: | Jim Chen <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.0 |
Built: | 2024-11-04 04:33:35 UTC |
Source: | https://github.com/chihangchen/srttools |
Retrieve all the subtitle text content from a srt file
srt.content(srt)
srt.content(srt)
srt |
vector. The srt file read by |
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.content(srt)
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.content(srt)
Insert new dialog to subtitles by specific index
srt.insert(srt, index, time, text)
srt.insert(srt, index, time, text)
srt |
vector. The srt file read by |
index |
integer. The index of new dialog. |
time |
character. The time of new dialog, a proper format is "hr:min:sec,msec –> hr:min:sec,msec" |
text |
character. The content of new dialog. |
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.insert(srt, index = 1, time = "00:00:00,000 --> 00:00:30,000", text = "Added by SRTtools")
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.insert(srt, index = 1, time = "00:00:00,000 --> 00:00:30,000", text = "Added by SRTtools")
Read a srt file as a vector, if there is any encoding issue, try to save your srt fle as ANSI encoding using Windows Notepad.
srt.read(file, encoding = "utf-8")
srt.read(file, encoding = "utf-8")
file |
character. The name of the file which the subtitles are to be read from. |
encoding |
character. Encoding to be assumed for input strings, deafult is 'utf-8'. |
# read a ANSI srt file srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8')
# read a ANSI srt file srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8')
Remove unwanted dialog from subtitles by specific index
srt.remove(srt, index)
srt.remove(srt, index)
srt |
vector. The srt file read by |
index |
integer. The index of unwanted dialog . |
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.remove(srt, index = 10)
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.remove(srt, index = 10)
Return the subtitle index by specific keyword
srt.search(srt, key_word)
srt.search(srt, key_word)
srt |
vector. The srt file read by |
key_word |
character. The key word want to be searched in subtitles. |
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.search(srt, key_word = "captain")
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.search(srt, key_word = "captain")
Shift a srt file with specific time.
srt.shift(srt, time_shifted)
srt.shift(srt, time_shifted)
srt |
vector. The srt file read by |
time_shifted |
numeric. The time that srt file want to be shifted (in seconds). |
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') # Postpone subtitles 3 seconds later srt <- srt.shift(srt, time_shifted = 3) # Expedite subtitles 5 seconds earlier srt <- srt.shift(srt, time_shifted = -5)
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') # Postpone subtitles 3 seconds later srt <- srt.shift(srt, time_shifted = 3) # Expedite subtitles 5 seconds earlier srt <- srt.shift(srt, time_shifted = -5)
Change subtitle style or posistion by specific subtitle index.
srt.style(srt, line = "all", pos = "None", style = "None", col = "None")
srt.style(srt, line = "all", pos = "None", style = "None", col = "None")
srt |
vector. The srt file read by |
line |
numerical vector. Style will only change the subtitles of the selected subtitle index, default is 'all', means the whole subtitles will apply the style. |
pos |
character. The subtitles position, the valid options are ' |
style |
character vector. The styles that subtitle applied, ' |
col |
character. The color that subtitle applied. |
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.style(srt, line = c(1,3,5), pos = 'top-left', style = c('b','i'), col = 'red')
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') srt.style(srt, line = c(1,3,5), pos = 'top-left', style = c('b','i'), col = 'red')
Write the srt file to the system.
srt.write(srt, filename)
srt.write(srt, filename)
srt |
vector. The srt file read by |
filename |
Either a character string naming a file or a connection open for writing. |
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') # Postpone subtitles 3 seconds later srt <- srt.shift(srt, time_shifted = 3) # Save and cover original "movie.srt" file srt.write(srt, filename = file.path(tempdir(), "movie.srt"))
srt_path <- system.file("extdata", "movie.srt", package="SRTtools") srt <- srt.read(srt_path, encoding = 'utf-8') # Postpone subtitles 3 seconds later srt <- srt.shift(srt, time_shifted = 3) # Save and cover original "movie.srt" file srt.write(srt, filename = file.path(tempdir(), "movie.srt"))
Srt file is a common subtitle format for videos, it contains subtitle and when the subtitle showed. This package is for ealign time of srt file, and also change color, style and position of subtitle in videos, the srt file will be read as a vector into R, and can be write into srt file after modified using this package.
Jim Chen