Changes functions that control the supported formats of the PlaYUVerStream lib
This commit is contained in:
1 parent
d4d3b11c3a
commit
e5e9971f39
7 files changed
+238
-138
No files matched your search
@@ -26,6 +26,7 @@
|
||||
#include <cstdio>
|
||||
#include "LibMemory.h"
|
||||
#include "PlaYUVerStream.h"
|
||||
#include <QImage>
|
||||
#ifdef USE_FFMPEG
|
||||
#include "LibAvContextHandle.h"
|
||||
#endif
|
||||
@@ -47,7 +48,7 @@ PlaYUVerStream::PlaYUVerStream()
|
||||
m_iCurrFrameNum = -1;
|
||||
m_iPixelFormat = -1;
|
||||
m_uiFrameRate = 30;
|
||||
m_iFileFormat = INVALID;
|
||||
m_iFileFormat = INVALID_INPUT;
|
||||
m_pStreamBuffer = NULL;
|
||||
m_cFilename = QString( "" );
|
||||
m_cStreamInformationString = QString( "" );
|
||||
@@ -57,8 +58,9 @@ PlaYUVerStream::PlaYUVerStream()
|
||||
m_uiFrameBufferSize = 2;
|
||||
m_uiFrameBufferIndex = 0;
|
||||
m_uiAveragePlayInterval = 0;
|
||||
|
||||
m_cLibAvContext = NULL;
|
||||
#ifdef USE_FFMPEG
|
||||
m_cLibAvContext = new LibAvContextHandle;
|
||||
#endif
|
||||
}
|
||||
|
||||
PlaYUVerStream::~PlaYUVerStream()
|
||||
@@ -66,65 +68,6 @@ PlaYUVerStream::~PlaYUVerStream()
|
||||
close();
|
||||
}
|
||||
|
||||
QString PlaYUVerStream::supportedReadFormats()
|
||||
{
|
||||
QString formats;
|
||||
formats = "*.yuv " // Raw video
|
||||
#ifdef USE_FFMPEG
|
||||
"*.avi " // Audio video interleaved
|
||||
"*.mp4 "// MP4
|
||||
"*.wmv "// Windows media video
|
||||
#endif
|
||||
; return formats;
|
||||
}
|
||||
|
||||
QStringList PlaYUVerStream::supportedReadFormatsList()
|
||||
{
|
||||
QStringList formats;
|
||||
formats << "Raw video (*.yuv)"
|
||||
#ifdef USE_FFMPEG
|
||||
<< "Audio video interleaved (*.avi)"
|
||||
<< "MPEG4 (*.mp4)"
|
||||
<< "Windows media video (*.wmv)"
|
||||
#endif
|
||||
;
|
||||
return formats;
|
||||
}
|
||||
|
||||
QString PlaYUVerStream::supportedWriteFormats()
|
||||
{
|
||||
QString formats;
|
||||
formats = "*.yuv " // raw video
|
||||
;
|
||||
return formats;
|
||||
}
|
||||
|
||||
QStringList PlaYUVerStream::supportedWriteFormatsList()
|
||||
{
|
||||
QStringList formats;
|
||||
formats << "Raw video (*.yuv)";
|
||||
return formats;
|
||||
}
|
||||
|
||||
QString PlaYUVerStream::supportedSaveFormats()
|
||||
{
|
||||
QString formats;
|
||||
formats = "*.jpg " // Joint Photographic Experts Group
|
||||
"*.jpeg "// Joint Photographic Experts Group
|
||||
"*.png "// Portable Network Graphics
|
||||
;
|
||||
return formats;
|
||||
}
|
||||
|
||||
QStringList PlaYUVerStream::supportedSaveFormatsList()
|
||||
{
|
||||
QStringList formats;
|
||||
formats << "Windows Bitmap (*.bmp)"
|
||||
<< "Joint Photographic Experts Group (*.jpg *.jpeg)"
|
||||
<< "Portable Network Graphics (*.png)";
|
||||
return formats;
|
||||
}
|
||||
|
||||
Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput )
|
||||
{
|
||||
Bool avStatus = false;
|
||||
@@ -141,17 +84,38 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
|
||||
m_uiHeight = height;
|
||||
m_uiFrameRate = frame_rate;
|
||||
|
||||
m_iFileFormat = YUVFormat;
|
||||
m_iPixelFormat = input_format;
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
if( m_bIsInput && QFileInfo( filename ).suffix().compare( QString( "yuv" ) ) )
|
||||
if( m_bIsInput )
|
||||
{
|
||||
avStatus = m_cLibAvContext->initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate, m_uiTotalFrameNum );
|
||||
m_cFormatName = QFileInfo( filename ).completeSuffix().toUpper();
|
||||
m_cCodedName = QString::fromUtf8( m_cLibAvContext->getCodecName() ).toUpper();
|
||||
m_iFileFormat = YUVINPUT;
|
||||
|
||||
QStringList formatsExt = PlaYUVerStream::supportedReadFormatsExt();
|
||||
QString currExt = QFileInfo( filename ).suffix();
|
||||
if( formatsExt.contains( currExt ) )
|
||||
{
|
||||
m_iFileFormat = formatsExt.indexOf( currExt );
|
||||
}
|
||||
|
||||
m_iPixelFormat = input_format;
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
if( m_bIsInput /*&& m_iFileFormat != YUVINPUT */)
|
||||
{
|
||||
avStatus = m_cLibAvContext->initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate, m_uiTotalFrameNum );
|
||||
m_cFormatName = QFileInfo( filename ).completeSuffix().toUpper();
|
||||
m_cCodedName = QString::fromUtf8( m_cLibAvContext->getCodecName() ).toUpper();
|
||||
}
|
||||
#endif
|
||||
|
||||
m_uiFrameBufferSize = 2;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
m_iFileFormat = YUVOUTPUT;
|
||||
m_uiFrameBufferSize = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 )
|
||||
{
|
||||
@@ -159,14 +123,6 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
if( m_bIsInput )
|
||||
{
|
||||
m_uiFrameBufferSize = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_uiFrameBufferSize = 1;
|
||||
}
|
||||
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
|
||||
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
|
||||
{
|
||||
@@ -301,7 +257,7 @@ Bool PlaYUVerStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight,
|
||||
resolutionString.remove( "_" );
|
||||
QStringList resolutionArgs = resolutionString.split( "x" );
|
||||
qDebug( ) << "Found resolution = "
|
||||
<< resolutionArgs;
|
||||
<< resolutionArgs;
|
||||
if( resolutionArgs.size() == 2 )
|
||||
{
|
||||
rWidth = resolutionArgs.at( 0 ).toUInt();
|
||||
@@ -454,9 +410,10 @@ Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
|
||||
return;
|
||||
}
|
||||
|
||||
Void PlaYUVerStream::saveFrame( const QString& filename )
|
||||
Bool PlaYUVerStream::saveFrame( const QString& filename )
|
||||
{
|
||||
return;
|
||||
QImage qimg = QImage( m_pcCurrFrame->getQImageBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), QImage::Format_RGB888 );
|
||||
return qimg.save( filename );
|
||||
}
|
||||
|
||||
Void PlaYUVerStream::setNextFrame()
|
||||
@@ -495,7 +452,7 @@ PlaYUVerFrame* PlaYUVerStream::getCurrFrame()
|
||||
|
||||
Void PlaYUVerStream::seekInput( UInt64 new_frame_num )
|
||||
{
|
||||
if( !m_pFile || new_frame_num < 0 || new_frame_num >= m_uiTotalFrameNum || ( Int64 )new_frame_num == m_iCurrFrameNum )
|
||||
if( !m_bInit || new_frame_num < 0 || new_frame_num >= m_uiTotalFrameNum || ( Int64 )new_frame_num == m_iCurrFrameNum )
|
||||
return;
|
||||
|
||||
m_iCurrFrameNum = new_frame_num - 1;
|
||||
|
||||
+93
-11
@@ -77,19 +77,101 @@ public:
|
||||
PlaYUVerStream();
|
||||
~PlaYUVerStream();
|
||||
|
||||
static QString supportedReadFormats();
|
||||
static QStringList supportedReadFormatsList();
|
||||
static QString supportedWriteFormats();
|
||||
static QStringList supportedWriteFormatsList();
|
||||
static QString supportedSaveFormats();
|
||||
static QStringList supportedSaveFormatsList();
|
||||
|
||||
enum PlaYUVerStreamFormats
|
||||
enum PlaYUVerStreamInputFormats
|
||||
{
|
||||
INVALID = -1,
|
||||
YUVFormat = 0, // Use color space.
|
||||
INVALID_INPUT = -1,
|
||||
YUVINPUT = 0,
|
||||
#ifdef USE_FFMPEG
|
||||
AVIINPUT,
|
||||
MP4INPUT,
|
||||
WMVINPUT,
|
||||
PGMINPUT,
|
||||
PNGINPUT,
|
||||
BMPINPUT,
|
||||
JPEGINPUT,
|
||||
#endif
|
||||
TOTAL_INPUT_FORMATS
|
||||
};
|
||||
|
||||
static QStringList supportedReadFormatsExt()
|
||||
{
|
||||
QStringList formatsExt;
|
||||
formatsExt << "yuv" // Raw video
|
||||
#ifdef USE_FFMPEG
|
||||
<< "avi" // Audio video interleaved
|
||||
<< "mp4"// MP4
|
||||
<< "wmv"// Windows media video
|
||||
<< "pgm"
|
||||
<< "png"
|
||||
<< "bmp"
|
||||
<< "jpg"
|
||||
#endif
|
||||
;
|
||||
assert( formatsExt.size() == TOTAL_INPUT_FORMATS );
|
||||
return formatsExt;
|
||||
}
|
||||
|
||||
static QStringList supportedReadFormatsName()
|
||||
{
|
||||
QStringList formatsName;
|
||||
formatsName << "Raw video"
|
||||
#ifdef USE_FFMPEG
|
||||
<< "Audio video interleaved"
|
||||
<< "MPEG4"
|
||||
<< "Windows media video"
|
||||
<< "Portable Grayscale Map"
|
||||
<< "Portable Network Graphics"
|
||||
<< "Windows Bitmap"
|
||||
<< "Joint Photographic Experts Group"
|
||||
#endif
|
||||
;
|
||||
assert( formatsName.size() == TOTAL_INPUT_FORMATS );
|
||||
return formatsName;
|
||||
}
|
||||
|
||||
enum PlaYUVerStreamOutputFormats
|
||||
{
|
||||
INVALID_OUTPUT = -1,
|
||||
YUVOUTPUT = 0,
|
||||
TOTAL_OUTPUT_FORMATS
|
||||
};
|
||||
|
||||
static QStringList supportedWriteFormatsExt()
|
||||
{
|
||||
QStringList formatsExt;
|
||||
formatsExt << "yuv" // raw video
|
||||
;
|
||||
assert( formatsExt.size() == TOTAL_OUTPUT_FORMATS );
|
||||
return formatsExt;
|
||||
}
|
||||
|
||||
static QStringList supportedWriteFormatsName()
|
||||
{
|
||||
QStringList formatsName;
|
||||
formatsName << "Raw video";
|
||||
assert( formatsName.size() == TOTAL_OUTPUT_FORMATS );
|
||||
return formatsName;
|
||||
}
|
||||
|
||||
static QStringList supportedSaveFormatsExt()
|
||||
{
|
||||
QStringList formatsExt;
|
||||
formatsExt << "bmp"
|
||||
<< "jpeg"
|
||||
<< "png" // portable network graphics
|
||||
;
|
||||
return formatsExt;
|
||||
}
|
||||
|
||||
static QStringList supportedSaveFormatsName()
|
||||
{
|
||||
QStringList formatsName;
|
||||
formatsName << "Windows Bitmap"
|
||||
<< "Joint Photographic Experts Group"
|
||||
<< "Portable Network Graphics";
|
||||
return formatsName;
|
||||
}
|
||||
|
||||
enum PlaYUVerStreamErrors
|
||||
{
|
||||
NO_STREAM_ERROR = 0,
|
||||
@@ -111,7 +193,7 @@ public:
|
||||
Void writeFrame();
|
||||
Void writeFrame( PlaYUVerFrame *pcFrame );
|
||||
|
||||
Void saveFrame( const QString& filename );
|
||||
Bool saveFrame( const QString& filename );
|
||||
|
||||
Void setNextFrame();
|
||||
PlaYUVerFrame* getCurrFrame();
|
||||
|
||||
@@ -108,16 +108,35 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height
|
||||
sprintf( aux_string, "%dx%d", width, height );
|
||||
av_dict_set( &format_opts, "video_size", aux_string, 0 );
|
||||
}
|
||||
// YUV420p = 0,
|
||||
// YUV444p,
|
||||
// YUV422p,
|
||||
// YUYV422,
|
||||
// GRAY,
|
||||
// RGB8,
|
||||
switch( pixel_format )
|
||||
{
|
||||
case PlaYUVerFrame::NO_FMT:
|
||||
break;
|
||||
|
||||
case PlaYUVerFrame::YUV420p:
|
||||
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_YUV420P ), 0 );
|
||||
break;
|
||||
case PlaYUVerFrame::YUV444p:
|
||||
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_YUV444P ), 0 );
|
||||
break;
|
||||
case PlaYUVerFrame::YUV422p:
|
||||
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_YUV422P ), 0 );
|
||||
break;
|
||||
case PlaYUVerFrame::YUYV422:
|
||||
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_YUYV422 ), 0 );
|
||||
break;
|
||||
case PlaYUVerFrame::GRAY:
|
||||
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_GRAY8 ), 0 );
|
||||
break;
|
||||
case PlaYUVerFrame::RGB8:
|
||||
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_RGB24 ), 0 );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -152,8 +171,8 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height
|
||||
video_dst_bufsize = ret;
|
||||
}
|
||||
|
||||
const char *codec_name = avcodec_get_name(video_dec_ctx->codec_id);
|
||||
sprintf(m_acCodecName, "%s", codec_name);
|
||||
const char *codec_name = avcodec_get_name( video_dec_ctx->codec_id );
|
||||
sprintf( m_acCodecName, "%s", codec_name );
|
||||
|
||||
Double fr = 30;
|
||||
if( video_stream->avg_frame_rate.den && video_stream->avg_frame_rate.num )
|
||||
@@ -188,6 +207,9 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height
|
||||
case AV_PIX_FMT_YUV420P:
|
||||
pixel_format = PlaYUVerFrame::YUV420p;
|
||||
break;
|
||||
case AV_PIX_FMT_YUV444P:
|
||||
pixel_format = PlaYUVerFrame::YUV444p;
|
||||
break;
|
||||
case AV_PIX_FMT_YUV422P:
|
||||
pixel_format = PlaYUVerFrame::YUV422p;
|
||||
break;
|
||||
@@ -213,7 +235,7 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height
|
||||
closeAvFormat();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#if( LIBAVFORMAT_VERSION_MAJOR >= 55 )
|
||||
frame = av_frame_alloc();
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user