diff --git a/source/lib/PlaYUVerStream.cpp b/source/lib/PlaYUVerStream.cpp index dc37a01..b3e4b58 100644 --- a/source/lib/PlaYUVerStream.cpp +++ b/source/lib/PlaYUVerStream.cpp @@ -82,6 +82,7 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ m_cFilename = filename; m_uiWidth = width; m_uiHeight = height; + m_iPixelFormat = input_format; m_uiFrameRate = frame_rate; 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_iPixelFormat = input_format; - #ifdef USE_FFMPEG 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" ); } - if( m_uiTotalFrameNum <= 0 ) + if( m_bIsInput && m_uiTotalFrameNum <= 0 ) { close(); return m_bInit; @@ -198,7 +197,6 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ m_bInit = true; seekInput( 0 ); -//loadAll(); m_cTimer.start(); m_uiAveragePlayInterval = 0; @@ -209,6 +207,9 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ Void PlaYUVerStream::close() { + if( !m_bInit ) + return; + if( m_pFile ) fclose( m_pFile ); @@ -500,8 +501,32 @@ Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame ) Bool PlaYUVerStream::saveFrame( const QString& filename ) { - QImage qimg = QImage( m_pcCurrFrame->getQImageBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), QImage::Format_RGB888 ); - return qimg.save( filename ); + Int iFileFormat = INVALID_INPUT; + + 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() diff --git a/source/lib/PlaYUVerStream.h b/source/lib/PlaYUVerStream.h index e0ab607..e8cd5d8 100644 --- a/source/lib/PlaYUVerStream.h +++ b/source/lib/PlaYUVerStream.h @@ -156,7 +156,8 @@ public: static QStringList supportedSaveFormatsExt() { QStringList formatsExt; - formatsExt << "bmp" + formatsExt << "yuv" + << "bmp" << "jpeg" << "png" // portable network graphics ; @@ -166,7 +167,8 @@ public: static QStringList supportedSaveFormatsName() { QStringList formatsName; - formatsName << "Windows Bitmap" + formatsName << "Raw Video" + << "Windows Bitmap" << "Joint Photographic Experts Group" << "Portable Network Graphics"; return formatsName;