AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
avtranscoder::Transcoder Class Reference

A Transcoder manages a list of streams, and process a transcode to create an output media file. More...

#include <Transcoder.hpp>

Public Member Functions

 Transcoder (IOutputFile &outputFile)
 
 ~Transcoder ()
 
void add (const std::string &filename)
 Add all streams of the file with the given filename. All the streams will be rewrapped. More...
 
void add (const std::string &filename, const size_t streamIndex, const std::string &profileName="", const float offset=0)
 Add a stream and set a profile. More...
 
void add (const std::string &filename, const size_t streamIndex, const std::string &profileName, ICodec &codec, const float offset=0)
 
void add (const std::string &filename, const size_t streamIndex, const ProfileLoader::Profile &profile, const float offset=0)
 Add a stream and set a custom profile. More...
 
void add (const std::string &filename, const size_t streamIndex, const ProfileLoader::Profile &profile, ICodec &codec, const float offset=0)
 
void add (const std::string &filename, const size_t streamIndex, const int subStreamIndex, const std::string &profileName="", const float offset=0)
 Add a stream and set a profile. More...
 
void add (const std::string &filename, const size_t streamIndex, const int subStreamIndex, const std::string &profileName, ICodec &codec, const float offset=0)
 
void add (const std::string &filename, const size_t streamIndex, const int subStreamIndex, const ProfileLoader::Profile &profile, const float offset=0)
 Add a stream and set a custom profile. More...
 
void add (const std::string &filename, const size_t streamIndex, const int subStreamIndex, const ProfileLoader::Profile &profile, ICodec &codec, const float offset=0)
 
void add (StreamTranscoder &streamTranscoder)
 Add the stream. More...
 
void preProcessCodecLatency ()
 Initialize all added streams, processing codec latency. More...
 
bool processFrame ()
 Process the next frame of all streams. More...
 
ProcessStat process (IProgress &progress)
 Process all the streams, and ended the process depending on the transcode politic. More...
 
ProcessStat process ()
 Call process with no display of progression. More...
 
std::vector< StreamTranscoder * > & getStreamTranscoders ()
 Return the list of streams added to the transcoder. More...
 
StreamTranscodergetStreamTranscoder (size_t streamIndex) const
 
EProcessMethod getProcessMethod () const
 Get current processMethod. More...
 
void setProcessMethod (const EProcessMethod eProcessMethod, const size_t indexBasedStream=0, const double outputDuration=0)
 Set the transcoding policy. More...
 

Private Member Functions

 Transcoder (const Transcoder &transcoder)
 
Transcoderoperator= (const Transcoder &transcoder)
 
void addRewrapStream (const std::string &filename, const size_t streamIndex, const float offset)
 
void addTranscodeStream (const std::string &filename, const size_t streamIndex, const int subStreamIndex, const float offset)
 
void addTranscodeStream (const std::string &filename, const size_t streamIndex, const int subStreamIndex, const ProfileLoader::Profile &profile, const float offset=0)
 
void addDummyStream (const ProfileLoader::Profile &profile, const ICodec &codec)
 
InputFileaddInputFile (const std::string &filename, const int streamIndex, const float offset)
 
ProfileLoader::Profile getProfileFromFile (InputFile &inputFile, const size_t streamIndex)
 The function analyses the inputFile. More...
 
float getStreamDuration (size_t indexStream) const
 Get the duration of the stream, in seconds. More...
 
float getMinTotalDuration () const
 Get the duration of the shortest stream, in seconds. More...
 
float getMaxTotalDuration () const
 Get the duration of the longest stream, in seconds. More...
 
float getExpectedOutputDuration () const
 Get the expected duration of the output program. More...
 
float getCurrentOutputDuration () const
 Get the current duration of the output program. More...
 
void manageSwitchToGenerator ()
 Set for each StreamTranscoder if it can switch to generator at the end. More...
 
void fillProcessStat (ProcessStat &processStat)
 Fill the given ProcessStat to summarize the process. More...
 

Private Attributes

IOutputFile_outputFile
 The output media file after process (has link) More...
 
std::vector< InputFile * > _inputFiles
 The list of input files which contain added streams (has ownership) More...
 
std::vector< StreamTranscoder * > _streamTranscoders
 All streams of the output media file after process. More...
 
std::vector< StreamTranscoder * > _streamTranscodersAllocated
 Streams allocated inside the Transcoder (has ownership) More...
 
ProfileLoader _profileLoader
 Objet to get existing profiles, and add new ones for the Transcoder. More...
 
EProcessMethod _eProcessMethod
 Processing policy. More...
 
size_t _mainStreamIndex
 Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream. More...
 
float _outputDuration
 

Detailed Description

A Transcoder manages a list of streams, and process a transcode to create an output media file.

Definition at line 42 of file Transcoder.hpp.

Constructor & Destructor Documentation

avtranscoder::Transcoder::Transcoder ( const Transcoder transcoder)
private
avtranscoder::Transcoder::Transcoder ( IOutputFile outputFile)
Note
Set FFmpeg log level to quite.

Definition at line 13 of file Transcoder.cpp.

avtranscoder::Transcoder::~Transcoder ( )

Definition at line 25 of file Transcoder.cpp.

References _inputFiles, and _streamTranscodersAllocated.

Member Function Documentation

void avtranscoder::Transcoder::add ( const std::string &  filename)

Add all streams of the file with the given filename. All the streams will be rewrapped.

Note
Currently we rewrap only the video and the audio streams. The streams with an other type are skipped.

Definition at line 38 of file Transcoder.cpp.

References addInputFile(), addRewrapStream(), avtranscoder::InputFile::getProperties(), avtranscoder::FileProperties::getStreamProperties(), avtranscoder::FileProperties::getStreamPropertiesWithIndex(), and avtranscoder::StreamProperties::getStreamType().

Referenced by add(), and parseConfigFile().

void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const std::string &  profileName = "",
const float  offset = 0 
)

Add a stream and set a profile.

Note
If profileName is empty, rewrap.
offset in seconds If offset is positive, the transcoder will generate black images or silence (depending on the type of stream) before the stream to process. If offset is negative, the transcoder will seek in the stream and start process at this specific time.

Definition at line 53 of file Transcoder.cpp.

References _profileLoader, add(), addRewrapStream(), and avtranscoder::ProfileLoader::getProfile().

void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const std::string &  profileName,
ICodec codec,
const float  offset = 0 
)
void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const ProfileLoader::Profile profile,
const float  offset = 0 
)

Add a stream and set a custom profile.

Note
Profile will be updated, be sure to pass unique profile name.

Definition at line 93 of file Transcoder.cpp.

References addTranscodeStream().

void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const ProfileLoader::Profile profile,
ICodec codec,
const float  offset = 0 
)

Definition at line 103 of file Transcoder.cpp.

References addDummyStream(), and addTranscodeStream().

void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const int  subStreamIndex,
const std::string &  profileName = "",
const float  offset = 0 
)

Add a stream and set a profile.

Note
If profileName is empty, rewrap.
If subStreamIndex is negative, no substream is selected it's the stream.

Definition at line 118 of file Transcoder.cpp.

References _profileLoader, add(), addRewrapStream(), addTranscodeStream(), and avtranscoder::ProfileLoader::getProfile().

void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const int  subStreamIndex,
const std::string &  profileName,
ICodec codec,
const float  offset = 0 
)
Note
If filename is empty, add a generated stream.
If filename is empty, profileName can't be empty (no sens to rewrap a generated stream).

Definition at line 149 of file Transcoder.cpp.

References _profileLoader, add(), addRewrapStream(), addTranscodeStream(), and avtranscoder::ProfileLoader::getProfile().

void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const int  subStreamIndex,
const ProfileLoader::Profile profile,
const float  offset = 0 
)

Add a stream and set a custom profile.

Note
Profile will be updated, be sure to pass unique profile name.
If subStreamIndex is negative, no substream is selected it's the stream.

Definition at line 181 of file Transcoder.cpp.

References add(), and addTranscodeStream().

void avtranscoder::Transcoder::add ( const std::string &  filename,
const size_t  streamIndex,
const int  subStreamIndex,
const ProfileLoader::Profile profile,
ICodec codec,
const float  offset = 0 
)
Note
If filename is empty, add a generated stream.

Definition at line 198 of file Transcoder.cpp.

References add(), addDummyStream(), and addTranscodeStream().

void avtranscoder::Transcoder::add ( StreamTranscoder streamTranscoder)

Add the stream.

Definition at line 218 of file Transcoder.cpp.

References _streamTranscoders.

InputFile * avtranscoder::Transcoder::addInputFile ( const std::string &  filename,
const int  streamIndex,
const float  offset 
)
private
void avtranscoder::Transcoder::addRewrapStream ( const std::string &  filename,
const size_t  streamIndex,
const float  offset 
)
private
void avtranscoder::Transcoder::addTranscodeStream ( const std::string &  filename,
const size_t  streamIndex,
const int  subStreamIndex,
const float  offset 
)
private

Definition at line 344 of file Transcoder.cpp.

References avtranscoder::constants::avProfileChannel, and getProfileFromFile().

Referenced by add().

void avtranscoder::Transcoder::addTranscodeStream ( const std::string &  filename,
const size_t  streamIndex,
const int  subStreamIndex,
const ProfileLoader::Profile profile,
const float  offset = 0 
)
private
float avtranscoder::Transcoder::getCurrentOutputDuration ( ) const
private

Get the current duration of the output program.

Note
Returns the duration of the smallest stream.
Returns
-1 if there is no output stream.

Definition at line 545 of file Transcoder.cpp.

References _outputFile, _streamTranscoders, avtranscoder::IOutputFile::getStream(), and avtranscoder::IOutputStream::getStreamDuration().

Referenced by process().

float avtranscoder::Transcoder::getExpectedOutputDuration ( ) const
private
float avtranscoder::Transcoder::getMaxTotalDuration ( ) const
private

Get the duration of the longest stream, in seconds.

Definition at line 516 of file Transcoder.cpp.

References _streamTranscoders, and getStreamDuration().

Referenced by getExpectedOutputDuration(), and manageSwitchToGenerator().

float avtranscoder::Transcoder::getMinTotalDuration ( ) const
private

Get the duration of the shortest stream, in seconds.

Definition at line 506 of file Transcoder.cpp.

References _streamTranscoders, and getStreamDuration().

Referenced by getExpectedOutputDuration(), and manageSwitchToGenerator().

EProcessMethod avtranscoder::Transcoder::getProcessMethod ( ) const
inline

Get current processMethod.

See also
EProcessMethod

Definition at line 162 of file Transcoder.hpp.

ProfileLoader::Profile avtranscoder::Transcoder::getProfileFromFile ( InputFile inputFile,
const size_t  streamIndex 
)
private
float avtranscoder::Transcoder::getStreamDuration ( size_t  indexStream) const
private

Get the duration of the stream, in seconds.

Note
If the stream is a generator, return limit of double.

Definition at line 501 of file Transcoder.cpp.

References _streamTranscoders.

Referenced by getExpectedOutputDuration(), getMaxTotalDuration(), and getMinTotalDuration().

StreamTranscoder& avtranscoder::Transcoder::getStreamTranscoder ( size_t  streamIndex) const
inline
Parameters
streamIndexcareful about the order of stream insertion of the Transcoder.
Returns
a reference to a stream manage by the Transcoder.

Definition at line 156 of file Transcoder.hpp.

std::vector<StreamTranscoder*>& avtranscoder::Transcoder::getStreamTranscoders ( )
inline

Return the list of streams added to the transcoder.

Definition at line 150 of file Transcoder.hpp.

Transcoder& avtranscoder::Transcoder::operator= ( const Transcoder transcoder)
private
void avtranscoder::Transcoder::preProcessCodecLatency ( )

Initialize all added streams, processing codec latency.

Note
This can be called several times with no side effects.
Can take a little bit of time.

Definition at line 223 of file Transcoder.cpp.

References _streamTranscoders, and LOG_DEBUG.

Referenced by process().

ProcessStat avtranscoder::Transcoder::process ( IProgress progress)

Process all the streams, and ended the process depending on the transcode politic.

Note
The function manages all process: init(), beginWrap(), processFrame()s, and endWrap().
Parameters
progresschoose a progress, or create your own in C++ or in bindings by inherit IProgress class.
Returns
ProcessStat: object with statistics of the process for each stream.
See also
IProgress

Definition at line 272 of file Transcoder.cpp.

References _outputFile, _streamTranscoders, avtranscoder::IOutputFile::beginWrap(), avtranscoder::eJobStatusCancel, avtranscoder::IOutputFile::endWrap(), fillProcessStat(), getCurrentOutputDuration(), getExpectedOutputDuration(), LOG_DEBUG, LOG_INFO, manageSwitchToGenerator(), preProcessCodecLatency(), processFrame(), and avtranscoder::IProgress::progress().

Referenced by main().

ProcessStat avtranscoder::Transcoder::process ( )

Call process with no display of progression.

Definition at line 266 of file Transcoder.cpp.

bool avtranscoder::Transcoder::processFrame ( )

Process the next frame of all streams.

Returns
if a frame was processed or not.

Definition at line 232 of file Transcoder.cpp.

References _streamTranscoders, avtranscoder::StreamTranscoder::eProcessCaseGenerator, LOG_DEBUG, LOG_INFO, and LOG_WARN.

Referenced by process().

void avtranscoder::Transcoder::setProcessMethod ( const EProcessMethod  eProcessMethod,
const size_t  indexBasedStream = 0,
const double  outputDuration = 0 
)

Set the transcoding policy.

Note
By default eProcessMethodBasedOnStream at index 0.
Parameters
indexBasedStreamin case of process method eProcessMethodBasedOnStream, stop transcode at the end of the indicated stream.
outputDurationin case of process method eProcessMethodBasedOnDuration, stop transcode at the end of the indicated duration.

Definition at line 326 of file Transcoder.cpp.

References _eProcessMethod, _mainStreamIndex, and _outputDuration.

Referenced by main().

Field Documentation

EProcessMethod avtranscoder::Transcoder::_eProcessMethod
private

Processing policy.

Definition at line 241 of file Transcoder.hpp.

Referenced by getExpectedOutputDuration(), manageSwitchToGenerator(), and setProcessMethod().

std::vector<InputFile*> avtranscoder::Transcoder::_inputFiles
private

The list of input files which contain added streams (has ownership)

Definition at line 234 of file Transcoder.hpp.

Referenced by addInputFile(), and ~Transcoder().

size_t avtranscoder::Transcoder::_mainStreamIndex
private

Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream.

Definition at line 243 of file Transcoder.hpp.

Referenced by getExpectedOutputDuration(), manageSwitchToGenerator(), and setProcessMethod().

float avtranscoder::Transcoder::_outputDuration
private

Duration of output media used to stop the process of transcode in case of

Definition at line 244 of file Transcoder.hpp.

Referenced by getExpectedOutputDuration(), manageSwitchToGenerator(), and setProcessMethod().

IOutputFile& avtranscoder::Transcoder::_outputFile
private

The output media file after process (has link)

Definition at line 233 of file Transcoder.hpp.

Referenced by addDummyStream(), addRewrapStream(), addTranscodeStream(), getCurrentOutputDuration(), and process().

ProfileLoader avtranscoder::Transcoder::_profileLoader
private

Objet to get existing profiles, and add new ones for the Transcoder.

Definition at line 239 of file Transcoder.hpp.

Referenced by add(), addDummyStream(), and addTranscodeStream().

std::vector<StreamTranscoder*> avtranscoder::Transcoder::_streamTranscoders
private
std::vector<StreamTranscoder*> avtranscoder::Transcoder::_streamTranscodersAllocated
private

Streams allocated inside the Transcoder (has ownership)

Definition at line 237 of file Transcoder.hpp.

Referenced by addDummyStream(), addRewrapStream(), addTranscodeStream(), and ~Transcoder().


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