Skip to content

Transcoder: add offset #47

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 7 commits into from
Aug 7, 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
7 changes: 5 additions & 2 deletions app/genericProcessor/genericProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ int main( int argc, char** argv )
avtranscoder::OutputFile outputFile( argv[2] );

avtranscoder::Transcoder transcoder( outputFile );
transcoder.setVerbose( verbose );
transcoder.setProcessMethod( avtranscoder::eProcessMethodShortest );

if( verbose )
std::cout << "parse config file" << std::endl;
parseConfigFile( inputConfigFile, transcoder, profiles );

// set verbose of all stream
transcoder.setVerbose( verbose );
transcoder.setProcessMethod( avtranscoder::eProcessMethodInfinity );
//transcoder.setOutputFps( 12 );

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

Expand Down
112 changes: 76 additions & 36 deletions src/AvTranscoder/Transcoder/StreamTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <cassert>
#include <iostream>
#include <limits>

namespace avtranscoder
{
Expand All @@ -32,9 +33,12 @@ StreamTranscoder::StreamTranscoder(
, _outputEssence( NULL )
, _transform( NULL )
, _subStreamIndex( -1 )
, _transcodeStream( false )
, _infiniteProcess( false )
, _frameProcessed( 0 )
, _offset( 0 )
, _takeFromDummy( false )
, _verbose( false )
, _offsetPassed( false )
, _infinityStream( false )
{
// create a re-wrapping case
switch( _inputStream->getStreamType() )
Expand All @@ -58,7 +62,8 @@ StreamTranscoder::StreamTranscoder(
InputStream& inputStream,
OutputFile& outputFile,
const Profile::ProfileDesc& profile,
const int subStreamIndex
const int subStreamIndex,
const size_t offset
)
: _inputStream( &inputStream )
, _outputStream( NULL )
Expand All @@ -69,9 +74,12 @@ StreamTranscoder::StreamTranscoder(
, _outputEssence( NULL )
, _transform( NULL )
, _subStreamIndex( subStreamIndex )
, _transcodeStream( true )
, _infiniteProcess( false )
, _frameProcessed( 0 )
, _offset( offset )
, _takeFromDummy( false )
, _verbose( false )
, _offsetPassed( false )
, _infinityStream( false )
{
// create a transcode case
switch( _inputStream->getStreamType() )
Expand Down Expand Up @@ -99,8 +107,6 @@ StreamTranscoder::StreamTranscoder(
DummyVideo* dummyVideo = new DummyVideo();
dummyVideo->setVideoDesc( outputVideo->getVideoDesc() );
_dummyEssence = dummyVideo;

_currentEssence = _inputEssence;

break;
}
Expand Down Expand Up @@ -137,8 +143,6 @@ StreamTranscoder::StreamTranscoder(
dummyAudio->setAudioDesc( outputAudio->getAudioDesc() );
_dummyEssence = dummyAudio;

_currentEssence = _inputEssence;

break;
}
default:
Expand All @@ -147,6 +151,7 @@ StreamTranscoder::StreamTranscoder(
break;
}
}
switchEssence( offset != 0 );
}

StreamTranscoder::StreamTranscoder(
Expand All @@ -163,9 +168,12 @@ StreamTranscoder::StreamTranscoder(
, _outputEssence( NULL )
, _transform( NULL )
, _subStreamIndex( -1 )
, _transcodeStream( true )
, _infiniteProcess( false )
, _frameProcessed( 0 )
, _offset( 0 )
, _takeFromDummy( false )
, _verbose( false )
, _offsetPassed( false )
, _infinityStream( false )
{
// create a coding case based on a InputEssence (aka dummy reader)
if( ! profile.count( Profile::avProfileType ) )
Expand Down Expand Up @@ -237,7 +245,8 @@ StreamTranscoder::~StreamTranscoder()

bool StreamTranscoder::processFrame()
{
if( _transcodeStream )
++_frameProcessed;
if( _transform )
{
if( _subStreamIndex < 0 )
{
Expand Down Expand Up @@ -275,12 +284,10 @@ bool StreamTranscoder::processRewrap( const int subStreamIndex )
assert( _outputStream != NULL );

DataStream dataStream;
// std::vector<DataStream> dataStream;

if( ! _inputStream->readNextPacket( dataStream ) )
return false;
_outputStream->wrap( dataStream );
// outputStream.wrap( dataStream.at( subStreamIndex ) );

return true;
}
Expand All @@ -297,6 +304,16 @@ bool StreamTranscoder::processTranscode()
DataStream dataStream;
if( _verbose )
std::cout << "transcode a frame " << std::endl;

if( _offset &&
_frameProcessed > _offset &&
! _offsetPassed &&
_takeFromDummy )
{
switchToInputEssence();
_offsetPassed = true;
}

if( _currentEssence->readNextFrame( *_sourceBuffer ) )
{
if( _verbose )
Expand All @@ -308,16 +325,15 @@ bool StreamTranscoder::processTranscode()
}
else
{
if( _infiniteProcess )
{
switchToDummyEssence();
return processTranscode( );
}

if( _verbose )
std::cout << "encode last frame(s)" << std::endl;
if( ! _outputEssence->encodeFrame( dataStream ) )
{
if( _infinityStream )
{
switchToDummyEssence();
return processTranscode();
}
return false;
}
}
Expand All @@ -340,6 +356,16 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
DataStream dataStream;
if( _verbose )
std::cout << "transcode a frame " << std::endl;

if( _offset &&
_frameProcessed > _offset &&
! _offsetPassed &&
_takeFromDummy )
{
switchToInputEssence();
_offsetPassed = true;
}

if( _currentEssence->readNextFrame( *_sourceBuffer, subStreamIndex ) )
{
if( _verbose )
Expand All @@ -351,14 +377,15 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
}
else
{
if( _infiniteProcess )
{
switchToDummyEssence();
return processTranscode( );
}

if( _verbose )
std::cout << "encode last frame(s)" << std::endl;
if( ! _outputEssence->encodeFrame( dataStream ) )
{
if( _infinityStream )
{
switchToDummyEssence();
return processTranscode();
}
return false;
}
}
Expand All @@ -368,22 +395,35 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
return true;
}

void StreamTranscoder::switchToDummyEssence()
void StreamTranscoder::switchEssence( bool swithToDummy )
{
if( _dummyEssence == NULL )
return;
_takeFromDummy = true;
_currentEssence = _dummyEssence;
_takeFromDummy = swithToDummy;
_currentEssence = swithToDummy ? _dummyEssence : _inputEssence;
assert( _currentEssence != NULL );
}

void StreamTranscoder::switchToDummyEssence()
{
switchEssence( true );
}

void StreamTranscoder::switchToInputEssence()
{
if( _inputEssence == NULL )
return;
_takeFromDummy = false;
_currentEssence = _inputEssence;
assert( _currentEssence != NULL );
switchEssence( false );
}

double StreamTranscoder::getDuration() const
{
if( _inputStream )
{
double totalDuration = 0;
totalDuration += _inputStream->getDuration();
// @todo add offset
return totalDuration;
}
// dummy
else
return std::numeric_limits<double>::max();
}

}
40 changes: 33 additions & 7 deletions src/AvTranscoder/Transcoder/StreamTranscoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ class StreamTranscoder
public:
/**
* @brief rewrap stream
* @note offset feature when rewrap a stream is not supported
**/
StreamTranscoder( InputStream& inputStream, OutputFile& outputFile );

/**
* @brief transcode stream
**/
StreamTranscoder( InputStream& inputStream, OutputFile& outputFile, const Profile::ProfileDesc& profile, const int subStreamIndex = -1 );
StreamTranscoder( InputStream& inputStream, OutputFile& outputFile, const Profile::ProfileDesc& profile, const int subStreamIndex = -1, const size_t offset = 0 );

/**
* @brief encode from dummy stream
* @note offset feature has no sense here
**/
StreamTranscoder( InputEssence& inputEssence, OutputFile& outputFile, const Profile::ProfileDesc& profile );

Expand All @@ -43,13 +45,21 @@ class StreamTranscoder
*/
bool processFrame();

bool isTranscodeStream() const { return _transcodeStream; }
void switchEssence( bool swithToDummy = true );
void switchToDummyEssence();
void switchToInputEssence();

void setVerbose( bool verbose = true ){ _verbose = verbose; }

void switchToDummyEssence();
void switchToInputEssence();
void setInfinityProcess( bool infinity = true ){ _infiniteProcess = infinity; }
void setInfinityStream( bool isInfinity ) { _infinityStream = isInfinity; }

void setOffset( bool offset = true ){ _offset = offset; }

/**
* @brief Get the duration of the stream.
* @note if it's a dummy stream, return limit of double.
*/
double getDuration() const;

private:
bool processRewrap();
Expand All @@ -72,11 +82,27 @@ class StreamTranscoder
EssenceTransform* _transform;

int _subStreamIndex;
bool _transcodeStream;

/**
* @brief How many frame processed for this StreamTranscoder.
*/
size_t _frameProcessed;
/**
* @brief Offset, in frame, at the beginning of the StreamTranscoder.
*/
size_t _offset;

bool _takeFromDummy;
bool _infiniteProcess;

bool _verbose;

bool _offsetPassed;

/**
* @brief Automatic switch to dummy
* @note not applicable when rewrap
*/
bool _infinityStream;
};

}
Expand Down
Loading