Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
e9a74c17
Commit
e9a74c17
authored
Apr 22, 2013
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored VideoWriter class (convert it to abstract interface)
parent
7a07f1a9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
62 deletions
+53
-62
videoenc.rst
modules/gpucodec/doc/videoenc.rst
+0
-0
gpucodec.hpp
modules/gpucodec/include/opencv2/gpucodec.hpp
+39
-49
perf_video.cpp
modules/gpucodec/perf/perf_video.cpp
+4
-4
precomp.hpp
modules/gpucodec/src/precomp.hpp
+1
-0
video_writer.cpp
modules/gpucodec/src/video_writer.cpp
+0
-0
test_video.cpp
modules/gpucodec/test/test_video.cpp
+5
-5
video_writer.cpp
samples/gpu/video_writer.cpp
+4
-4
No files found.
modules/gpucodec/doc/videoenc.rst
View file @
e9a74c17
This diff is collapsed.
Click to expand it.
modules/gpucodec/include/opencv2/gpucodec.hpp
View file @
e9a74c17
...
...
@@ -12,6 +12,7 @@
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
@@ -51,22 +52,15 @@
#include "opencv2/core/gpu.hpp"
namespace
cv
{
namespace
gpu
{
namespace
cv
{
namespace
gpu
codec
{
////////////////////////////////// Video Encoding //////////////////////////////////
// Works only under Windows
// Supports olny H264 video codec and AVI files
class
CV_EXPORTS
VideoWriter_GPU
{
public
:
struct
EncoderParams
;
// Works only under Windows.
// Supports olny H264 video codec and AVI files.
// Callbacks for video encoder, use it if you want to work with raw video stream
class
EncoderCallBack
;
enum
SurfaceFormat
{
enum
SurfaceFormat
{
SF_UYVY
=
0
,
SF_YUY2
,
SF_YV12
,
...
...
@@ -74,28 +68,10 @@ public:
SF_IYUV
,
SF_BGR
,
SF_GRAY
=
SF_BGR
};
VideoWriter_GPU
();
VideoWriter_GPU
(
const
String
&
fileName
,
cv
::
Size
frameSize
,
double
fps
,
SurfaceFormat
format
=
SF_BGR
);
VideoWriter_GPU
(
const
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
,
SurfaceFormat
format
=
SF_BGR
);
VideoWriter_GPU
(
const
cv
::
Ptr
<
EncoderCallBack
>&
encoderCallback
,
cv
::
Size
frameSize
,
double
fps
,
const
EncoderParams
&
params
,
SurfaceFormat
format
=
SF_BGR
);
~
VideoWriter_GPU
();
// all methods throws cv::Exception if error occurs
void
open
(
const
String
&
fileName
,
cv
::
Size
frameSize
,
double
fps
,
SurfaceFormat
format
=
SF_BGR
);
void
open
(
const
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
,
SurfaceFormat
format
=
SF_BGR
);
void
open
(
const
cv
::
Ptr
<
EncoderCallBack
>&
encoderCallback
,
cv
::
Size
frameSize
,
double
fps
,
const
EncoderParams
&
params
,
SurfaceFormat
format
=
SF_BGR
);
bool
isOpened
()
const
;
void
close
();
void
write
(
const
cv
::
gpu
::
GpuMat
&
image
,
bool
lastFrame
=
false
);
};
struct
CV_EXPORTS
EncoderParams
{
struct
CV_EXPORTS
EncoderParams
{
int
P_Interval
;
// NVVE_P_INTERVAL,
int
IDR_Period
;
// NVVE_IDR_PERIOD,
int
DynamicGOP
;
// NVVE_DYNAMIC_GOP,
...
...
@@ -121,13 +97,11 @@ public:
void
load
(
const
String
&
configFile
);
void
save
(
const
String
&
configFile
)
const
;
};
EncoderParams
getParams
()
const
;
};
class
CV_EXPORTS
EncoderCallBack
{
public
:
class
CV_EXPORTS
EncoderCallBack
{
public
:
enum
PicType
{
IFRAME
=
1
,
...
...
@@ -137,26 +111,43 @@ public:
virtual
~
EncoderCallBack
()
{}
//
callback function to signal the start of bitstream that is to be encoded
// must return pointer to buffer
//!
callback function to signal the start of bitstream that is to be encoded
//! callback must allocate host buffer for CUDA encoder and return pointer to it and it's size
virtual
uchar
*
acquireBitStream
(
int
*
bufferSize
)
=
0
;
//
callback function to signal that the encoded bitstream is ready to be written to file
//!
callback function to signal that the encoded bitstream is ready to be written to file
virtual
void
releaseBitStream
(
unsigned
char
*
data
,
int
size
)
=
0
;
//
callback function to signal that the encoding operation on the frame has started
//!
callback function to signal that the encoding operation on the frame has started
virtual
void
onBeginFrame
(
int
frameNumber
,
PicType
picType
)
=
0
;
//
callback function signals that the encoding operation on the frame has finished
//!
callback function signals that the encoding operation on the frame has finished
virtual
void
onEndFrame
(
int
frameNumber
,
PicType
picType
)
=
0
;
};
};
class
Impl
;
class
CV_EXPORTS
VideoWriter
{
public
:
virtual
~
VideoWriter
()
{}
private
:
cv
::
Ptr
<
Impl
>
impl_
;
//! writes the next frame from GPU memory
virtual
void
write
(
InputArray
frame
,
bool
lastFrame
=
false
)
=
0
;
virtual
EncoderParams
getEncoderParams
()
const
=
0
;
};
//! create VideoWriter for specified output file (only AVI file format is supported)
CV_EXPORTS
Ptr
<
VideoWriter
>
createVideoWriter
(
const
String
&
fileName
,
Size
frameSize
,
double
fps
,
SurfaceFormat
format
=
SF_BGR
);
CV_EXPORTS
Ptr
<
VideoWriter
>
createVideoWriter
(
const
String
&
fileName
,
Size
frameSize
,
double
fps
,
const
EncoderParams
&
params
,
SurfaceFormat
format
=
SF_BGR
);
//! create VideoWriter for user-defined callbacks
CV_EXPORTS
Ptr
<
VideoWriter
>
createVideoWriter
(
const
Ptr
<
EncoderCallBack
>&
encoderCallback
,
Size
frameSize
,
double
fps
,
SurfaceFormat
format
=
SF_BGR
);
CV_EXPORTS
Ptr
<
VideoWriter
>
createVideoWriter
(
const
Ptr
<
EncoderCallBack
>&
encoderCallback
,
Size
frameSize
,
double
fps
,
const
EncoderParams
&
params
,
SurfaceFormat
format
=
SF_BGR
);
}}
// namespace cv { namespace gpucodec {
namespace
cv
{
namespace
gpu
{
////////////////////////////////// Video Decoding //////////////////////////////////////////
namespace
detail
...
...
@@ -257,7 +248,6 @@ private:
namespace
cv
{
template
<>
CV_EXPORTS
void
Ptr
<
cv
::
gpu
::
VideoWriter_GPU
::
Impl
>::
delete_obj
();
template
<>
CV_EXPORTS
void
Ptr
<
cv
::
gpu
::
VideoReader_GPU
::
Impl
>::
delete_obj
();
}
...
...
modules/gpucodec/perf/perf_video.cpp
View file @
e9a74c17
...
...
@@ -119,7 +119,7 @@ PERF_TEST_P(FileName, VideoWriter, Values("gpu/video/768x576.avi", "gpu/video/19
if
(
PERF_RUN_GPU
())
{
cv
::
gpu
::
VideoWriter_GPU
d_writer
;
cv
::
Ptr
<
cv
::
gpucodec
::
VideoWriter
>
d_writer
;
cv
::
gpu
::
GpuMat
d_frame
;
...
...
@@ -130,11 +130,11 @@ PERF_TEST_P(FileName, VideoWriter, Values("gpu/video/768x576.avi", "gpu/video/19
d_frame
.
upload
(
frame
);
if
(
!
d_writer
.
isOpened
())
d_writer
.
open
(
outputFile
,
frame
.
size
(),
FPS
);
if
(
d_writer
.
empty
())
d_writer
=
cv
::
gpucodec
::
createVideoWriter
(
outputFile
,
frame
.
size
(),
FPS
);
startTimer
();
next
();
d_writer
.
write
(
d_frame
);
d_writer
->
write
(
d_frame
);
stopTimer
();
}
}
...
...
modules/gpucodec/src/precomp.hpp
View file @
e9a74c17
...
...
@@ -12,6 +12,7 @@
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
modules/gpucodec/src/video_writer.cpp
View file @
e9a74c17
This diff is collapsed.
Click to expand it.
modules/gpucodec/test/test_video.cpp
View file @
e9a74c17
...
...
@@ -89,7 +89,7 @@ GPU_TEST_P(Video, Writer)
cv
::
VideoCapture
reader
(
inputFile
);
ASSERT_TRUE
(
reader
.
isOpened
());
cv
::
gpu
::
VideoWriter_GPU
d_writer
;
cv
::
Ptr
<
cv
::
gpucodec
::
VideoWriter
>
d_writer
;
cv
::
Mat
frame
;
cv
::
gpu
::
GpuMat
d_frame
;
...
...
@@ -101,14 +101,14 @@ GPU_TEST_P(Video, Writer)
d_frame
.
upload
(
frame
);
if
(
!
d_writer
.
isOpened
())
d_writer
.
open
(
outputFile
,
frame
.
size
(),
FPS
);
if
(
d_writer
.
empty
())
d_writer
=
cv
::
gpucodec
::
createVideoWriter
(
outputFile
,
frame
.
size
(),
FPS
);
d_writer
.
write
(
d_frame
);
d_writer
->
write
(
d_frame
);
}
reader
.
release
();
d_writer
.
clo
se
();
d_writer
.
relea
se
();
reader
.
open
(
outputFile
);
ASSERT_TRUE
(
reader
.
isOpened
());
...
...
samples/gpu/video_writer.cpp
View file @
e9a74c17
...
...
@@ -33,7 +33,7 @@ int main(int argc, const char* argv[])
cv
::
gpu
::
printShortCudaDeviceInfo
(
cv
::
gpu
::
getDevice
());
cv
::
VideoWriter
writer
;
cv
::
gpu
::
VideoWriter_GPU
d_writer
;
cv
::
Ptr
<
cv
::
gpucodec
::
VideoWriter
>
d_writer
;
cv
::
Mat
frame
;
cv
::
gpu
::
GpuMat
d_frame
;
...
...
@@ -64,11 +64,11 @@ int main(int argc, const char* argv[])
return
-
1
;
}
if
(
!
d_writer
.
isOpened
())
if
(
d_writer
.
empty
())
{
std
::
cout
<<
"Open GPU Writer"
<<
std
::
endl
;
d_writer
.
open
(
"output_gpu.avi"
,
frame
.
size
(),
FPS
);
d_writer
=
cv
::
gpucodec
::
createVideoWriter
(
"output_gpu.avi"
,
frame
.
size
(),
FPS
);
}
d_frame
.
upload
(
frame
);
...
...
@@ -81,7 +81,7 @@ int main(int argc, const char* argv[])
cpu_times
.
push_back
(
tm
.
getTimeMilli
());
tm
.
reset
();
tm
.
start
();
d_writer
.
write
(
d_frame
);
d_writer
->
write
(
d_frame
);
tm
.
stop
();
gpu_times
.
push_back
(
tm
.
getTimeMilli
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment