14     : _outputFile(outputFile)
 
   16     , _streamTranscoders()
 
   17     , _streamTranscodersAllocated()
 
   18     , _profileLoader(true)
 
   40     const int streamIndex = -1;
 
   41     const float offset = 0;
 
   44     for(
size_t index = 0; index < inputStreams.size(); ++index)
 
   48         if(streamType == AVMEDIA_TYPE_VIDEO || streamType == AVMEDIA_TYPE_AUDIO)
 
   53 void Transcoder::add(
const std::string& filename, 
const size_t streamIndex, 
const std::string& profileName,
 
   57     if(profileName.length() == 0)
 
   60         if(filename.length() == 0)
 
   61             throw std::runtime_error(
"Can't re-wrap a stream without filename indicated");
 
   69         add(filename, streamIndex, transcodeProfile, offset);
 
   73 void Transcoder::add(
const std::string& filename, 
const size_t streamIndex, 
const std::string& profileName, 
ICodec& codec,
 
   77     if(profileName.length() == 0)
 
   80         if(filename.length() == 0)
 
   81             throw std::runtime_error(
"Can't re-wrap a stream without filename indicated");
 
   89         add(filename, streamIndex, transcodeProfile, codec, offset);
 
   97     if(!filename.length())
 
   98         throw std::runtime_error(
"Can't transcode a stream without filename indicated");
 
  104                      ICodec& codec, 
const float offset)
 
  107     if(!filename.length())
 
  118 void Transcoder::add(
const std::string& filename, 
const size_t streamIndex, 
const int subStreamIndex,
 
  119                      const std::string& profileName, 
const float offset)
 
  122     if(subStreamIndex < 0)
 
  124         add(filename, streamIndex, profileName, offset);
 
  128     if(profileName.length() == 0)
 
  131         if(subStreamIndex < 0)
 
  145         add(filename, streamIndex, subStreamIndex, transcodeProfile, offset);
 
  149 void Transcoder::add(
const std::string& filename, 
const size_t streamIndex, 
const int subStreamIndex,
 
  150                      const std::string& profileName, 
ICodec& codec, 
const float offset)
 
  153     if(subStreamIndex < 0)
 
  155         add(filename, streamIndex, profileName, codec);
 
  160     if(profileName.length() == 0)
 
  163         if(subStreamIndex < 0)
 
  177         add(filename, streamIndex, subStreamIndex, transcodeProfile, codec, offset);
 
  181 void Transcoder::add(
const std::string& filename, 
const size_t streamIndex, 
const int subStreamIndex,
 
  185     if(subStreamIndex < 0)
 
  187         add(filename, streamIndex, profile, offset);
 
  192     if(!filename.length())
 
  193         throw std::runtime_error(
"Can't transcode a stream without filename indicated");
 
  198 void Transcoder::add(
const std::string& filename, 
const size_t streamIndex, 
const int subStreamIndex,
 
  202     if(subStreamIndex < 0)
 
  204         add(filename, streamIndex, profile);
 
  209     if(!filename.length())
 
  238     size_t nbStreamProcessStatusFailed = 0;
 
  244             LOG_WARN(
"Failed to process stream " << streamIndex)
 
  245             ++nbStreamProcessStatusFailed;
 
  254             --nbStreamsWithoutGenerator;
 
  258     if(nbStreamsWithoutGenerator != 0 && nbStreamsWithoutGenerator == nbStreamProcessStatusFailed)
 
  260         LOG_INFO(
"End of process because all streams (except generators) failed to process a new frame.")
 
  275         throw std::runtime_error(
"Missing input streams in transcoder");
 
  286     LOG_INFO(
"The expected output duration of the program will be " << expectedOutputDuration << 
"s.")
 
  289     bool frameProcessed = 
true;
 
  290     while(frameProcessed)
 
  299         if(progress.
progress((progressDuration > expectedOutputDuration) ? expectedOutputDuration : progressDuration,
 
  302             LOG_INFO(
"End of process because the job was canceled.")
 
  307         if(progressDuration >= expectedOutputDuration)
 
  309             LOG_INFO(
"End of process because the output program duration (" 
  310                      << progressDuration << 
"s) is equal or upper than " << expectedOutputDuration << 
"s.")
 
  317     LOG_INFO(
"End of process: " << frame << 
" frames processed")
 
  327                                   const double outputDuration)
 
  336     LOG_INFO(
"Add rewrap stream from file '" << filename << 
"' / index=" << streamIndex << 
" / offset=" << offset << 
"s")
 
  353     if(it != profile.end())
 
  366     LOG_INFO(
"Add transcode stream from file '" 
  367              << filename << 
"' / index=" << streamIndex << 
" / channel=" << subStreamIndex
 
  373     switch(referenceFile->getStream(streamIndex).getProperties().getStreamType())
 
  375         case AVMEDIA_TYPE_VIDEO:
 
  376         case AVMEDIA_TYPE_AUDIO:
 
  383         case AVMEDIA_TYPE_DATA:
 
  384         case AVMEDIA_TYPE_SUBTITLE:
 
  385         case AVMEDIA_TYPE_ATTACHMENT:
 
  388             throw std::runtime_error(
"unsupported media type in transcode setup");
 
  399     LOG_INFO(
"Add generated stream with codec '" 
  414             if(((*it)->getFilename() == filename) && !(*it)->getStream(streamIndex).isActivated())
 
  416                 referenceFile = (*it);
 
  417                 LOG_DEBUG(
"Get instance of InputFile from '" << filename << 
"'")
 
  425         LOG_DEBUG(
"New instance of InputFile from '" << filename << 
"'")
 
  443     return referenceFile;
 
  453         case AVMEDIA_TYPE_VIDEO:
 
  455             videoProperties = 
dynamic_cast<const VideoProperties*
>(streamProperties);
 
  458         case AVMEDIA_TYPE_AUDIO:
 
  460             audioProperties = 
dynamic_cast<const AudioProperties*
>(streamProperties);
 
  473     if(videoProperties != NULL)
 
  478         std::stringstream ss;
 
  479         ss << videoProperties->
getFps();
 
  485     else if(audioProperties != NULL)
 
  490         std::stringstream ss;
 
  508     float minTotalDuration = std::numeric_limits<float>::max();
 
  513     return minTotalDuration;
 
  518     float maxTotalDuration = 0;
 
  523     return maxTotalDuration;
 
  539             return std::numeric_limits<float>::max();
 
  547     float currentOutputDuration = -1;
 
  551         if(currentOutputDuration == -1)
 
  552             currentOutputDuration = currentStreamDuration;
 
  553         else if(currentStreamDuration < currentOutputDuration)
 
  554             currentOutputDuration = currentStreamDuration;
 
  556     return currentOutputDuration;
 
  603         if(inputStream == NULL)
 
  605             LOG_WARN(
"Cannot process statistics of generated stream.")
 
  611             case AVMEDIA_TYPE_VIDEO:
 
  617                     const AVCodecContext& encoderContext = encoder->getCodec().getAVCodecContext();
 
  618                     if(encoderContext.coded_frame && (encoderContext.flags & CODEC_FLAG_PSNR))
 
  620                         videoStat.setQuality(encoderContext.coded_frame->quality);
 
  621                         videoStat.setPSNR(encoderContext.coded_frame->error[0] /
 
  622                                           (encoderContext.width * encoderContext.height * 255.0 * 255.0));
 
  628             case AVMEDIA_TYPE_AUDIO:
 
  635                 LOG_WARN(
"No process statistics for stream at index: " << streamIndex << 
" (AVMediaType = " << mediaType
 
void loadProfile(const std::string &avProfileFileName)
Load the profile defines in the given file. 
 
Base class of Progress. Inherit this class to have your own way to manage a progress bar...
 
ProcessStat contains statistics given after the process. 
 
AVMediaType getStreamType() const 
 
const std::string avProfileFrameRate
 
std::vector< InputFile * > _inputFiles
The list of input files which contain added streams (has ownership) 
 
void manageSwitchToGenerator()
Set for each StreamTranscoder if it can switch to generator at the end. 
 
virtual EJobStatus progress(const double processedDuration, const double programDuration)=0
Manage the progress. 
 
std::vector< StreamTranscoder * > _streamTranscodersAllocated
Streams allocated inside the Transcoder (has ownership) 
 
IOutputfile is the interface to wrap and write medias. It can be overloaded to integrate custom wrapp...
 
std::string getCodecName() const 
 
bool hasProfile(const Profile &profile) const 
 
std::string getPixelFormatName() const 
 
virtual bool beginWrap()=0
Write the header of file (if necessary) 
 
float getMaxTotalDuration() const 
Get the duration of the longest stream, in seconds. 
 
void addTranscodeStream(const std::string &filename, const size_t streamIndex, const int subStreamIndex, const float offset)
 
std::map< std::string, std::string > Profile
 
const std::string avProfileTypeAudio
 
const std::string avProfileIdentificator
 
const std::string avProfileIdentificatorHuman
 
const std::string avProfileSampleRate
 
float getCurrentOutputDuration() const 
Get the current duration of the output program. 
 
const Profile & getProfile(const std::string &avProfileIdentificator) const 
 
const std::string avProfilePixelFormat
 
const std::vector< avtranscoder::StreamProperties * > getStreamProperties() const 
 
const std::string avProfileTypeVideo
 
const avtranscoder::StreamProperties & getStreamPropertiesWithIndex(const size_t streamIndex) const 
 
float getExpectedOutputDuration() const 
Get the expected duration of the output program. 
 
EProcessMethod
Enum to set a policy of how we manage the process in case of several streams. eProcessMethodShortest:...
 
virtual bool endWrap()=0
Write the footer of file (if necessary) 
 
void add(const std::string &filename)
Add all streams of the file with the given filename. All the streams will be rewrapped. 
 
EProcessMethod _eProcessMethod
Processing policy. 
 
float getMinTotalDuration() const 
Get the duration of the shortest stream, in seconds. 
 
float getStreamDuration(size_t indexStream) const 
Get the duration of the stream, in seconds. 
 
size_t getNbChannels() const 
 
std::vector< StreamTranscoder * > _streamTranscoders
All streams of the output media file after process. 
 
size_t getSampleRate() const 
 
ProfileLoader _profileLoader
Objet to get existing profiles, and add new ones for the Transcoder. 
 
virtual float getStreamDuration() const =0
 
bool processFrame()
Process the next frame of all streams. 
 
void preProcessCodecLatency()
Initialize all added streams, processing codec latency. 
 
float getFps() const 
Corresponds to the 'fps' returned by ffprobe. fps = the average framerate that has come from the AVSt...
 
void fillProcessStat(ProcessStat &processStat)
Fill the given ProcessStat to summarize the process. 
 
std::string getCodecName() const 
 
ProcessStat process()
Call process with no display of progression. 
 
void addVideoStat(const size_t streamIndex, const VideoStat &videoStat)
 
std::string getSampleFormatName() const 
 
PixelProperties & getPixelProperties()
 
const std::string avProfileWidth
 
virtual size_t getNbFrames() const =0
 
Statistics related to a video stream. 
 
Virtual based class of properties for all types of stream. 
 
const std::string avProfileHeight
 
ProfileLoader::Profile getProfileFromFile(InputFile &inputFile, const size_t streamIndex)
The function analyses the inputFile. 
 
void addDummyStream(const ProfileLoader::Profile &profile, const ICodec &codec)
 
const std::string avProfileCodec
 
Transcoder(const Transcoder &transcoder)
 
Statistics related to an audio stream. 
 
const std::string avProfileSampleFormat
 
size_t _mainStreamIndex
Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream. 
 
void setProcessMethod(const EProcessMethod eProcessMethod, const size_t indexBasedStream=0, const double outputDuration=0)
Set the transcoding policy. 
 
void addAudioStat(const size_t streamIndex, const AudioStat &audioStat)
 
size_t getNbStreams() const 
 
const std::string avProfileChannel
 
const std::string avProfileType
 
Implementation of IProgress, to manage cases when we need an IProgress but don't care of a progress b...
 
IOutputFile & _outputFile
The output media file after process (has link) 
 
void addRewrapStream(const std::string &filename, const size_t streamIndex, const float offset)
 
InputFile * addInputFile(const std::string &filename, const int streamIndex, const float offset)
 
virtual IOutputStream & getStream(const size_t streamIndex)=0
Get the output stream.