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

#include <tsSubRipGenerator.h>

Public Member Functions

 SubRipGenerator (const fs::path &file_name=UString(), Report &report=(ts::NullReport::Instance()))
 SubRipGenerator (std::ostream *stream)
 ~SubRipGenerator ()
template<class Rep1, class Period1, class Rep2, class Period2>
void addFrame (const cn::duration< Rep1, Period1 > &show_timestamp, const cn::duration< Rep2, Period2 > &hide_timestamp, const UString &line)
template<class Rep1, class Period1, class Rep2, class Period2>
void addFrame (const cn::duration< Rep1, Period1 > &show_timestamp, const cn::duration< Rep2, Period2 > &hide_timestamp, const UStringList &lines)
void close ()
int frameCount () const
bool isOpen ()
bool open (const fs::path &file_name, Report &report=(ts::NullReport::Instance()))
bool setStream (std::ostream *stream)

Static Public Member Functions

template<class Rep1, class Period1, class Rep2, class Period2>
static UString FormatDuration (const cn::duration< Rep1, Period1 > &show_timestamp, const cn::duration< Rep2, Period2 > &hide_timestamp)
template<class Rep, class Period>
static UString FormatTime (const cn::duration< Rep, Period > &timestamp)

Detailed Description

Generate subtitles in SubRip format (aka SRT).

Constructor & Destructor Documentation

◆ SubRipGenerator() [1/2]

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

Constructor.

Parameters
[in]file_nameOptional 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.

◆ ~SubRipGenerator()

ts::SubRipGenerator::~SubRipGenerator ( )

Destructor.

Member Function Documentation

◆ open()

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

Open or re-open the generator to a new file. The previous file is closed.

Parameters
[in]file_nameOutput 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.

◆ close()

void ts::SubRipGenerator::close ( )

Close the generator.

◆ 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 > & show_timestamp,
const cn::duration< Rep2, Period2 > & hide_timestamp,
const UStringList & lines )

Add a multi-lines subtitle frame.

Parameters
[in]show_timestampShow frame at this timestamp (from start of stream)
[in]hide_timestampHide 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 > & show_timestamp,
const cn::duration< Rep2, Period2 > & hide_timestamp,
const UString & line )
inline

Add a one-line subtitle frame.

Parameters
[in]show_timestampShow frame at this timestamp (from start of stream)
[in]hide_timestampHide 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>
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>
UString ts::SubRipGenerator::FormatDuration ( const cn::duration< Rep1, Period1 > & show_timestamp,
const cn::duration< Rep2, Period2 > & hide_timestamp )
inlinestatic

Format a duration as SRT header.

Parameters
[in]show_timestampShow frame at this timestamp (in ms from start of stream)
[in]hide_timestampHide 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: