Package 'SRTtools'

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

Help Index


Retrieve Subtitle Text

Description

Retrieve all the subtitle text content from a srt file

Usage

srt.content(srt)

Arguments

srt

vector. The srt file read by srt.read.

See Also

srt.read

Examples

srt_path <- system.file("extdata", "movie.srt", package="SRTtools")
srt <- srt.read(srt_path, encoding = 'utf-8')

srt.content(srt)

Insert new dialog

Description

Insert new dialog to subtitles by specific index

Usage

srt.insert(srt, index, time, text)

Arguments

srt

vector. The srt file read by srt.read.

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.

See Also

srt.read

Examples

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 srt file

Description

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.

Usage

srt.read(file, encoding = "utf-8")

Arguments

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'.

See Also

readLines

Examples

# read a ANSI srt file
srt_path <- system.file("extdata", "movie.srt", package="SRTtools")
srt <- srt.read(srt_path, encoding = 'utf-8')

Remove dialog

Description

Remove unwanted dialog from subtitles by specific index

Usage

srt.remove(srt, index)

Arguments

srt

vector. The srt file read by srt.read.

index

integer. The index of unwanted dialog .

See Also

srt.read

Examples

srt_path <- system.file("extdata", "movie.srt", package="SRTtools")
srt <- srt.read(srt_path, encoding = 'utf-8')
srt.remove(srt, index = 10)

Search Index By KeyWord

Description

Return the subtitle index by specific keyword

Usage

srt.search(srt, key_word)

Arguments

srt

vector. The srt file read by srt.read.

key_word

character. The key word want to be searched in subtitles.

See Also

srt.read

Examples

srt_path <- system.file("extdata", "movie.srt", package="SRTtools")
srt <- srt.read(srt_path, encoding = 'utf-8')
srt.search(srt, key_word = "captain")

Re-synchronize Srt File

Description

Shift a srt file with specific time.

Usage

srt.shift(srt, time_shifted)

Arguments

srt

vector. The srt file read by srt.read.

time_shifted

numeric. The time that srt file want to be shifted (in seconds).

See Also

srt.read

Examples

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 Style of Subtitle

Description

Change subtitle style or posistion by specific subtitle index.

Usage

srt.style(srt, line = "all", pos = "None", style = "None",
  col = "None")

Arguments

srt

vector. The srt file read by srt.read.

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 'bottom-left', 'bottom-center', 'bottom-right', 'middle-left', 'middle-center', 'middle-right', 'top-left', 'top-center', 'top-right' and 'center'.

style

character vector. The styles that subtitle applied, 'u' for bottom line, 'i' for italic, 'b' for bold, 's' for strikethrough.

col

character. The color that subtitle applied.

See Also

srt.read

Examples

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 Output

Description

Write the srt file to the system.

Usage

srt.write(srt, filename)

Arguments

srt

vector. The srt file read by srt.read.

filename

Either a character string naming a file or a connection open for writing.

See Also

srt.read

Examples

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"))

Adjust srt file to get better experience in watching movie.

Description

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.

Author(s)

Jim Chen