Basic Image AlgorithmS Library
2.8.0
|
Video encoding using FFmpeg library. More...
#include <VideoSink/VideoSink_FFmpeg.hh>
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... | |
Video encoding using FFmpeg library.
Usage:
For more information about supported codecs and formats visit: http://www.ffmpeg.org
Definition at line 64 of file VideoSink_FFmpeg.hh.
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.
int VideoSink_FFmpeg::AddFrame | ( | const ImageBase & | image | ) |
Add an Image to the stream and write it to the video output file.
Resampling will be done automatically.
Definition at line 328 of file VideoSink_FFmpeg.cpp.
References BIAS::ImageBase::CM_Grey, BIAS::ImageBase::CM_invalid, BIAS::ImageBase::CM_RGB, BIAS::ImageBase::CM_UYVY422, BIAS::ImageConvert::ConvertST(), BIAS::Rescale< InputStorageType, OutputStorageType >::Downsample(), BIAS::ImageBase::GetChannelCount(), BIAS::ImageBase::GetColorModel(), BIAS::ImageBase::GetHeight(), BIAS::Image< StorageType >::GetImageData(), BIAS::ImageBase::GetSize(), BIAS::ImageBase::GetStorageType(), BIAS::ImageBase::GetWidth(), BIAS::realtime_(), BIAS::Image< StorageType >::ScaleShiftBetween(), BIAS::ImageBase::SetColorModel(), BIAS::ImageBase::ST_unsignedchar, BIAS::ImageConvert::ToRGB(), and BIAS::Rescale< InputStorageType, OutputStorageType >::Upsample().
Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().
int VideoSink_FFmpeg::AddFrame | ( | std::string | filename | ) |
Load an Image from file and add it to the video output file.
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.
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.
Definition at line 290 of file VideoSink_FFmpeg.cpp.
|
inline |
Get the last error message.
Definition at line 184 of file VideoSink_FFmpeg.hh.
References errMsg_.
Referenced by BIAS::BVWXMainFrame::OnSaveAsMovie().
|
protected |
Get the pixel format from a given color model.
Definition at line 503 of file VideoSink_FFmpeg.cpp.
References BIAS::ImageBase::CM_BGR, BIAS::ImageBase::CM_BGRA, BIAS::ImageBase::CM_Grey, BIAS::ImageBase::CM_GreyA, BIAS::ImageBase::CM_RGB, BIAS::ImageBase::CM_RGBA, BIAS::ImageBase::CM_UYVY422, BIAS::ImageBase::CM_YUV411, BIAS::ImageBase::CM_YUV420P, BIAS::ImageBase::CM_YUV444, and BIAS::ImageBase::CM_YUYV422.
|
protected |
Called by constructor to init variables.
Definition at line 22 of file VideoSink_FFmpeg.cpp.
|
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.
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().
|
protected |
Bitrate (default: 1200000)
Definition at line 203 of file VideoSink_FFmpeg.hh.
|
protected |
Encoding buffer size.
Definition at line 215 of file VideoSink_FFmpeg.hh.
|
protected |
Codec ID (default: CODEC_ID_MPEG1VIDEO)
Definition at line 199 of file VideoSink_FFmpeg.hh.
|
protected |
The last error message.
Definition at line 216 of file VideoSink_FFmpeg.hh.
Referenced by GetError().
|
protected |
Framerate (default: 25)
Definition at line 202 of file VideoSink_FFmpeg.hh.
|
protected |
Gop size (default: 12)
Definition at line 204 of file VideoSink_FFmpeg.hh.
|
protected |
Frame height (default: 288)
Definition at line 201 of file VideoSink_FFmpeg.hh.
|
protected |
Max B-frames (default: 0)
Definition at line 205 of file VideoSink_FFmpeg.hh.
|
protected |
Override flag (default: true)
Definition at line 207 of file VideoSink_FFmpeg.hh.
|
protected |
Encoding buffer.
Definition at line 214 of file VideoSink_FFmpeg.hh.
|
protected |
Format context for video encoder.
Definition at line 209 of file VideoSink_FFmpeg.hh.
Referenced by IsOpened().
|
protected |
Input picture.
Definition at line 210 of file VideoSink_FFmpeg.hh.
|
protected |
Output picture.
Definition at line 212 of file VideoSink_FFmpeg.hh.
|
protected |
Output picture buffer.
Definition at line 213 of file VideoSink_FFmpeg.hh.
|
protected |
Color conversion context.
Definition at line 211 of file VideoSink_FFmpeg.hh.
|
protected |
Presentation timestamp.
Definition at line 217 of file VideoSink_FFmpeg.hh.
|
protected |
Realtime flag (default: false)
Definition at line 206 of file VideoSink_FFmpeg.hh.
|
protected |
Frame width (default: 352)
Definition at line 200 of file VideoSink_FFmpeg.hh.