Skip to content

Transcoder: call init method to process #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/genericProcessor/genericProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,11 @@ int main( int argc, char** argv )
// set verbose of all stream
transcoder.setVerbose( verbose );
transcoder.setProcessMethod( avtranscoder::eProcessMethodLongest );
transcoder.init();

if( verbose )
std::cout << "start Transcode" << std::endl;

avtranscoder::ConsoleProgress progress;

// video re-wrapping or transcoding if necessary
transcoder.process( progress );

std::cout << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/transcoder/StreamTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ StreamTranscoder::~StreamTranscoder()

void StreamTranscoder::init()
{
// rewrap
// rewrap case: no need to take care of the latency of codec
if( ! _inputEssence )
return;

Expand Down
129 changes: 67 additions & 62 deletions src/AvTranscoder/transcoder/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ Transcoder::Transcoder( OutputFile& outputFile )
, _mainStreamIndex( 0 )
, _verbose( false )
{
// Initialize the OutputFile
_outputFile.setup();

// Print no output from ffmpeg
av_log_set_level( AV_LOG_QUIET );
}

Transcoder::~Transcoder()
Expand Down Expand Up @@ -252,19 +256,17 @@ void Transcoder::init()
bool Transcoder::processFrame()
{
if( _streamTranscoders.size() == 0 )
{
return false;
}

if( _verbose )
std::cout << "process frame" << std::endl;

for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex )
{
if( _verbose )
std::cout << "process stream " << streamIndex << "/" << _streamTranscoders.size() - 1 << std::endl;

bool streamProcessStatus = _streamTranscoders.at( streamIndex )->processFrame();

if( ! streamProcessStatus )
{
_streamTranscoders.clear();
Expand All @@ -276,51 +278,30 @@ bool Transcoder::processFrame()

void Transcoder::process( IProgress& progress )
{
size_t frame = 0;

if( ! _streamTranscoders.size() )
{
if( _streamTranscoders.size() == 0 )
throw std::runtime_error( "missing input streams in transcoder" );
}


manageInfinityStreamFromProcessMethod();

if( _verbose )
std::cout << "begin transcoding" << std::endl;
init();

_outputFile.beginWrap();

double totalDuration = std::numeric_limits<double>::max();
switch( _eProcessMethod )
{
case eProcessMethodShortest :
totalDuration = getMinTotalDuration();
break;
case eProcessMethodLongest :
totalDuration = getMaxTotalDuration();
break;
case eProcessMethodBasedOnStream :
totalDuration = getStreamDuration( _mainStreamIndex );
break;
case eProcessMethodInfinity :
totalDuration = std::numeric_limits<double>::max();
break;
}
double totalDuration = getTotalDurationFromProcessMethod();

if( _verbose )
av_log_set_level( AV_LOG_DEBUG );

while( 1 )
size_t frame = 0;
bool frameProcessed = true;
while( frameProcessed )
{
if( _verbose )
std::cout << "process frame " << frame << std::endl;

bool frameProcessed = processFrame();
if( ! frameProcessed )
break;
frameProcessed = processFrame();

if( progress.progress( _outputFile.getProgressDuration(), totalDuration ) == eJobStatusCancel )
{
break;
}

++frame;
}
Expand All @@ -335,34 +316,6 @@ void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const si
{
_eProcessMethod = eProcessMethod;
_mainStreamIndex = indexBasedStream;

for( size_t i = 0; i < _streamTranscoders.size(); ++i )
{
switch( _eProcessMethod )
{
case eProcessMethodShortest :
if( _streamTranscoders.at( i )->getDuration() == getMinTotalDuration() )
_streamTranscoders.at( i )->setInfinityStream( false );
else
_streamTranscoders.at( i )->setInfinityStream( true );
break;
case eProcessMethodLongest :
if( _streamTranscoders.at( i )->getDuration() == getMaxTotalDuration() )
_streamTranscoders.at( i )->setInfinityStream( false );
else
_streamTranscoders.at( i )->setInfinityStream( true );
break;
case eProcessMethodBasedOnStream :
if( i != _mainStreamIndex )
_streamTranscoders.at( i )->setInfinityStream( true );
else
_streamTranscoders.at( i )->setInfinityStream( false );
break;
case eProcessMethodInfinity :
_streamTranscoders.at( i )->setInfinityStream( true );
break;
}
}
}

void Transcoder::setVerbose( bool verbose )
Expand All @@ -373,6 +326,10 @@ void Transcoder::setVerbose( bool verbose )
(*it)->setVerbose( _verbose );
}
_outputFile.setVerbose( _verbose );

// Print stuff which is only useful for ffmpeg developers.
if( _verbose )
av_log_set_level( AV_LOG_DEBUG );
}

void Transcoder::addRewrapStream( const std::string& filename, const size_t streamIndex )
Expand Down Expand Up @@ -528,4 +485,52 @@ double Transcoder::getMaxTotalDuration() const
return maxTotalDuration;
}

double Transcoder::getTotalDurationFromProcessMethod() const
{
switch( _eProcessMethod )
{
case eProcessMethodShortest :
return getMinTotalDuration();
case eProcessMethodLongest :
return getMaxTotalDuration();
case eProcessMethodBasedOnStream :
return getStreamDuration( _mainStreamIndex );
case eProcessMethodInfinity :
return std::numeric_limits<double>::max();
default:
return getMaxTotalDuration();
}
}

void Transcoder::manageInfinityStreamFromProcessMethod()
{
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
{
switch( _eProcessMethod )
{
case eProcessMethodShortest :
if( _streamTranscoders.at( i )->getDuration() == getMinTotalDuration() )
_streamTranscoders.at( i )->setInfinityStream( false );
else
_streamTranscoders.at( i )->setInfinityStream( true );
break;
case eProcessMethodLongest :
if( _streamTranscoders.at( i )->getDuration() == getMaxTotalDuration() )
_streamTranscoders.at( i )->setInfinityStream( false );
else
_streamTranscoders.at( i )->setInfinityStream( true );
break;
case eProcessMethodBasedOnStream :
if( i != _mainStreamIndex )
_streamTranscoders.at( i )->setInfinityStream( true );
else
_streamTranscoders.at( i )->setInfinityStream( false );
break;
case eProcessMethodInfinity :
_streamTranscoders.at( i )->setInfinityStream( true );
break;
}
}
}

}
24 changes: 19 additions & 5 deletions src/AvTranscoder/transcoder/Transcoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ enum EProcessMethod
class AvExport Transcoder
{
public:

/**
* @note Set FFmpeg log level to quite.
*/
Transcoder( OutputFile& outputFile );

~Transcoder();
Expand Down Expand Up @@ -112,7 +114,9 @@ class AvExport Transcoder

/**
* @brief Process all the streams, and ended the process depending on the transcode politic.
* @param progress
* @note The function manages all process: init(), beginWrap(), processFrame()s, and endWrap().
* @param progress: choose a progress, or create your own in C++ or in bindings by inherit IProgress class.
* @see IProgress
*/
void process( IProgress& progress );

Expand All @@ -124,20 +128,19 @@ class AvExport Transcoder

/**
* @brief Set the transcodage politic.
* @note Call it after adding the streams.
* @note By default eProcessMethodLongest.
* @param indexBasedStream: in case of process method eProcessMethodBasedOnStream, stop transcode at the end of the indicated stream.
*/
void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0 );

/**
* @brief Set verbose mode for the Transcoder and its streams.
* @brief Set verbose mode for the Transcoder, its streams, and its output file.
* @note If you call it before adding the streams, no verbose mode will be set for the new streams.
* @note set av log level to AV_LOG_DEBUG
*/
void setVerbose( bool verbose = true );

private:

void addRewrapStream( const std::string& filename, const size_t streamIndex );

void addTranscodeStream( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, const size_t offset ); ///< Get profile from input
Expand All @@ -164,6 +167,17 @@ class AvExport Transcoder
*/
double getMaxTotalDuration() const;

/**
* @brief Get the duration of the output program
* @note Depends on the streams, the process method, and the main stream index.
*/
double getTotalDurationFromProcessMethod() const;

/**
* @brief Set for each StreamTranscoder if it is an infinity stream (switch to generator at the end of the stream).
*/
void manageInfinityStreamFromProcessMethod();

private:
OutputFile& _outputFile; ///< The output media file after process.
std::vector< InputFile* > _inputFiles; ///< The list of input files which contain added streams.
Expand Down
1 change: 0 additions & 1 deletion test/pyTest/testTranscoderAdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ def testAddStreamTranscoder():

# process
progress = av.NoDisplayProgress()
transcoder.init()
transcoder.process( progress )

7 changes: 0 additions & 7 deletions test/pyTest/testTranscoderTranscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def testTranscodeWave24b48kmono():

transcoder.add( inputFileName, 0, "wave24b48kmono" )

transcoder.init()
progress = av.ConsoleProgress()
transcoder.process( progress )

Expand Down Expand Up @@ -47,7 +46,6 @@ def testTranscodeWave16b48kmono():

transcoder.add( inputFileName, 0, "wave16b48kmono" )

transcoder.init()
progress = av.ConsoleProgress()
transcoder.process( progress )

Expand Down Expand Up @@ -77,7 +75,6 @@ def testTranscodeWave16b48kmono():

# transcoder.add( inputFileName, 0, "dnxhd120" )

# transcoder.init()
# progress = av.ConsoleProgress()
# transcoder.process( progress )

Expand Down Expand Up @@ -106,7 +103,6 @@ def testTranscodeWave16b48kmono():

# transcoder.add( inputFileName, 0, "dnxhd185" )

# transcoder.init()
# progress = av.ConsoleProgress()
# transcoder.process( progress )

Expand Down Expand Up @@ -135,7 +131,6 @@ def testTranscodeWave16b48kmono():

# transcoder.add( inputFileName, 0, "dnxhd185x" )

# transcoder.init()
# progress = av.ConsoleProgress()
# transcoder.process( progress )

Expand Down Expand Up @@ -164,7 +159,6 @@ def testTranscodeWave16b48kmono():

# transcoder.add( inputFileName, 0, "xdcamhd422" )

# transcoder.init()
# progress = av.ConsoleProgress()
# transcoder.process( progress )

Expand Down Expand Up @@ -213,7 +207,6 @@ def testTranscodeWave16b48kmono():

# transcoder.add( inputFileName, 0, customProfile )

# transcoder.init()
# progress = av.ConsoleProgress()
# transcoder.process( progress )

Expand Down