Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BIAS::VideoSink_FFmpeg Class Reference

Video encoding using FFmpeg library. More...

#include <VideoSink/VideoSink_FFmpeg.hh>

+ Collaboration diagram for BIAS::VideoSink_FFmpeg:

Public Member Functions

int AddFrame (const ImageBase &image)
 Add an Image to the stream and write it to the video output file. More...
 
int AddFrame (std::string filename)
 Load an Image from file and add it to the video output file. More...
 
int AddFrames (std::vector< std::string > filenames)
 Load each Image from a list of files and add them to the video output file. More...
 
int Close ()
 Close the video output file, write remaining frames and clean up. More...
 
std::string GetError ()
 Get the last error message. More...
 
bool IsOpened ()
 Get status of video output file. More...
 
int Open (std::string filename)
 Open a file for video output and init the codec. More...
 
void SetBitrate (int bitrate)
 Set bitrate in bits per second. More...
 
void SetDefaults ()
 Reset all user parameters to default values. More...
 
void SetEncoder (enum CodecID codecId)
 Set encoder. More...
 
void SetFPS (float fps)
 Set framerate in frames per second. More...
 
void SetGopSize (int gopSize)
 Set the gop size of the video stream. More...
 
void SetMaxBFrames (int maxBFrames)
 Set maximal number of bidirectional frames. More...
 
void SetOverride (bool override)
 Set if the output file should be overridden if it already exists. More...
 
void SetRealtime (bool realtime)
 Set realtime mode. More...
 
void SetSize (int width, int height)
 Set frame size of video. More...
 
 VideoSink_FFmpeg ()
 Standard constructor. More...
 
 ~VideoSink_FFmpeg ()
 Clean up. More...
 

Protected Member Functions

enum PixelFormat GetPixelFormat_ (enum ImageBase::EColorModel colorModel)
 Get the pixel format from a given color model. More...
 
void Init_ ()
 Called by constructor to init variables. More...
 

Protected Attributes

int bitrate_
 Bitrate (default: 1200000) More...
 
uint64_t bufferSize_
 Encoding buffer size. More...
 
enum CodecID codecId_
 Codec ID (default: CODEC_ID_MPEG1VIDEO) More...
 
std::string errMsg_
 The last error message. More...
 
AVRational fps_
 Framerate (default: 25) More...
 
int gopSize_
 Gop size (default: 12) More...
 
int height_
 Frame height (default: 288) More...
 
int maxBFrames_
 Max B-frames (default: 0) More...
 
bool override_
 Override flag (default: true) More...
 
uint8_t * pBuffer_
 Encoding buffer. More...
 
AVFormatContext * pFormatCtx_
 Format context for video encoder. More...
 
AVFrame * pInputPict_
 Input picture. More...
 
AVFrame * pPict_
 Output picture. More...
 
uint8_t * pPictBuffer_
 Output picture buffer. More...
 
SwsContext * pSwsCtx_
 Color conversion context. More...
 
int64_t pts_
 Presentation timestamp. More...
 
bool realtime_
 Realtime flag (default: false) More...
 
int width_
 Frame width (default: 352) More...
 

Detailed Description

Video encoding using FFmpeg library.

Author
Carsten Heine carst.nosp@m.enhe.nosp@m.ine@g.nosp@m.mx.d.nosp@m.e Supports realtime encoding.

Usage:

* // Create a video sink object
* vs = new VideoSink_FFmpeg;
*
* // Set some parameters
* vs->SetSize(640, 480);
* vs->SetEncoder(CODEC_ID_MPEG4);
* vs->SetFPS(25.0);
* vs->SetBitrate(600000);
*
* // Open output video file and write header
* vs->Open("video.mkv");
*
* // Add some images to the file
* for (int i=0; i<250; i++)
* vs->AddFrame(image[i]);
*
* // Write trailer and close the file
* vs->Close
*

For more information about supported codecs and formats visit: http://www.ffmpeg.org

Definition at line 64 of file VideoSink_FFmpeg.hh.

Constructor & Destructor Documentation

VideoSink_FFmpeg::VideoSink_FFmpeg ( )

Standard constructor.

Definition at line 10 of file VideoSink_FFmpeg.cpp.

VideoSink_FFmpeg::~VideoSink_FFmpeg ( )

Clean up.

Definition at line 17 of file VideoSink_FFmpeg.cpp.

Member Function Documentation

int VideoSink_FFmpeg::AddFrame ( const ImageBase image)
int VideoSink_FFmpeg::AddFrame ( std::string  filename)

Load an Image from file and add it to the video output file.

Returns
0 on success, -1 on error, 1 on non critical error.

Definition at line 487 of file VideoSink_FFmpeg.cpp.

References BIAS::ImageIO::Load().

int VideoSink_FFmpeg::AddFrames ( std::vector< std::string >  filenames)

Load each Image from a list of files and add them to the video output file.

Returns
0 on success, -1 on error, 1 on non critical error.

Definition at line 494 of file VideoSink_FFmpeg.cpp.

int VideoSink_FFmpeg::Close ( )

Close the video output file, write remaining frames and clean up.

Parameters set by the user will not be overridden, so you can encode another video with the same settings. To reset all parameters call SetDefaults.

Returns
0 on success, -1 on error.

Definition at line 290 of file VideoSink_FFmpeg.cpp.

std::string BIAS::VideoSink_FFmpeg::GetError ( )
inline

Get the last error message.

Definition at line 184 of file VideoSink_FFmpeg.hh.

References errMsg_.

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

enum PixelFormat VideoSink_FFmpeg::GetPixelFormat_ ( enum ImageBase::EColorModel  colorModel)
protected
void VideoSink_FFmpeg::Init_ ( )
protected

Called by constructor to init variables.

Definition at line 22 of file VideoSink_FFmpeg.cpp.

bool BIAS::VideoSink_FFmpeg::IsOpened ( )
inline

Get status of video output file.

Definition at line 179 of file VideoSink_FFmpeg.hh.

References pFormatCtx_.

int VideoSink_FFmpeg::Open ( std::string  filename)

Open a file for video output and init the codec.

The output format will be determined by the file extension. Possible values are .mkv (Matroska), .mpg (Mpeg), .mp4 (Mpeg4), .avi (Avi) and many others. The parameters set by the user will be checked at this point. If another file is already opened for output, it will be closed first. Setting any parameters after the file is opened will have no effect.

Returns
0 on success, -1 on error.

Definition at line 92 of file VideoSink_FFmpeg.cpp.

References BIAS::realtime_().

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

void VideoSink_FFmpeg::SetBitrate ( int  bitrate)

Set bitrate in bits per second.

This has to be called before Open.

Definition at line 67 of file VideoSink_FFmpeg.cpp.

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

void VideoSink_FFmpeg::SetDefaults ( )

Reset all user parameters to default values.

Definition at line 34 of file VideoSink_FFmpeg.cpp.

References BIAS::realtime_().

void VideoSink_FFmpeg::SetEncoder ( enum CodecID  codecId)

Set encoder.

Tested with CODEC_ID_MPEG4, CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO, CODEC_ID_FFV1 and some others. This has to be called before Open.

Definition at line 48 of file VideoSink_FFmpeg.cpp.

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

void VideoSink_FFmpeg::SetFPS ( float  fps)

Set framerate in frames per second.

Not all encoders support all framerates. For Mpeg1 and Mpeg2 this will try to get the best alternative, if you specify an invalid value. Check Google if you have problems setting a valid framerate. This has to be called before Open.

Definition at line 59 of file VideoSink_FFmpeg.cpp.

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

void VideoSink_FFmpeg::SetGopSize ( int  gopSize)

Set the gop size of the video stream.

This is the number of frames between fully coded intra frames. Set this to -1 for intra only. Will be ignored for encoders, that only support intra frames. This has to be called before Open.

Definition at line 72 of file VideoSink_FFmpeg.cpp.

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

void VideoSink_FFmpeg::SetMaxBFrames ( int  maxBFrames)

Set maximal number of bidirectional frames.

Set this to 0 for no B frames. Will be ignored for encoders, that don't support B-frames. This has to be called before Open.

Definition at line 77 of file VideoSink_FFmpeg.cpp.

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

void VideoSink_FFmpeg::SetOverride ( bool  override)

Set if the output file should be overridden if it already exists.

This has to be called before Open.

Definition at line 87 of file VideoSink_FFmpeg.cpp.

void VideoSink_FFmpeg::SetRealtime ( bool  realtime)

Set realtime mode.

This will set the presentation timestamps of the frames based on the real time clock for live encoding. This will adjust different time deltas between frames for playback in correct speed. This is only supported for .mkv and .flv files at the moment. This has to be called before Open.

Definition at line 82 of file VideoSink_FFmpeg.cpp.

References BIAS::realtime_().

void VideoSink_FFmpeg::SetSize ( int  width,
int  height 
)

Set frame size of video.

Resolution has to be a multiple of two. This has to be called before Open.

Definition at line 53 of file VideoSink_FFmpeg.cpp.

Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().

Member Data Documentation

int BIAS::VideoSink_FFmpeg::bitrate_
protected

Bitrate (default: 1200000)

Definition at line 203 of file VideoSink_FFmpeg.hh.

uint64_t BIAS::VideoSink_FFmpeg::bufferSize_
protected

Encoding buffer size.

Definition at line 215 of file VideoSink_FFmpeg.hh.

enum CodecID BIAS::VideoSink_FFmpeg::codecId_
protected

Codec ID (default: CODEC_ID_MPEG1VIDEO)

Definition at line 199 of file VideoSink_FFmpeg.hh.

std::string BIAS::VideoSink_FFmpeg::errMsg_
protected

The last error message.

Definition at line 216 of file VideoSink_FFmpeg.hh.

Referenced by GetError().

AVRational BIAS::VideoSink_FFmpeg::fps_
protected

Framerate (default: 25)

Definition at line 202 of file VideoSink_FFmpeg.hh.

int BIAS::VideoSink_FFmpeg::gopSize_
protected

Gop size (default: 12)

Definition at line 204 of file VideoSink_FFmpeg.hh.

int BIAS::VideoSink_FFmpeg::height_
protected

Frame height (default: 288)

Definition at line 201 of file VideoSink_FFmpeg.hh.

int BIAS::VideoSink_FFmpeg::maxBFrames_
protected

Max B-frames (default: 0)

Definition at line 205 of file VideoSink_FFmpeg.hh.

bool BIAS::VideoSink_FFmpeg::override_
protected

Override flag (default: true)

Definition at line 207 of file VideoSink_FFmpeg.hh.

uint8_t* BIAS::VideoSink_FFmpeg::pBuffer_
protected

Encoding buffer.

Definition at line 214 of file VideoSink_FFmpeg.hh.

AVFormatContext* BIAS::VideoSink_FFmpeg::pFormatCtx_
protected

Format context for video encoder.

Definition at line 209 of file VideoSink_FFmpeg.hh.

Referenced by IsOpened().

AVFrame* BIAS::VideoSink_FFmpeg::pInputPict_
protected

Input picture.

Definition at line 210 of file VideoSink_FFmpeg.hh.

AVFrame* BIAS::VideoSink_FFmpeg::pPict_
protected

Output picture.

Definition at line 212 of file VideoSink_FFmpeg.hh.

uint8_t* BIAS::VideoSink_FFmpeg::pPictBuffer_
protected

Output picture buffer.

Definition at line 213 of file VideoSink_FFmpeg.hh.

SwsContext* BIAS::VideoSink_FFmpeg::pSwsCtx_
protected

Color conversion context.

Definition at line 211 of file VideoSink_FFmpeg.hh.

int64_t BIAS::VideoSink_FFmpeg::pts_
protected

Presentation timestamp.

Definition at line 217 of file VideoSink_FFmpeg.hh.

bool BIAS::VideoSink_FFmpeg::realtime_
protected

Realtime flag (default: false)

Definition at line 206 of file VideoSink_FFmpeg.hh.

int BIAS::VideoSink_FFmpeg::width_
protected

Frame width (default: 352)

Definition at line 200 of file VideoSink_FFmpeg.hh.


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