Add function to save YUV frames
This commit is contained in:
1 parent
1c1da8de34
commit
11276b993f
2 files changed
+35
-8
No files matched your search
@@ -82,6 +82,7 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
|
|||||||
m_cFilename = filename;
|
m_cFilename = filename;
|
||||||
m_uiWidth = width;
|
m_uiWidth = width;
|
||||||
m_uiHeight = height;
|
m_uiHeight = height;
|
||||||
|
m_iPixelFormat = input_format;
|
||||||
m_uiFrameRate = frame_rate;
|
m_uiFrameRate = frame_rate;
|
||||||
|
|
||||||
if( m_bIsInput )
|
if( m_bIsInput )
|
||||||
@@ -101,8 +102,6 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
|
|||||||
}
|
}
|
||||||
m_cFormatName = PlaYUVerStream::supportedReadFormatsExt().at( m_iFileFormat ).toUpper();
|
m_cFormatName = PlaYUVerStream::supportedReadFormatsExt().at( m_iFileFormat ).toUpper();
|
||||||
|
|
||||||
m_iPixelFormat = input_format;
|
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
if( m_iFileFormat != YUVINPUT )
|
if( m_iFileFormat != YUVINPUT )
|
||||||
{
|
{
|
||||||
@@ -172,7 +171,7 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
|
|||||||
m_cCodedName = QString::fromUtf8( "Raw Video" );
|
m_cCodedName = QString::fromUtf8( "Raw Video" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_uiTotalFrameNum <= 0 )
|
if( m_bIsInput && m_uiTotalFrameNum <= 0 )
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
return m_bInit;
|
return m_bInit;
|
||||||
@@ -198,7 +197,6 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
|
|||||||
m_bInit = true;
|
m_bInit = true;
|
||||||
|
|
||||||
seekInput( 0 );
|
seekInput( 0 );
|
||||||
//loadAll();
|
|
||||||
|
|
||||||
m_cTimer.start();
|
m_cTimer.start();
|
||||||
m_uiAveragePlayInterval = 0;
|
m_uiAveragePlayInterval = 0;
|
||||||
@@ -209,6 +207,9 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
|
|||||||
|
|
||||||
Void PlaYUVerStream::close()
|
Void PlaYUVerStream::close()
|
||||||
{
|
{
|
||||||
|
if( !m_bInit )
|
||||||
|
return;
|
||||||
|
|
||||||
if( m_pFile )
|
if( m_pFile )
|
||||||
fclose( m_pFile );
|
fclose( m_pFile );
|
||||||
|
|
||||||
@@ -500,8 +501,32 @@ Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
|
|||||||
|
|
||||||
Bool PlaYUVerStream::saveFrame( const QString& filename )
|
Bool PlaYUVerStream::saveFrame( const QString& filename )
|
||||||
{
|
{
|
||||||
QImage qimg = QImage( m_pcCurrFrame->getQImageBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), QImage::Format_RGB888 );
|
Int iFileFormat = INVALID_INPUT;
|
||||||
return qimg.save( filename );
|
|
||||||
|
QStringList formatsExt = PlaYUVerStream::supportedReadFormatsExt();
|
||||||
|
QString currExt = QFileInfo( filename ).suffix();
|
||||||
|
if( formatsExt.contains( currExt ) )
|
||||||
|
{
|
||||||
|
iFileFormat = formatsExt.indexOf( currExt );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( iFileFormat == YUVINPUT )
|
||||||
|
{
|
||||||
|
PlaYUVerStream auxFrameStream;
|
||||||
|
if( !auxFrameStream.open( filename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate, false ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auxFrameStream.writeFrame( m_pcCurrFrame );
|
||||||
|
auxFrameStream.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QImage qimg = QImage( m_pcCurrFrame->getQImageBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), QImage::Format_RGB888 );
|
||||||
|
return qimg.save( filename );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Void PlaYUVerStream::setNextFrame()
|
Void PlaYUVerStream::setNextFrame()
|
||||||
|
|||||||
@@ -156,7 +156,8 @@ public:
|
|||||||
static QStringList supportedSaveFormatsExt()
|
static QStringList supportedSaveFormatsExt()
|
||||||
{
|
{
|
||||||
QStringList formatsExt;
|
QStringList formatsExt;
|
||||||
formatsExt << "bmp"
|
formatsExt << "yuv"
|
||||||
|
<< "bmp"
|
||||||
<< "jpeg"
|
<< "jpeg"
|
||||||
<< "png" // portable network graphics
|
<< "png" // portable network graphics
|
||||||
;
|
;
|
||||||
@@ -166,7 +167,8 @@ public:
|
|||||||
static QStringList supportedSaveFormatsName()
|
static QStringList supportedSaveFormatsName()
|
||||||
{
|
{
|
||||||
QStringList formatsName;
|
QStringList formatsName;
|
||||||
formatsName << "Windows Bitmap"
|
formatsName << "Raw Video"
|
||||||
|
<< "Windows Bitmap"
|
||||||
<< "Joint Photographic Experts Group"
|
<< "Joint Photographic Experts Group"
|
||||||
<< "Portable Network Graphics";
|
<< "Portable Network Graphics";
|
||||||
return formatsName;
|
return formatsName;
|
||||||
|
|||||||
Reference in new issue
Block a user