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
1ba25c55
Commit
1ba25c55
authored
May 17, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11520 from terfendail:ffmpeg_icapture
parents
45b92aeb
aeed43ec
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
49 deletions
+53
-49
cap.cpp
modules/videoio/src/cap.cpp
+16
-11
cap_ffmpeg.cpp
modules/videoio/src/cap_ffmpeg.cpp
+34
-32
precomp.hpp
modules/videoio/src/precomp.hpp
+3
-6
No files found.
modules/videoio/src/cap.cpp
View file @
1ba25c55
...
@@ -297,12 +297,6 @@ CV_IMPL CvCapture * cvCreateFileCaptureWithPreference (const char * filename, in
...
@@ -297,12 +297,6 @@ CV_IMPL CvCapture * cvCreateFileCaptureWithPreference (const char * filename, in
// bail out to let the user know that it is not available
// bail out to let the user know that it is not available
if
(
apiPreference
)
break
;
if
(
apiPreference
)
break
;
#ifdef HAVE_FFMPEG
case
CAP_FFMPEG
:
TRY_OPEN
(
result
,
cvCreateFileCapture_FFMPEG_proxy
(
filename
))
if
(
apiPreference
)
break
;
#endif
#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO
#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO
case
CAP_V4L
:
case
CAP_V4L
:
TRY_OPEN
(
result
,
cvCreateCameraCapture_V4L
(
filename
))
TRY_OPEN
(
result
,
cvCreateCameraCapture_V4L
(
filename
))
...
@@ -383,11 +377,6 @@ static CvVideoWriter* cvCreateVideoWriterWithPreference(const char* filename, in
...
@@ -383,11 +377,6 @@ static CvVideoWriter* cvCreateVideoWriterWithPreference(const char* filename, in
default
:
default
:
//exit if the specified API is unavaliable
//exit if the specified API is unavaliable
if
(
apiPreference
!=
CAP_ANY
)
break
;
if
(
apiPreference
!=
CAP_ANY
)
break
;
#ifdef HAVE_FFMPEG
case
CAP_FFMPEG
:
TRY_OPEN
(
result
,
cvCreateVideoWriter_FFMPEG_proxy
(
filename
,
fourcc
,
fps
,
frameSize
,
is_color
))
if
(
apiPreference
!=
CAP_ANY
)
break
;
#endif
#ifdef HAVE_MSMF
#ifdef HAVE_MSMF
case
CAP_MSMF
:
case
CAP_MSMF
:
TRY_OPEN
(
result
,
cvCreateVideoWriter_MSMF
(
filename
,
fourcc
,
fps
,
frameSize
,
is_color
))
TRY_OPEN
(
result
,
cvCreateVideoWriter_MSMF
(
filename
,
fourcc
,
fps
,
frameSize
,
is_color
))
...
@@ -530,6 +519,14 @@ static Ptr<IVideoCapture> IVideoCapture_create(const String& filename, int apiPr
...
@@ -530,6 +519,14 @@ static Ptr<IVideoCapture> IVideoCapture_create(const String& filename, int apiPr
{
{
bool
useAny
=
(
apiPreference
==
CAP_ANY
);
bool
useAny
=
(
apiPreference
==
CAP_ANY
);
Ptr
<
IVideoCapture
>
capture
;
Ptr
<
IVideoCapture
>
capture
;
#ifdef HAVE_FFMPEG
if
(
useAny
||
apiPreference
==
CAP_FFMPEG
)
{
capture
=
cvCreateFileCapture_FFMPEG_proxy
(
filename
);
if
(
capture
&&
capture
->
isOpened
())
return
capture
;
}
#endif
#ifdef HAVE_GSTREAMER
#ifdef HAVE_GSTREAMER
if
(
useAny
||
apiPreference
==
CAP_GSTREAMER
)
if
(
useAny
||
apiPreference
==
CAP_GSTREAMER
)
{
{
...
@@ -576,6 +573,14 @@ static Ptr<IVideoCapture> IVideoCapture_create(const String& filename, int apiPr
...
@@ -576,6 +573,14 @@ static Ptr<IVideoCapture> IVideoCapture_create(const String& filename, int apiPr
static
Ptr
<
IVideoWriter
>
IVideoWriter_create
(
const
String
&
filename
,
int
apiPreference
,
int
_fourcc
,
double
fps
,
Size
frameSize
,
bool
isColor
)
static
Ptr
<
IVideoWriter
>
IVideoWriter_create
(
const
String
&
filename
,
int
apiPreference
,
int
_fourcc
,
double
fps
,
Size
frameSize
,
bool
isColor
)
{
{
Ptr
<
IVideoWriter
>
iwriter
;
Ptr
<
IVideoWriter
>
iwriter
;
#ifdef HAVE_FFMPEG
if
(
apiPreference
==
CAP_FFMPEG
||
apiPreference
==
CAP_ANY
)
{
iwriter
=
cvCreateVideoWriter_FFMPEG_proxy
(
filename
,
_fourcc
,
fps
,
frameSize
,
isColor
);
if
(
!
iwriter
.
empty
())
return
iwriter
;
}
#endif
#ifdef HAVE_MFX
#ifdef HAVE_MFX
if
(
apiPreference
==
CAP_INTEL_MFX
||
apiPreference
==
CAP_ANY
)
if
(
apiPreference
==
CAP_INTEL_MFX
||
apiPreference
==
CAP_ANY
)
{
{
...
...
modules/videoio/src/cap_ffmpeg.cpp
View file @
1ba25c55
...
@@ -196,11 +196,11 @@ private:
...
@@ -196,11 +196,11 @@ private:
};
};
class
CvCapture_FFMPEG_proxy
CV_FINAL
:
class
CvCapture_FFMPEG_proxy
CV_FINAL
:
public
cv
::
IVideoCapture
public
CvCapture
{
{
public
:
public
:
CvCapture_FFMPEG_proxy
()
{
ffmpegCapture
=
0
;
}
CvCapture_FFMPEG_proxy
()
{
ffmpegCapture
=
0
;
}
CvCapture_FFMPEG_proxy
(
const
cv
::
String
&
filename
)
{
ffmpegCapture
=
0
;
open
(
filename
);
}
virtual
~
CvCapture_FFMPEG_proxy
()
{
close
();
}
virtual
~
CvCapture_FFMPEG_proxy
()
{
close
();
}
virtual
double
getProperty
(
int
propId
)
const
CV_OVERRIDE
virtual
double
getProperty
(
int
propId
)
const
CV_OVERRIDE
...
@@ -215,26 +215,25 @@ public:
...
@@ -215,26 +215,25 @@ public:
{
{
return
ffmpegCapture
?
icvGrabFrame_FFMPEG_p
(
ffmpegCapture
)
!=
0
:
false
;
return
ffmpegCapture
?
icvGrabFrame_FFMPEG_p
(
ffmpegCapture
)
!=
0
:
false
;
}
}
virtual
IplImage
*
retrieveFrame
(
int
)
CV_OVERRIDE
virtual
bool
retrieveFrame
(
int
,
cv
::
OutputArray
frame
)
CV_OVERRIDE
{
{
unsigned
char
*
data
=
0
;
unsigned
char
*
data
=
0
;
int
step
=
0
,
width
=
0
,
height
=
0
,
cn
=
0
;
int
step
=
0
,
width
=
0
,
height
=
0
,
cn
=
0
;
if
(
!
ffmpegCapture
||
if
(
!
ffmpegCapture
||
!
icvRetrieveFrame_FFMPEG_p
(
ffmpegCapture
,
&
data
,
&
step
,
&
width
,
&
height
,
&
cn
))
!
icvRetrieveFrame_FFMPEG_p
(
ffmpegCapture
,
&
data
,
&
step
,
&
width
,
&
height
,
&
cn
))
return
0
;
return
false
;
cvInitImageHeader
(
&
frame
,
cvSize
(
width
,
height
),
8
,
cn
);
frame
.
assign
(
cv
::
Mat
(
height
,
width
,
CV_MAKETYPE
(
CV_8U
,
cn
),
data
,
step
));
cvSetData
(
&
frame
,
data
,
step
);
return
true
;
return
&
frame
;
}
}
virtual
bool
open
(
const
c
har
*
filename
)
virtual
bool
open
(
const
c
v
::
String
&
filename
)
{
{
icvInitFFMPEG
::
Init
();
icvInitFFMPEG
::
Init
();
close
();
close
();
if
(
!
icvCreateFileCapture_FFMPEG_p
)
if
(
!
icvCreateFileCapture_FFMPEG_p
)
return
false
;
return
false
;
ffmpegCapture
=
icvCreateFileCapture_FFMPEG_p
(
filename
);
ffmpegCapture
=
icvCreateFileCapture_FFMPEG_p
(
filename
.
c_str
()
);
return
ffmpegCapture
!=
0
;
return
ffmpegCapture
!=
0
;
}
}
virtual
void
close
()
virtual
void
close
()
...
@@ -245,44 +244,45 @@ public:
...
@@ -245,44 +244,45 @@ public:
ffmpegCapture
=
0
;
ffmpegCapture
=
0
;
}
}
virtual
bool
isOpened
()
const
CV_OVERRIDE
{
return
ffmpegCapture
!=
0
;
}
virtual
int
getCaptureDomain
()
CV_OVERRIDE
{
return
CV_CAP_FFMPEG
;
}
protected
:
protected
:
void
*
ffmpegCapture
;
void
*
ffmpegCapture
;
IplImage
frame
;
};
};
CvCapture
*
cvCreateFileCapture_FFMPEG_proxy
(
const
char
*
filename
)
cv
::
Ptr
<
cv
::
IVideoCapture
>
cv
::
cvCreateFileCapture_FFMPEG_proxy
(
const
cv
::
String
&
filename
)
{
{
CvCapture_FFMPEG_proxy
*
result
=
new
CvCapture_FFMPEG_proxy
;
cv
::
Ptr
<
CvCapture_FFMPEG_proxy
>
capture
=
cv
::
makePtr
<
CvCapture_FFMPEG_proxy
>
(
filename
);
if
(
result
->
open
(
filename
))
if
(
capture
&&
capture
->
isOpened
())
return
result
;
return
capture
;
delete
result
;
return
cv
::
Ptr
<
cv
::
IVideoCapture
>
();
return
0
;
}
}
class
CvVideoWriter_FFMPEG_proxy
CV_FINAL
:
class
CvVideoWriter_FFMPEG_proxy
CV_FINAL
:
public
Cv
VideoWriter
public
cv
::
I
VideoWriter
{
{
public
:
public
:
CvVideoWriter_FFMPEG_proxy
()
{
ffmpegWriter
=
0
;
}
CvVideoWriter_FFMPEG_proxy
()
{
ffmpegWriter
=
0
;
}
CvVideoWriter_FFMPEG_proxy
(
const
cv
::
String
&
filename
,
int
fourcc
,
double
fps
,
cv
::
Size
frameSize
,
bool
isColor
)
{
ffmpegWriter
=
0
;
open
(
filename
,
fourcc
,
fps
,
frameSize
,
isColor
);
}
virtual
~
CvVideoWriter_FFMPEG_proxy
()
{
close
();
}
virtual
~
CvVideoWriter_FFMPEG_proxy
()
{
close
();
}
virtual
bool
writeFrame
(
const
IplImage
*
image
)
CV_OVERRIDE
virtual
void
write
(
cv
::
InputArray
image
)
CV_OVERRIDE
{
{
if
(
!
ffmpegWriter
)
if
(
!
ffmpegWriter
)
return
false
;
return
;
CV_Assert
(
image
->
depth
==
8
);
CV_Assert
(
image
.
depth
()
==
CV_8U
);
return
icvWriteFrame_FFMPEG_p
(
ffmpegWriter
,
(
const
uchar
*
)
image
->
imageData
,
icvWriteFrame_FFMPEG_p
(
ffmpegWriter
,
(
const
uchar
*
)
image
.
getMat
().
ptr
(),
(
int
)
image
.
step
(),
image
.
cols
(),
image
.
rows
(),
image
.
channels
(),
0
);
image
->
widthStep
,
image
->
width
,
image
->
height
,
image
->
nChannels
,
image
->
origin
)
!=
0
;
}
}
virtual
bool
open
(
const
c
har
*
filename
,
int
fourcc
,
double
fps
,
Cv
Size
frameSize
,
bool
isColor
)
virtual
bool
open
(
const
c
v
::
String
&
filename
,
int
fourcc
,
double
fps
,
cv
::
Size
frameSize
,
bool
isColor
)
{
{
icvInitFFMPEG
::
Init
();
icvInitFFMPEG
::
Init
();
close
();
close
();
if
(
!
icvCreateVideoWriter_FFMPEG_p
)
if
(
!
icvCreateVideoWriter_FFMPEG_p
)
return
false
;
return
false
;
ffmpegWriter
=
icvCreateVideoWriter_FFMPEG_p
(
filename
,
fourcc
,
fps
,
frameSize
.
width
,
frameSize
.
height
,
isColor
);
ffmpegWriter
=
icvCreateVideoWriter_FFMPEG_p
(
filename
.
c_str
()
,
fourcc
,
fps
,
frameSize
.
width
,
frameSize
.
height
,
isColor
);
return
ffmpegWriter
!=
0
;
return
ffmpegWriter
!=
0
;
}
}
...
@@ -294,18 +294,20 @@ public:
...
@@ -294,18 +294,20 @@ public:
ffmpegWriter
=
0
;
ffmpegWriter
=
0
;
}
}
virtual
double
getProperty
(
int
)
const
CV_OVERRIDE
{
return
0
;
}
virtual
bool
setProperty
(
int
,
double
)
CV_OVERRIDE
{
return
false
;
}
virtual
bool
isOpened
()
const
CV_OVERRIDE
{
return
ffmpegWriter
!=
0
;
}
protected
:
protected
:
void
*
ffmpegWriter
;
void
*
ffmpegWriter
;
};
};
CvVideoWriter
*
cvCreateVideoWriter_FFMPEG_proxy
(
const
char
*
filename
,
int
fourcc
,
cv
::
Ptr
<
cv
::
IVideoWriter
>
cv
::
cvCreateVideoWriter_FFMPEG_proxy
(
const
cv
::
String
&
filename
,
int
fourcc
,
double
fps
,
CvSize
frameSize
,
int
isColor
)
double
fps
,
cv
::
Size
frameSize
,
int
isColor
)
{
{
CvVideoWriter_FFMPEG_proxy
*
result
=
new
CvVideoWriter_FFMPEG_proxy
;
cv
::
Ptr
<
CvVideoWriter_FFMPEG_proxy
>
writer
=
cv
::
makePtr
<
CvVideoWriter_FFMPEG_proxy
>
(
filename
,
fourcc
,
fps
,
frameSize
,
isColor
!=
0
);
if
(
writer
&&
writer
->
isOpened
())
if
(
result
->
open
(
filename
,
fourcc
,
fps
,
frameSize
,
isColor
!=
0
))
return
writer
;
return
result
;
return
cv
::
Ptr
<
cv
::
IVideoWriter
>
();
delete
result
;
return
0
;
}
}
modules/videoio/src/precomp.hpp
View file @
1ba25c55
...
@@ -139,12 +139,6 @@ CvVideoWriter* cvCreateVideoWriter_Images(const char* filename);
...
@@ -139,12 +139,6 @@ CvVideoWriter* cvCreateVideoWriter_Images(const char* filename);
#define CV_CAP_GSTREAMER_V4L2 2
#define CV_CAP_GSTREAMER_V4L2 2
#define CV_CAP_GSTREAMER_FILE 3
#define CV_CAP_GSTREAMER_FILE 3
CvCapture
*
cvCreateFileCapture_FFMPEG_proxy
(
const
char
*
filename
);
CvVideoWriter
*
cvCreateVideoWriter_FFMPEG_proxy
(
const
char
*
filename
,
int
fourcc
,
double
fps
,
CvSize
frameSize
,
int
is_color
);
CvCapture
*
cvCreateFileCapture_QT
(
const
char
*
filename
);
CvCapture
*
cvCreateFileCapture_QT
(
const
char
*
filename
);
CvCapture
*
cvCreateCameraCapture_QT
(
const
int
index
);
CvCapture
*
cvCreateCameraCapture_QT
(
const
int
index
);
...
@@ -198,6 +192,9 @@ namespace cv
...
@@ -198,6 +192,9 @@ namespace cv
Ptr
<
IVideoCapture
>
createGStreamerCapture
(
const
String
&
filename
);
Ptr
<
IVideoCapture
>
createGStreamerCapture
(
const
String
&
filename
);
Ptr
<
IVideoCapture
>
createGStreamerCapture
(
int
index
);
Ptr
<
IVideoCapture
>
createGStreamerCapture
(
int
index
);
Ptr
<
cv
::
IVideoCapture
>
cvCreateFileCapture_FFMPEG_proxy
(
const
String
&
filename
);
Ptr
<
IVideoWriter
>
cvCreateVideoWriter_FFMPEG_proxy
(
const
String
&
filename
,
int
fourcc
,
double
fps
,
Size
frameSize
,
int
isColor
);
}
}
#endif
/* __VIDEOIO_H_ */
#endif
/* __VIDEOIO_H_ */
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