Commit 70909738 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

added support of different surface formats to VideoWriter_GPU

added key frame handling to ffmpeg wrappers
parent 4c44ccc3
...@@ -1898,18 +1898,29 @@ public: ...@@ -1898,18 +1898,29 @@ public:
// Callbacks for video encoder, use it if you want to work with raw video stream // Callbacks for video encoder, use it if you want to work with raw video stream
class EncoderCallBack; class EncoderCallBack;
enum SurfaceFormat
{
SF_UYVY = 0,
SF_YUY2,
SF_YV12,
SF_NV12,
SF_IYUV,
SF_BGR,
SF_GRAY = SF_BGR
};
VideoWriter_GPU(); VideoWriter_GPU();
VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps); VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params); VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps); VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params); VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
~VideoWriter_GPU(); ~VideoWriter_GPU();
// all methods throws cv::Exception if error occurs // all methods throws cv::Exception if error occurs
void open(const std::string& fileName, cv::Size frameSize, double fps); void open(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
void open(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params); void open(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps); void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params); void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
bool isOpened() const; bool isOpened() const;
void close(); void close();
......
This diff is collapsed.
...@@ -71,11 +71,11 @@ typedef void (*CvReleaseVideoWriter_Plugin)( void** writer ); ...@@ -71,11 +71,11 @@ typedef void (*CvReleaseVideoWriter_Plugin)( void** writer );
OPENCV_FFMPEG_API struct OutputMediaStream_FFMPEG* create_OutputMediaStream_FFMPEG(const char* fileName, int width, int height, double fps); OPENCV_FFMPEG_API struct OutputMediaStream_FFMPEG* create_OutputMediaStream_FFMPEG(const char* fileName, int width, int height, double fps);
OPENCV_FFMPEG_API void release_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream); OPENCV_FFMPEG_API void release_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream);
OPENCV_FFMPEG_API void write_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size); OPENCV_FFMPEG_API void write_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size, int keyFrame);
typedef struct OutputMediaStream_FFMPEG* (*Create_OutputMediaStream_FFMPEG_Plugin)(const char* fileName, int width, int height, double fps); typedef struct OutputMediaStream_FFMPEG* (*Create_OutputMediaStream_FFMPEG_Plugin)(const char* fileName, int width, int height, double fps);
typedef void (*Release_OutputMediaStream_FFMPEG_Plugin)(struct OutputMediaStream_FFMPEG* stream); typedef void (*Release_OutputMediaStream_FFMPEG_Plugin)(struct OutputMediaStream_FFMPEG* stream);
typedef void (*Write_OutputMediaStream_FFMPEG_Plugin)(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size); typedef void (*Write_OutputMediaStream_FFMPEG_Plugin)(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size, int keyFrame);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -1454,9 +1454,9 @@ void CvVideoWriter_FFMPEG::close() ...@@ -1454,9 +1454,9 @@ void CvVideoWriter_FFMPEG::close()
struct OutputMediaStream_FFMPEG struct OutputMediaStream_FFMPEG
{ {
bool open(const char* fileName, int width, int height, double fps); bool open(const char* fileName, int width, int height, double fps);
void write(unsigned char* data, int size);
void close(); void close();
void write(unsigned char* data, int size, int keyFrame);
// add a video output stream to the container // add a video output stream to the container
static AVStream* addVideoStream(AVFormatContext *oc, CodecID codec_id, int w, int h, int bitrate, double fps, PixelFormat pixel_format); static AVStream* addVideoStream(AVFormatContext *oc, CodecID codec_id, int w, int h, int bitrate, double fps, PixelFormat pixel_format);
...@@ -1698,13 +1698,16 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height, ...@@ -1698,13 +1698,16 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height,
return true; return true;
} }
void OutputMediaStream_FFMPEG::write(unsigned char* data, int size) void OutputMediaStream_FFMPEG::write(unsigned char* data, int size, int keyFrame)
{ {
// if zero size, it means the image was buffered // if zero size, it means the image was buffered
if (size > 0) if (size > 0)
{ {
AVPacket pkt; AVPacket pkt;
av_init_packet(&pkt); av_init_packet(&pkt);
if (keyFrame)
pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index = video_st_->index; pkt.stream_index = video_st_->index;
pkt.data = data; pkt.data = data;
...@@ -1734,7 +1737,7 @@ void release_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream) ...@@ -1734,7 +1737,7 @@ void release_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream)
free(stream); free(stream);
} }
void write_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size) void write_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size, int keyFrame)
{ {
stream->write(data, size); stream->write(data, size, keyFrame);
} }
...@@ -1620,9 +1620,9 @@ void CvVideoWriter_FFMPEG::close() ...@@ -1620,9 +1620,9 @@ void CvVideoWriter_FFMPEG::close()
struct OutputMediaStream_FFMPEG struct OutputMediaStream_FFMPEG
{ {
bool open(const char* fileName, int width, int height, double fps); bool open(const char* fileName, int width, int height, double fps);
void write(unsigned char* data, int size);
void close(); void close();
void write(unsigned char* data, int size, int keyFrame);
// add a video output stream to the container // add a video output stream to the container
static AVStream* addVideoStream(AVFormatContext *oc, CodecID codec_id, int w, int h, int bitrate, double fps, PixelFormat pixel_format); static AVStream* addVideoStream(AVFormatContext *oc, CodecID codec_id, int w, int h, int bitrate, double fps, PixelFormat pixel_format);
...@@ -1864,7 +1864,7 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height, ...@@ -1864,7 +1864,7 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height,
return true; return true;
} }
void OutputMediaStream_FFMPEG::write(unsigned char* data, int size) void OutputMediaStream_FFMPEG::write(unsigned char* data, int size, int keyFrame)
{ {
// if zero size, it means the image was buffered // if zero size, it means the image was buffered
if (size > 0) if (size > 0)
...@@ -1872,6 +1872,9 @@ void OutputMediaStream_FFMPEG::write(unsigned char* data, int size) ...@@ -1872,6 +1872,9 @@ void OutputMediaStream_FFMPEG::write(unsigned char* data, int size)
AVPacket pkt; AVPacket pkt;
av_init_packet(&pkt); av_init_packet(&pkt);
if (keyFrame)
pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index = video_st_->index; pkt.stream_index = video_st_->index;
pkt.data = data; pkt.data = data;
pkt.size = size; pkt.size = size;
...@@ -1900,7 +1903,7 @@ void release_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream) ...@@ -1900,7 +1903,7 @@ void release_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream)
free(stream); free(stream);
} }
void write_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size) void write_OutputMediaStream_FFMPEG(struct OutputMediaStream_FFMPEG* stream, unsigned char* data, int size, int keyFrame)
{ {
stream->write(data, size); stream->write(data, size, keyFrame);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment