Uniformisation of write and save

This commit is contained in:
jfmcarreira committed 2016-04-02 02:42:20 +01:00
1 parent 64162887a9
commit b71ca0580c
7 files changed
+70 -152

No files matched your search

+1 -1
View File
@@ -305,7 +305,7 @@ Void PlaYUVerApp::save()
QString supported = tr( "Supported Files (" );
QStringList formatsList;
std::vector<PlaYUVerSupportedFormat> supportedFmts = PlaYUVerStream::supportedSaveFormats();
std::vector<PlaYUVerSupportedFormat> supportedFmts = PlaYUVerStream::supportedWriteFormats();
for( UInt i = 0; i < supportedFmts.size(); i++ )
{
QString currFmt;
+51 -115
View File
@@ -62,19 +62,9 @@ std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedWriteFormats()
REGIST_PLAYUVER_SUPPORTED_FMT( &PlaYUVerRawHandler::Create, "Raw Video", "yuv" );
#ifdef USE_FFMPEG
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Write );
#endif
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedSaveFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
APPEND_PLAYUVER_SUPPORTED_FMT( PlaYUVerStream, Write );
#ifdef USE_FFMPEG
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Save );
#endif
#ifdef USE_OPENCV
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Save );
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Write );
#endif
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
@@ -105,15 +95,38 @@ std::vector<PlaYUVerStdResolution> PlaYUVerStream::stdResolutionSizes()
return stdResList;
}
CreateStreamHandlerFn PlaYUVerStream::findStreamHandler( std::string strFilename, bool bRead )
{
std::string currExt = strFilename.substr( strFilename.find_last_of( "." ) + 1 );
currExt = lowercase( currExt );
std::vector<PlaYUVerSupportedFormat> supportedFmts;
if( bRead )
{
supportedFmts = PlaYUVerStream::supportedReadFormats();
}
else
{
supportedFmts = PlaYUVerStream::supportedWriteFormats();
}
for( UInt i = 0; i < supportedFmts.size(); i++ )
{
if( supportedFmts[i].formatExt == currExt )
{
return supportedFmts[i].formatFct;
}
}
return NULL;
}
PlaYUVerStream::PlaYUVerStream()
{
m_bInit = false;
m_bIsInput = true;
m_bIsOpened = false;
m_bLoadAll = false;
m_iStreamHandler = INVALID_HANDLER;
m_pfctCreateHandler = NULL;
m_pcStreamHandler = NULL;
m_pchFilename = NULL;
m_bIsInput = true;
m_bLoadAll = false;
m_uiWidth = 0;
m_uiHeight = 0;
m_uiTotalFrameNum = 0;
@@ -122,7 +135,6 @@ PlaYUVerStream::PlaYUVerStream()
m_uiBitsPerPixel = 8;
m_iEndianness = -1;
m_dFrameRate = 30;
m_pStreamBuffer = NULL;
m_cFilename = "";
m_pcCurrFrame = NULL;
m_pcNextFrame = NULL;
@@ -187,40 +199,6 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
m_iEndianness = endianness;
m_dFrameRate = frame_rate;
m_pchFilename = new Char[m_cFilename.size() + 1];
std::copy( m_cFilename.begin(), m_cFilename.end(), m_pchFilename );
m_pchFilename[m_cFilename.size()] = '\0'; // don't forget the terminating 0
m_iStreamHandler = INVALID_HANDLER;
std::string currExt = m_cFilename.substr( m_cFilename.find_last_of( "." ) + 1 );
currExt = lowercase( currExt );
std::vector<PlaYUVerSupportedFormat> supportedFmts;
if( m_bIsInput )
{
supportedFmts = supportedReadFormats();
}
else
{
supportedFmts = supportedWriteFormats();
}
for( UInt i = 0; i < supportedFmts.size(); i++ )
{
if( supportedFmts[i].formatExt == currExt )
{
m_pfctCreateHandler = supportedFmts[i].formatFct;
break;
}
}
// if( m_iStreamHandler == INVALID_HANDLER )
// {
// close();
// throw "Invalid file format";
// return m_bInit;
// }
// #ifdef USE_OPENCV
// if( m_iStreamHandler == OPENCV_HANDLER )
@@ -239,6 +217,13 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
// }
// #endif
m_pfctCreateHandler = PlaYUVerStream::findStreamHandler( filename, m_bIsInput );
if( !m_pfctCreateHandler )
{
close();
throw "[PlaYUVerStream] Invalid handler";
}
m_pcStreamHandler = m_pfctCreateHandler();
if( !m_pcStreamHandler )
@@ -323,12 +308,12 @@ Bool PlaYUVerStream::reload()
{
m_pcStreamHandler->setBytesPerFrame( m_pcCurrFrame->getBytesPerFrame() );
m_pcStreamHandler->closeHandler();
if( !m_pcStreamHandler->openHandler( m_cFilename, m_bIsInput ) )
{
throw "[PlaYUVerStream] Cannot open file using FFmpeg libs";
}
m_uiTotalFrameNum = m_pcStreamHandler->calculateFrameNumber();
m_pcStreamHandler->closeHandler();
if( !m_pcStreamHandler->openHandler( m_cFilename, m_bIsInput ) )
{
throw "[PlaYUVerStream] Cannot open file using FFmpeg libs";
}
m_uiTotalFrameNum = m_pcStreamHandler->calculateFrameNumber();
if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 || m_uiTotalFrameNum < 1 )
@@ -350,7 +335,7 @@ Void PlaYUVerStream::close()
if( !m_bInit )
return;
m_pcStreamHandler->closeHandler();
m_pcStreamHandler->closeHandler();
@@ -366,12 +351,6 @@ Void PlaYUVerStream::close()
m_ppcFrameBuffer = NULL;
}
if( m_pStreamBuffer )
freeMem1D<Byte>( m_pStreamBuffer );
if( m_pchFilename )
delete[] m_pchFilename;
m_bLoadAll = false;
m_bInit = false;
}
@@ -482,18 +461,12 @@ Void PlaYUVerStream::readFrame()
return;
}
if( m_iStreamHandler == OPENCV_HANDLER )
if( !m_pcStreamHandler->read( m_pcNextFrame ) )
{
throw "[PlaYUVerStream] Cannot read file";
return;
}
if( !m_pcStreamHandler->read( m_pcNextFrame ) )
{
throw "[PlaYUVerStream] Cannot read file";
return;
}
m_uiCurrFrameFileIdx++;
return;
}
@@ -519,51 +492,14 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename )
Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *saveFrame )
{
Int iFileFormat = INVALID_HANDLER;
std::string fmtExt;
std::string currExt = filename.substr( filename.find_last_of( "." ) + 1 );
std::vector<PlaYUVerSupportedFormat> supportedFmts = PlaYUVerStream::supportedSaveFormats();
for( UInt i = 0; i < supportedFmts.size(); i++ )
PlaYUVerStream auxSaveStream;
if( !auxSaveStream.open( filename, saveFrame->getWidth(), saveFrame->getHeight(), saveFrame->getPelFormat(), saveFrame->getBitsPel(), saveFrame->getEndianness(), 1, false ) )
{
if( supportedFmts[i].formatExt == currExt )
{
iFileFormat = i;
fmtExt = supportedFmts[i].formatExt[i];
break;
}
return false;
}
if( iFileFormat != INVALID_HANDLER )
{
if( fmtExt == "yuv" )
{
PlaYUVerStream auxFrameStream;
if( !auxFrameStream.open( filename, saveFrame->getWidth(), saveFrame->getHeight(), saveFrame->getPelFormat(), saveFrame->getBitsPel(), 1, false ) )
{
return false;
}
auxFrameStream.writeFrame( saveFrame );
auxFrameStream.close();
return true;
}
#if 0
else
{
saveFrame->fillRGBBuffer();
QImage qimg = QImage( saveFrame->getRGBBuffer(), saveFrame->getWidth(), saveFrame->getHeight(), QImage::Format_RGB32 );
return qimg.save( qtString );
}
#endif
// #ifdef USE_OPENCV
// else
// {
// return LibOpenCVHandler::saveFrame( saveFrame, filename );
// }
// #endif
}
return false;
auxSaveStream.writeFrame( saveFrame );
auxSaveStream.close();
return true;
}
Bool PlaYUVerStream::setNextFrame()
+4 -18
View File
@@ -85,7 +85,8 @@ public:
static std::vector<PlaYUVerSupportedFormat> supportedReadFormats();
static std::vector<PlaYUVerSupportedFormat> supportedWriteFormats();
static std::vector<PlaYUVerSupportedFormat> supportedSaveFormats();
static CreateStreamHandlerFn findStreamHandler( std::string strFilename, bool bRead );
static std::vector<PlaYUVerStdResolution> stdResolutionSizes();
@@ -166,26 +167,11 @@ public:
private:
Bool m_bInit;
Bool m_bIsInput;
Bool m_bIsOpened;
Bool m_bLoadAll;
enum PlaYUVerStreamHandlers
{
INVALID_HANDLER = -1,
YUV_IO,
OPENCV_HANDLER,
FFMPEG,
TOTAL_HANDLERR
};
Int m_iStreamHandler;
CreateStreamHandlerFn m_pfctCreateHandler;
PlaYUVerStreamHandlerIf* m_pcStreamHandler;
Bool m_bIsInput;
std::string m_cFilename;
Char* m_pchFilename;
UInt m_uiWidth;
UInt m_uiHeight;
Int m_iPixelFormat;
@@ -195,7 +181,7 @@ private:
UInt64 m_uiTotalFrameNum;
Int64 m_iCurrFrameNum;
Byte* m_pStreamBuffer;
Bool m_bLoadAll;
UInt m_uiFrameBufferSize;
PlaYUVerFrame **m_ppcFrameBuffer;
+5 -7
View File
@@ -54,12 +54,6 @@ std::vector<PlaYUVerSupportedFormat> StreamHandlerLibav::supportedWriteFormats()
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<PlaYUVerSupportedFormat> StreamHandlerLibav::supportedSaveFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
static int open_codec_context( int *stream_idx, AVFormatContext *m_cFmtCtx, enum AVMediaType type )
{
int ret;
@@ -162,8 +156,10 @@ Bool StreamHandlerLibav::openHandler( std::string strFilename, Bool bInput )
getMem1D( &m_pchFrameBuffer, m_uiFrameBufferSize );
}
m_strFormatName = uppercase (strFilename.substr( strFilename.find_last_of( "." ) + 1 ) );
const char *name = avcodec_get_name( m_cCodecCtx->codec_id );
sprintf( m_acCodecName, "%s", name );
// sprintf( m_acCodecName, "%s", name );
m_strCodecName = name;
Double fr = 30;
if( m_cStream->avg_frame_rate.den && m_cStream->avg_frame_rate.num )
@@ -207,6 +203,8 @@ Bool StreamHandlerLibav::openHandler( std::string strFilename, Bool bInput )
m_uiBitsPerPixel = 16;
m_iEndianness = 0;
pix_fmt = AV_PIX_FMT_GRAY8;
case AV_PIX_FMT_PAL8:
pix_fmt = AV_PIX_FMT_GRAY8;
break;
}
-1
View File
@@ -62,7 +62,6 @@ public:
static std::vector<PlaYUVerSupportedFormat> supportedReadFormats();
static std::vector<PlaYUVerSupportedFormat> supportedWriteFormats();
static std::vector<PlaYUVerSupportedFormat> supportedSaveFormats();
StreamHandlerLibav()
{
+9 -9
View File
@@ -45,19 +45,13 @@ std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedReadFormats()
std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedWriteFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedSaveFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
// APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Read );
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Read );
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
Bool StreamHandlerOpenCV::openHandler( std::string strFilename, Bool bInput )
{
m_cFilename = m_cFilename;
m_cFilename = strFilename;
return true;
}
@@ -93,8 +87,14 @@ Bool StreamHandlerOpenCV::read( PlaYUVerFrame* pcFrame )
Bool StreamHandlerOpenCV::write( PlaYUVerFrame* pcFrame )
{
Bool bRet = false;
cv::Mat* pcCvFrame = pcFrame->getCvMat();
return cv::imwrite( m_cFilename.c_str(), *pcCvFrame );
if( pcCvFrame )
{
bRet = cv::imwrite( m_cFilename.c_str(), *pcCvFrame );
delete pcCvFrame;
}
return bRet;
}
} // NAMESPACE
-1
View File
@@ -47,7 +47,6 @@ public:
static std::vector<PlaYUVerSupportedFormat> supportedReadFormats();
static std::vector<PlaYUVerSupportedFormat> supportedWriteFormats();
static std::vector<PlaYUVerSupportedFormat> supportedSaveFormats();
StreamHandlerOpenCV()
{