Skip to content

Commit b1d2088

Browse files
jvineyalalek
authored andcommitted
Merge pull request opencv#10011 from jviney:master
Fix build with FFmpeg master. Some deprecated APIs have been removed. (opencv#10011) * Fix build with FFmpeg master. * ffmpeg: update AVFMT_RAWPICTURE support removal
1 parent 017a38a commit b1d2088

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

modules/videoio/src/cap_ffmpeg_impl.hpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ extern "C" {
149149
#define AV_PIX_FMT_GRAY16BE PIX_FMT_GRAY16BE
150150
#endif
151151

152+
#ifndef PKT_FLAG_KEY
153+
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
154+
#endif
155+
152156
#if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 \
153157
? CALC_FFMPEG_VERSION(52, 38, 100) : CALC_FFMPEG_VERSION(52, 13, 0))
154158
#define USE_AV_FRAME_GET_BUFFER 1
@@ -1570,7 +1574,11 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
15701574
// some formats want stream headers to be seperate
15711575
if(oc->oformat->flags & AVFMT_GLOBALHEADER)
15721576
{
1577+
#if LIBAVCODEC_BUILD > CALC_FFMPEG_VERSION(56, 35, 0)
1578+
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1579+
#else
15731580
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
1581+
#endif
15741582
}
15751583
#endif
15761584

@@ -1598,23 +1606,24 @@ static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st,
15981606
#endif
15991607
int ret = OPENCV_NO_FRAMES_WRITTEN_CODE;
16001608

1601-
if (oc->oformat->flags & AVFMT_RAWPICTURE) {
1609+
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(57, 0, 0)
1610+
if (oc->oformat->flags & AVFMT_RAWPICTURE)
1611+
{
16021612
/* raw video case. The API will change slightly in the near
16031613
futur for that */
16041614
AVPacket pkt;
16051615
av_init_packet(&pkt);
16061616

1607-
#ifndef PKT_FLAG_KEY
1608-
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
1609-
#endif
1610-
16111617
pkt.flags |= PKT_FLAG_KEY;
16121618
pkt.stream_index= video_st->index;
16131619
pkt.data= (uint8_t *)picture;
16141620
pkt.size= sizeof(AVPicture);
16151621

16161622
ret = av_write_frame(oc, &pkt);
1617-
} else {
1623+
}
1624+
else
1625+
#endif
1626+
{
16181627
/* encode the image */
16191628
AVPacket pkt;
16201629
av_init_packet(&pkt);
@@ -1772,7 +1781,9 @@ void CvVideoWriter_FFMPEG::close()
17721781
/* write the trailer, if any */
17731782
if(ok && oc)
17741783
{
1775-
if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 )
1784+
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(57, 0, 0)
1785+
if (!(oc->oformat->flags & AVFMT_RAWPICTURE))
1786+
#endif
17761787
{
17771788
for(;;)
17781789
{
@@ -2071,7 +2082,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
20712082

20722083
outbuf = NULL;
20732084

2074-
if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
2085+
2086+
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(57, 0, 0)
2087+
if (!(oc->oformat->flags & AVFMT_RAWPICTURE))
2088+
#endif
2089+
{
20752090
/* allocate output buffer */
20762091
/* assume we will never get codec output with more than 4 bytes per pixel... */
20772092
outbuf_size = width*height*4;
@@ -2376,7 +2391,11 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CV_CODEC
23762391
// some formats want stream headers to be seperate
23772392
if (oc->oformat->flags & AVFMT_GLOBALHEADER)
23782393
{
2379-
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
2394+
#if LIBAVCODEC_BUILD > CALC_FFMPEG_VERSION(56, 35, 0)
2395+
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
2396+
#else
2397+
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
2398+
#endif
23802399
}
23812400
#endif
23822401

0 commit comments

Comments
 (0)