Add rate reduction operation to PlaYUVerTools
This commit is contained in:
1 parent
d96167856c
commit
9c2e6fdbb8
4 files changed
+80
-1
No files matched your search
@@ -183,6 +183,59 @@ Int PlaYUVerTools::Open( Int argc, Char* argv[] )
|
||||
log( LOG_INFO, "PlaYUVer Save Frame\n" );
|
||||
}
|
||||
|
||||
if( Opts().hasOpt( "rate-reduction" ) )
|
||||
{
|
||||
if( m_apcInputStreams.size() == 0 )
|
||||
{
|
||||
log( LOG_ERROR, "Invalid number of input streams! " );
|
||||
return 2;
|
||||
}
|
||||
Int64 currFrames = 0;
|
||||
Int64 numberOfFrames = LONG_MAX;
|
||||
for( UInt i = 0; i < m_apcInputStreams.size(); i++ )
|
||||
{
|
||||
currFrames = m_apcInputStreams[i]->getFrameNum();
|
||||
if( currFrames < numberOfFrames )
|
||||
numberOfFrames = currFrames;
|
||||
}
|
||||
if( m_iRateReductionFactor <= 0 )
|
||||
{
|
||||
log( LOG_ERROR, "Invalid frame rate reduction value!" );
|
||||
return 2;
|
||||
}
|
||||
|
||||
if( Opts().hasOpt( "output" ) )
|
||||
m_pcOutputFileNames.push_back( m_strOutput );
|
||||
|
||||
PlaYUVerFrame* pcInputFrame = m_apcInputStreams[0]->getCurrFrame();
|
||||
PlaYUVerStream* pcOutputStream = new PlaYUVerStream;
|
||||
try
|
||||
{
|
||||
pcOutputStream->open( m_pcOutputFileNames[0], pcInputFrame->getWidth(), pcInputFrame->getHeight(),
|
||||
pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel(), PLAYUVER_LITTLE_ENDIAN, 1,
|
||||
false );
|
||||
}
|
||||
catch( const char* msg )
|
||||
{
|
||||
log( LOG_ERROR, "Cannot open input stream %s with the following error %s!\n", m_pcOutputFileNames[0].c_str(),
|
||||
msg );
|
||||
delete pcOutputStream;
|
||||
pcOutputStream = NULL;
|
||||
return 2;
|
||||
}
|
||||
m_apcOutputStreams.push_back( pcOutputStream );
|
||||
|
||||
if( m_apcOutputStreams.size() != m_apcInputStreams.size() )
|
||||
{
|
||||
log( LOG_ERROR, "Invalid number of outputs! Each input must have an output filename. " );
|
||||
return 2;
|
||||
}
|
||||
|
||||
m_uiOperation = RATE_REDUCTION_OPERATION;
|
||||
m_fpProcess = &PlaYUVerTools::RateReductionOperation;
|
||||
log( LOG_INFO, "PlaYUVer Frame Rate Reduction\n" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Quality operation
|
||||
*/
|
||||
@@ -344,6 +397,27 @@ Int PlaYUVerTools::SaveOperation()
|
||||
return 0;
|
||||
}
|
||||
|
||||
Int PlaYUVerTools::RateReductionOperation()
|
||||
{
|
||||
Bool abEOF;
|
||||
log( LOG_INFO, "\n Reducing frame rate by a factor of %d ... ", m_iRateReductionFactor );
|
||||
for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ )
|
||||
{
|
||||
log( LOG_INFO, "\n Reading frame %d ... ", frame );
|
||||
if( ( frame % m_iRateReductionFactor ) == 0 )
|
||||
{
|
||||
log( LOG_INFO, "Writing", frame );
|
||||
m_apcOutputStreams[0]->writeFrame( m_apcInputStreams[0]->getCurrFrame() );
|
||||
}
|
||||
abEOF = m_apcInputStreams[0]->setNextFrame();
|
||||
if( !abEOF )
|
||||
{
|
||||
m_apcInputStreams[0]->readFrame();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Int PlaYUVerTools::QualityOperation()
|
||||
{
|
||||
const char* pchQualityMetricName = PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str();
|
||||
|
||||
@@ -54,6 +54,7 @@ class PlaYUVerTools : public PlaYUVerToolsCmdParser
|
||||
{
|
||||
INVALID_OPERATION,
|
||||
SAVE_OPERATION,
|
||||
RATE_REDUCTION_OPERATION,
|
||||
QUALITY_OPERATION,
|
||||
MODULE_OPERATION,
|
||||
};
|
||||
@@ -72,6 +73,8 @@ class PlaYUVerTools : public PlaYUVerToolsCmdParser
|
||||
std::vector<String> m_pcOutputFileNames;
|
||||
Int SaveOperation();
|
||||
|
||||
Int RateReductionOperation();
|
||||
|
||||
Int m_uiQualityMetric;
|
||||
Int QualityOperation();
|
||||
|
||||
|
||||
@@ -70,7 +70,8 @@ Int PlaYUVerToolsCmdParser::parseToolsArgs( Int argc, Char* argv[] )
|
||||
( "frames,f", m_iFrames, "number of frames to parse" ) /**/
|
||||
( "quality", m_strQualityMetric, "select a quality metric" ) /**/
|
||||
( "module", m_strModule, "select a module (use internal name)" ) /**/
|
||||
( "save", "save a specific frame" );
|
||||
( "save", "save a specific frame" ) /**/
|
||||
( "rate-reduction", m_iRateReductionFactor, "reduce the frame rate" ); /**/
|
||||
|
||||
if( !m_cOptions.parse( argc, argv ) )
|
||||
{
|
||||
|
||||
@@ -72,6 +72,7 @@ class PlaYUVerToolsCmdParser
|
||||
String m_strOutput;
|
||||
Int64 m_iFrames;
|
||||
|
||||
Int m_iRateReductionFactor;
|
||||
String m_strQualityMetric;
|
||||
String m_strModule;
|
||||
|
||||
|
||||
Reference in new issue
Block a user