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
eb3c9ed1
Commit
eb3c9ed1
authored
Apr 04, 2013
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ffmpeg wrapper compatibility with libavcodec > 53.25.0
Based on pull request #685
parent
1e9ed142
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
24 deletions
+32
-24
cap_ffmpeg_impl.hpp
modules/highgui/src/cap_ffmpeg_impl.hpp
+32
-24
No files found.
modules/highgui/src/cap_ffmpeg_impl.hpp
View file @
eb3c9ed1
...
@@ -148,6 +148,14 @@ extern "C" {
...
@@ -148,6 +148,14 @@ extern "C" {
#define AVERROR_EOF (-MKTAG( 'E','O','F',' '))
#define AVERROR_EOF (-MKTAG( 'E','O','F',' '))
#endif
#endif
#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54,25,0)
# define CV_CODEC_ID AVCodecID
# define CV_CODEC(name) AV_##name
#else
# define CV_CODEC_ID CodecID
# define CV_CODEC(name) name
#endif
static
int
get_number_of_cpus
(
void
)
static
int
get_number_of_cpus
(
void
)
{
{
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(52, 111, 0)
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(52, 111, 0)
...
@@ -1021,7 +1029,7 @@ static const char * icvFFMPEGErrStr(int err)
...
@@ -1021,7 +1029,7 @@ static const char * icvFFMPEGErrStr(int err)
/* function internal to FFMPEG (libavformat/riff.c) to lookup codec id by fourcc tag*/
/* function internal to FFMPEG (libavformat/riff.c) to lookup codec id by fourcc tag*/
extern
"C"
{
extern
"C"
{
enum
C
odec
ID
codec_get_bmp_id
(
unsigned
int
tag
);
enum
C
V_CODEC_
ID
codec_get_bmp_id
(
unsigned
int
tag
);
}
}
void
CvVideoWriter_FFMPEG
::
init
()
void
CvVideoWriter_FFMPEG
::
init
()
...
@@ -1073,7 +1081,7 @@ static AVFrame * icv_alloc_picture_FFMPEG(int pix_fmt, int width, int height, bo
...
@@ -1073,7 +1081,7 @@ static AVFrame * icv_alloc_picture_FFMPEG(int pix_fmt, int width, int height, bo
/* add a video output stream to the container */
/* add a video output stream to the container */
static
AVStream
*
icv_add_video_stream_FFMPEG
(
AVFormatContext
*
oc
,
static
AVStream
*
icv_add_video_stream_FFMPEG
(
AVFormatContext
*
oc
,
C
odec
ID
codec_id
,
C
V_CODEC_
ID
codec_id
,
int
w
,
int
h
,
int
bitrate
,
int
w
,
int
h
,
int
bitrate
,
double
fps
,
int
pixel_format
)
double
fps
,
int
pixel_format
)
{
{
...
@@ -1105,7 +1113,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
...
@@ -1105,7 +1113,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
c
->
codec_id
=
oc
->
oformat
->
video_codec
;
c
->
codec_id
=
oc
->
oformat
->
video_codec
;
#endif
#endif
if
(
codec_id
!=
C
ODEC_ID_NONE
){
if
(
codec_id
!=
C
V_CODEC
(
CODEC_ID_NONE
)
){
c
->
codec_id
=
codec_id
;
c
->
codec_id
=
codec_id
;
}
}
...
@@ -1166,10 +1174,10 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
...
@@ -1166,10 +1174,10 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
c
->
gop_size
=
12
;
/* emit one intra frame every twelve frames at most */
c
->
gop_size
=
12
;
/* emit one intra frame every twelve frames at most */
c
->
pix_fmt
=
(
PixelFormat
)
pixel_format
;
c
->
pix_fmt
=
(
PixelFormat
)
pixel_format
;
if
(
c
->
codec_id
==
C
ODEC_ID_MPEG2VIDEO
)
{
if
(
c
->
codec_id
==
C
V_CODEC
(
CODEC_ID_MPEG2VIDEO
)
)
{
c
->
max_b_frames
=
2
;
c
->
max_b_frames
=
2
;
}
}
if
(
c
->
codec_id
==
C
ODEC_ID_MPEG1VIDEO
||
c
->
codec_id
==
CODEC_ID_MSMPEG4V3
){
if
(
c
->
codec_id
==
C
V_CODEC
(
CODEC_ID_MPEG1VIDEO
)
||
c
->
codec_id
==
CV_CODEC
(
CODEC_ID_MSMPEG4V3
)
){
/* needed to avoid using macroblocks in which some coeffs overflow
/* needed to avoid using macroblocks in which some coeffs overflow
this doesnt happen with normal video, it just happens here as the
this doesnt happen with normal video, it just happens here as the
motion of the chroma plane doesnt match the luma plane */
motion of the chroma plane doesnt match the luma plane */
...
@@ -1263,7 +1271,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
...
@@ -1263,7 +1271,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
#if LIBAVFORMAT_BUILD < 5231
#if LIBAVFORMAT_BUILD < 5231
// It is not needed in the latest versions of the ffmpeg
// It is not needed in the latest versions of the ffmpeg
if
(
c
->
codec_id
==
C
ODEC_ID_RAWVIDEO
&&
origin
!=
1
)
if
(
c
->
codec_id
==
C
V_CODEC
(
CODEC_ID_RAWVIDEO
)
&&
origin
!=
1
)
{
{
if
(
!
temp_image
.
data
)
if
(
!
temp_image
.
data
)
{
{
...
@@ -1450,7 +1458,7 @@ void CvVideoWriter_FFMPEG::close()
...
@@ -1450,7 +1458,7 @@ void CvVideoWriter_FFMPEG::close()
bool
CvVideoWriter_FFMPEG
::
open
(
const
char
*
filename
,
int
fourcc
,
bool
CvVideoWriter_FFMPEG
::
open
(
const
char
*
filename
,
int
fourcc
,
double
fps
,
int
width
,
int
height
,
bool
is_color
)
double
fps
,
int
width
,
int
height
,
bool
is_color
)
{
{
C
odecID
codec_id
=
CODEC_ID_NONE
;
C
V_CODEC_ID
codec_id
=
CV_CODEC
(
CODEC_ID_NONE
)
;
int
err
,
codec_pix_fmt
;
int
err
,
codec_pix_fmt
;
double
bitrate_scale
=
1
;
double
bitrate_scale
=
1
;
...
@@ -1491,11 +1499,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
...
@@ -1491,11 +1499,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
/* Lookup codec_id for given fourcc */
/* Lookup codec_id for given fourcc */
#if LIBAVCODEC_VERSION_INT<((51<<16)+(49<<8)+0)
#if LIBAVCODEC_VERSION_INT<((51<<16)+(49<<8)+0)
if
(
(
codec_id
=
codec_get_bmp_id
(
fourcc
))
==
C
ODEC_ID_NONE
)
if
(
(
codec_id
=
codec_get_bmp_id
(
fourcc
))
==
C
V_CODEC
(
CODEC_ID_NONE
)
)
return
false
;
return
false
;
#else
#else
const
struct
AVCodecTag
*
tags
[]
=
{
codec_bmp_tags
,
NULL
};
const
struct
AVCodecTag
*
tags
[]
=
{
codec_bmp_tags
,
NULL
};
if
(
(
codec_id
=
av_codec_get_id
(
tags
,
fourcc
))
==
C
ODEC_ID_NONE
)
if
(
(
codec_id
=
av_codec_get_id
(
tags
,
fourcc
))
==
C
V_CODEC
(
CODEC_ID_NONE
)
)
return
false
;
return
false
;
#endif
#endif
...
@@ -1517,20 +1525,20 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
...
@@ -1517,20 +1525,20 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
// set a few optimal pixel formats for lossless codecs of interest..
// set a few optimal pixel formats for lossless codecs of interest..
switch
(
codec_id
)
{
switch
(
codec_id
)
{
#if LIBAVCODEC_VERSION_INT>((50<<16)+(1<<8)+0)
#if LIBAVCODEC_VERSION_INT>((50<<16)+(1<<8)+0)
case
C
ODEC_ID_JPEGLS
:
case
C
V_CODEC
(
CODEC_ID_JPEGLS
)
:
// BGR24 or GRAY8 depending on is_color...
// BGR24 or GRAY8 depending on is_color...
codec_pix_fmt
=
input_pix_fmt
;
codec_pix_fmt
=
input_pix_fmt
;
break
;
break
;
#endif
#endif
case
C
ODEC_ID_HUFFYUV
:
case
C
V_CODEC
(
CODEC_ID_HUFFYUV
)
:
codec_pix_fmt
=
PIX_FMT_YUV422P
;
codec_pix_fmt
=
PIX_FMT_YUV422P
;
break
;
break
;
case
C
ODEC_ID_MJPEG
:
case
C
V_CODEC
(
CODEC_ID_MJPEG
)
:
case
C
ODEC_ID_LJPEG
:
case
C
V_CODEC
(
CODEC_ID_LJPEG
)
:
codec_pix_fmt
=
PIX_FMT_YUVJ420P
;
codec_pix_fmt
=
PIX_FMT_YUVJ420P
;
bitrate_scale
=
3
;
bitrate_scale
=
3
;
break
;
break
;
case
C
ODEC_ID_RAWVIDEO
:
case
C
V_CODEC
(
CODEC_ID_RAWVIDEO
)
:
codec_pix_fmt
=
input_pix_fmt
==
PIX_FMT_GRAY8
||
codec_pix_fmt
=
input_pix_fmt
==
PIX_FMT_GRAY8
||
input_pix_fmt
==
PIX_FMT_GRAY16LE
||
input_pix_fmt
==
PIX_FMT_GRAY16LE
||
input_pix_fmt
==
PIX_FMT_GRAY16BE
?
input_pix_fmt
:
PIX_FMT_YUV420P
;
input_pix_fmt
==
PIX_FMT_GRAY16BE
?
input_pix_fmt
:
PIX_FMT_YUV420P
;
...
@@ -1761,7 +1769,7 @@ struct OutputMediaStream_FFMPEG
...
@@ -1761,7 +1769,7 @@ struct OutputMediaStream_FFMPEG
void
write
(
unsigned
char
*
data
,
int
size
,
int
keyFrame
);
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
,
C
odec
ID
codec_id
,
int
w
,
int
h
,
int
bitrate
,
double
fps
,
PixelFormat
pixel_format
);
static
AVStream
*
addVideoStream
(
AVFormatContext
*
oc
,
C
V_CODEC_
ID
codec_id
,
int
w
,
int
h
,
int
bitrate
,
double
fps
,
PixelFormat
pixel_format
);
AVOutputFormat
*
fmt_
;
AVOutputFormat
*
fmt_
;
AVFormatContext
*
oc_
;
AVFormatContext
*
oc_
;
...
@@ -1808,7 +1816,7 @@ void OutputMediaStream_FFMPEG::close()
...
@@ -1808,7 +1816,7 @@ void OutputMediaStream_FFMPEG::close()
}
}
}
}
AVStream
*
OutputMediaStream_FFMPEG
::
addVideoStream
(
AVFormatContext
*
oc
,
C
odec
ID
codec_id
,
int
w
,
int
h
,
int
bitrate
,
double
fps
,
PixelFormat
pixel_format
)
AVStream
*
OutputMediaStream_FFMPEG
::
addVideoStream
(
AVFormatContext
*
oc
,
C
V_CODEC_
ID
codec_id
,
int
w
,
int
h
,
int
bitrate
,
double
fps
,
PixelFormat
pixel_format
)
{
{
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 10, 0)
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 10, 0)
AVStream
*
st
=
avformat_new_stream
(
oc
,
0
);
AVStream
*
st
=
avformat_new_stream
(
oc
,
0
);
...
@@ -1888,10 +1896,10 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CodecID
...
@@ -1888,10 +1896,10 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CodecID
c
->
gop_size
=
12
;
// emit one intra frame every twelve frames at most
c
->
gop_size
=
12
;
// emit one intra frame every twelve frames at most
c
->
pix_fmt
=
pixel_format
;
c
->
pix_fmt
=
pixel_format
;
if
(
c
->
codec_id
==
C
ODEC_ID_MPEG2VIDEO
)
if
(
c
->
codec_id
==
C
V_CODEC
(
CODEC_ID_MPEG2VIDEO
)
)
c
->
max_b_frames
=
2
;
c
->
max_b_frames
=
2
;
if
(
c
->
codec_id
==
C
ODEC_ID_MPEG1VIDEO
||
c
->
codec_id
==
CODEC_ID_MSMPEG4V3
)
if
(
c
->
codec_id
==
C
V_CODEC
(
CODEC_ID_MPEG1VIDEO
)
||
c
->
codec_id
==
CV_CODEC
(
CODEC_ID_MSMPEG4V3
)
)
{
{
// needed to avoid using macroblocks in which some coeffs overflow
// needed to avoid using macroblocks in which some coeffs overflow
// this doesnt happen with normal video, it just happens here as the
// this doesnt happen with normal video, it just happens here as the
...
@@ -1928,7 +1936,7 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height,
...
@@ -1928,7 +1936,7 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height,
if
(
!
fmt_
)
if
(
!
fmt_
)
return
false
;
return
false
;
C
odecID
codec_id
=
CODEC_ID_H264
;
C
V_CODEC_ID
codec_id
=
CV_CODEC
(
CODEC_ID_H264
)
;
// alloc memory for context
// alloc memory for context
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
...
@@ -2129,23 +2137,23 @@ bool InputMediaStream_FFMPEG::open(const char* fileName, int* codec, int* chroma
...
@@ -2129,23 +2137,23 @@ bool InputMediaStream_FFMPEG::open(const char* fileName, int* codec, int* chroma
switch
(
enc
->
codec_id
)
switch
(
enc
->
codec_id
)
{
{
case
C
ODEC_ID_MPEG1VIDEO
:
case
C
V_CODEC
(
CODEC_ID_MPEG1VIDEO
)
:
*
codec
=
::
VideoCodec_MPEG1
;
*
codec
=
::
VideoCodec_MPEG1
;
break
;
break
;
case
C
ODEC_ID_MPEG2VIDEO
:
case
C
V_CODEC
(
CODEC_ID_MPEG2VIDEO
)
:
*
codec
=
::
VideoCodec_MPEG2
;
*
codec
=
::
VideoCodec_MPEG2
;
break
;
break
;
case
C
ODEC_ID_MPEG4
:
case
C
V_CODEC
(
CODEC_ID_MPEG4
)
:
*
codec
=
::
VideoCodec_MPEG4
;
*
codec
=
::
VideoCodec_MPEG4
;
break
;
break
;
case
C
ODEC_ID_VC1
:
case
C
V_CODEC
(
CODEC_ID_VC1
)
:
*
codec
=
::
VideoCodec_VC1
;
*
codec
=
::
VideoCodec_VC1
;
break
;
break
;
case
C
ODEC_ID_H264
:
case
C
V_CODEC
(
CODEC_ID_H264
)
:
*
codec
=
::
VideoCodec_H264
;
*
codec
=
::
VideoCodec_H264
;
break
;
break
;
...
...
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