TSDuck v3.38-3675
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::SubRipGenerator Class Reference

Generate subtitles in SubRip format (aka SRT). More...

#include <tsSubRipGenerator.h>

Public Member Functions

 SubRipGenerator (const fs::path &fileName=UString(), Report &report=(ts::NullReport::Instance()))
 Constructor.
 
 SubRipGenerator (std::ostream *stream)
 Constructor.
 
 ~SubRipGenerator ()
 Destructor.
 
template<class Rep1 , class Period1 , class Rep2 , class Period2 >
void addFrame (const cn::duration< Rep1, Period1 > &showTimestamp, const cn::duration< Rep2, Period2 > &hideTimestamp, const UString &line)
 Add a one-line subtitle frame.
 
template<class Rep1 , class Period1 , class Rep2 , class Period2 >
void addFrame (const cn::duration< Rep1, Period1 > &showTimestamp, const cn::duration< Rep2, Period2 > &hideTimestamp, const UStringList &lines)
 Add a multi-lines subtitle frame.
 
void close ()
 Close the generator.
 
int frameCount () const
 Get the number of generated frames fo far.
 
bool isOpen ()
 Check if the generator is open and ready to output frames.
 
bool open (const fs::path &fileName, Report &report=(ts::NullReport::Instance()))
 Open or re-open the generator to a new file.
 
bool setStream (std::ostream *stream)
 Open or re-open the generator to a new text stream.
 

Static Public Member Functions

template<class Rep1 , class Period1 , class Rep2 , class Period2 >
static UString FormatDuration (const cn::duration< Rep1, Period1 > &showTimestamp, const cn::duration< Rep2, Period2 > &hideTimestamp)
 Format a duration as SRT header.
 
template<class Rep , class Period >
static UString FormatTime (const cn::duration< Rep, Period > &timestamp)
 Format a timestamp as SRT time.
 

Detailed Description

Generate subtitles in SubRip format (aka SRT).

Constructor & Destructor Documentation

◆ SubRipGenerator() [1/2]

ts::SubRipGenerator::SubRipGenerator ( const fs::path &  fileName = UString(),
Report report = (ts::NullReport::Instance()) 
)
explicit

Constructor.

Parameters
[in]fileNameOptional output file name. If non-empty, the file is created and open. Use isOpen() to check if the file was correctly created.
[in,out]reportWhere to report errors.

◆ SubRipGenerator() [2/2]

ts::SubRipGenerator::SubRipGenerator ( std::ostream *  stream)
explicit

Constructor.

Parameters
[in]streamOutput text stream. The generator is considered "open" if stream is not zero.

Member Function Documentation

◆ open()

bool ts::SubRipGenerator::open ( const fs::path &  fileName,
Report report = (ts::NullReport::Instance()) 
)

Open or re-open the generator to a new file.

The previous file is closed.

Parameters
[in]fileNameOutput file name.
[in,out]reportWhere to report errors.
Returns
True if the file was correctly created and open, false otherwise.

◆ setStream()

bool ts::SubRipGenerator::setStream ( std::ostream *  stream)

Open or re-open the generator to a new text stream.

The previous file is closed.

Parameters
[in]streamOutput text stream.
Returns
True if stream is not zero, false otherwise.

◆ isOpen()

bool ts::SubRipGenerator::isOpen ( )
inline

Check if the generator is open and ready to output frames.

Returns
True if the generator is open and ready.

◆ addFrame() [1/2]

template<class Rep1 , class Period1 , class Rep2 , class Period2 >
void ts::SubRipGenerator::addFrame ( const cn::duration< Rep1, Period1 > &  showTimestamp,
const cn::duration< Rep2, Period2 > &  hideTimestamp,
const UStringList lines 
)

Add a multi-lines subtitle frame.

Parameters
[in]showTimestampShow frame at this timestamp (from start of stream)
[in]hideTimestampHide frame at this timestamp (from start of stream)
[in]linesText lines.

◆ addFrame() [2/2]

template<class Rep1 , class Period1 , class Rep2 , class Period2 >
void ts::SubRipGenerator::addFrame ( const cn::duration< Rep1, Period1 > &  showTimestamp,
const cn::duration< Rep2, Period2 > &  hideTimestamp,
const UString line 
)
inline

Add a one-line subtitle frame.

Parameters
[in]showTimestampShow frame at this timestamp (from start of stream)
[in]hideTimestampHide frame at this timestamp (from start of stream)
[in]lineText line.

◆ frameCount()

int ts::SubRipGenerator::frameCount ( ) const
inline

Get the number of generated frames fo far.

Returns
The number of generated frames fo far.

◆ FormatTime()

template<class Rep , class Period >
static UString ts::SubRipGenerator::FormatTime ( const cn::duration< Rep, Period > &  timestamp)
static

Format a timestamp as SRT time.

Parameters
[in]timestampTimestamp in milliseconds.
Returns
SRT formatted time.

◆ FormatDuration()

template<class Rep1 , class Period1 , class Rep2 , class Period2 >
static UString ts::SubRipGenerator::FormatDuration ( const cn::duration< Rep1, Period1 > &  showTimestamp,
const cn::duration< Rep2, Period2 > &  hideTimestamp 
)
inlinestatic

Format a duration as SRT header.

Parameters
[in]showTimestampShow frame at this timestamp (in ms from start of stream)
[in]hideTimestampHide frame at this timestamp (in ms from start of stream)
Returns
SRT formatted duration.

The documentation for this class was generated from the following file: