ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
QVideoEncoder Class Reference

Video encoder based on FFmpeg. More...

#include <QVideoEncoder.h>

Collaboration diagram for QVideoEncoder:

Classes

struct  OutputFormat
 Output format. More...
 

Public Member Functions

 QVideoEncoder (QString filename, int width, int height, unsigned bitrate, int gop=12, int fps=25)
 Default constructor. More...
 
virtual ~QVideoEncoder ()
 
bool open (QString formatShortName, QStringList &errors)
 Creates an (empty) video/anmiation file. More...
 
bool isOpen () const
 Returns whether the file is opened or not. More...
 
virtual bool encodeImage (const QImage &image, int frameIndex, QString *errorString=nullptr)
 Adds an image to the stream. More...
 
virtual bool close ()
 Closes the file. More...
 

Static Public Member Functions

static bool GetSupportedOutputFormats (std::vector< OutputFormat > &formats, bool ignoreIfNoFileExtension=true)
 Returns the list of supported output formats. More...
 

Protected Member Functions

bool isSizeValid ()
 Returns whether the image size is valid. More...
 
bool initFrame ()
 
void freeFrame ()
 
bool convertImage_sws (const QImage &image, QString *errorString=nullptr)
 Convert the QImage to the internal YUV format. More...
 

Protected Attributes

QString m_filename
 
int m_width
 
int m_height
 
unsigned m_bitrate
 
int m_gop
 
int m_fps
 
bool m_isOpen
 
FFmpegStuffEncm_ff
 FFmpeg variables. More...
 

Detailed Description

Video encoder based on FFmpeg.

Definition at line 14 of file QVideoEncoder.h.

Constructor & Destructor Documentation

◆ QVideoEncoder()

QVideoEncoder::QVideoEncoder ( QString  filename,
int  width,
int  height,
unsigned  bitrate,
int  gop = 12,
int  fps = 25 
)

Default constructor.

Parameters
filenamevideo filename
widthvideo width (must be a multiple of 8)
heightvideo height (must be a multiple of 8)
bitratebit rate (e.g. 400 000)
gopkeyframe interval
fpsframe rate

Definition at line 47 of file QVideoEncoder.cpp.

◆ ~QVideoEncoder()

QVideoEncoder::~QVideoEncoder ( )
virtual

Definition at line 62 of file QVideoEncoder.cpp.

References close(), and m_ff.

Member Function Documentation

◆ close()

bool QVideoEncoder::close ( )
virtual

Closes the file.

Definition at line 330 of file QVideoEncoder.cpp.

References FFmpegStuffEnc::codecContext, FFmpegStuffEnc::formatContext, freeFrame(), m_ff, m_isOpen, and write_frame().

Referenced by ~QVideoEncoder().

◆ convertImage_sws()

bool QVideoEncoder::convertImage_sws ( const QImage &  image,
QString *  errorString = nullptr 
)
protected

Convert the QImage to the internal YUV format.

Warning
The QImage is allocated by QT without guarantee about the alignment and bytes per lines. It should be okay as we make sure the image size is a multiple of 8 bytes however it is not guaranteed that sws_scale won't at some point require more bytes per line.

Definition at line 492 of file QVideoEncoder.cpp.

References format, FFmpegStuffEnc::frame, image, m_ff, m_height, m_width, and FFmpegStuffEnc::swsContext.

Referenced by encodeImage().

◆ encodeImage()

bool QVideoEncoder::encodeImage ( const QImage &  image,
int  frameIndex,
QString *  errorString = nullptr 
)
virtual

Adds an image to the stream.

Definition at line 394 of file QVideoEncoder.cpp.

References FFmpegStuffEnc::codecContext, convertImage_sws(), FFmpegStuffEnc::frame, image, isOpen(), m_ff, and write_frame().

◆ freeFrame()

void QVideoEncoder::freeFrame ( )
protected

Definition at line 98 of file QVideoEncoder.cpp.

References FFmpegStuffEnc::frame, and m_ff.

Referenced by close().

◆ GetSupportedOutputFormats()

bool QVideoEncoder::GetSupportedOutputFormats ( std::vector< OutputFormat > &  formats,
bool  ignoreIfNoFileExtension = true 
)
static

◆ initFrame()

bool QVideoEncoder::initFrame ( )
protected

Definition at line 75 of file QVideoEncoder.cpp.

References FFmpegStuffEnc::codecContext, FFmpegStuffEnc::frame, and m_ff.

Referenced by open().

◆ isOpen()

bool QVideoEncoder::isOpen ( ) const
inline

Returns whether the file is opened or not.

Definition at line 43 of file QVideoEncoder.h.

References m_isOpen.

Referenced by encodeImage().

◆ isSizeValid()

bool QVideoEncoder::isSizeValid ( )
protected

Returns whether the image size is valid.

Definition at line 71 of file QVideoEncoder.cpp.

References m_height, and m_width.

Referenced by open().

◆ open()

bool QVideoEncoder::open ( QString  formatShortName,
QStringList &  errors 
)

Creates an (empty) video/anmiation file.

Parameters
formatShortNameoutput format (short name)
  • If empty, the format will be automatically guessed from the filename.
  • If it can't be guessed this way then MPEG is used by default.
errors(if any)
Returns
success

Definition at line 180 of file QVideoEncoder.cpp.

References cloudViewer_ff_const59, FFmpegStuffEnc::codecContext, FFmpegStuffEnc::formatContext, initFrame(), isSizeValid(), m_bitrate, m_ff, m_filename, m_fps, m_gop, m_height, m_isOpen, m_width, and FFmpegStuffEnc::videoStream.

Member Data Documentation

◆ m_bitrate

unsigned QVideoEncoder::m_bitrate
protected

Definition at line 69 of file QVideoEncoder.h.

Referenced by open().

◆ m_ff

FFmpegStuffEnc* QVideoEncoder::m_ff
protected

FFmpeg variables.

Definition at line 75 of file QVideoEncoder.h.

Referenced by close(), convertImage_sws(), encodeImage(), freeFrame(), initFrame(), open(), and ~QVideoEncoder().

◆ m_filename

QString QVideoEncoder::m_filename
protected

Definition at line 66 of file QVideoEncoder.h.

Referenced by open().

◆ m_fps

int QVideoEncoder::m_fps
protected

Definition at line 71 of file QVideoEncoder.h.

Referenced by open().

◆ m_gop

int QVideoEncoder::m_gop
protected

Definition at line 70 of file QVideoEncoder.h.

Referenced by open().

◆ m_height

int QVideoEncoder::m_height
protected

Definition at line 68 of file QVideoEncoder.h.

Referenced by convertImage_sws(), isSizeValid(), and open().

◆ m_isOpen

bool QVideoEncoder::m_isOpen
protected

Definition at line 72 of file QVideoEncoder.h.

Referenced by close(), isOpen(), and open().

◆ m_width

int QVideoEncoder::m_width
protected

Definition at line 67 of file QVideoEncoder.h.

Referenced by convertImage_sws(), isSizeValid(), and open().


The documentation for this class was generated from the following files: