diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index 5a9b10f..b321fd7 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -168,6 +168,14 @@ extern "C" { #endif #endif +#if LIBAVFORMAT_VERSION_MAJOR < 58 +# define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER +#endif + +#if LIBAVFORMAT_VERSION_MAJOR < 58 +# define AV_PKT_FLAG_KEY PKT_FLAG_KEY +#endif + #if USE_AV_INTERRUPT_CALLBACK #define LIBAVFORMAT_INTERRUPT_OPEN_TIMEOUT_MS 30000 #define LIBAVFORMAT_INTERRUPT_READ_TIMEOUT_MS 30000 @@ -1554,7 +1562,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc, // some formats want stream headers to be seperate if(oc->oformat->flags & AVFMT_GLOBALHEADER) { - c->flags |= CODEC_FLAG_GLOBAL_HEADER; + c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; } #endif @@ -1582,23 +1590,21 @@ static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, #endif int ret = OPENCV_NO_FRAMES_WRITTEN_CODE; +#if LIBAVFORMAT_VERSION_MAJOR < 58 if (oc->oformat->flags & AVFMT_RAWPICTURE) { /* raw video case. The API will change slightly in the near futur for that */ AVPacket pkt; av_init_packet(&pkt); -#ifndef PKT_FLAG_KEY -#define PKT_FLAG_KEY AV_PKT_FLAG_KEY -#endif - - pkt.flags |= PKT_FLAG_KEY; + pkt.flags |= AV_PKT_FLAG_KEY; pkt.stream_index= video_st->index; pkt.data= (uint8_t *)picture; pkt.size= sizeof(AVPicture); ret = av_write_frame(oc, &pkt); } else { +#endif /* encode the image */ AVPacket pkt; av_init_packet(&pkt); @@ -1633,7 +1639,7 @@ static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, pkt.pts = c->coded_frame->pts; #endif if(c->coded_frame->key_frame) - pkt.flags |= PKT_FLAG_KEY; + pkt.flags |= AV_PKT_FLAG_KEY; pkt.stream_index= video_st->index; pkt.data= outbuf; pkt.size= out_size; @@ -1642,7 +1648,9 @@ static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, ret = av_write_frame(oc, &pkt); } #endif +#if LIBAVFORMAT_VERSION_MAJOR < 58 } +#endif return ret; } @@ -1756,15 +1764,19 @@ void CvVideoWriter_FFMPEG::close() /* write the trailer, if any */ if(ok && oc) { +#if LIBAVFORMAT_VERSION_MAJOR < 58 if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 ) { +#endif for(;;) { int ret = icv_av_write_frame_FFMPEG( oc, video_st, outbuf, outbuf_size, NULL); if( ret == OPENCV_NO_FRAMES_WRITTEN_CODE || ret < 0 ) break; } +#if LIBAVFORMAT_VERSION_MAJOR < 58 } +#endif av_write_trailer(oc); } @@ -2055,12 +2067,16 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, outbuf = NULL; +#if LIBAVFORMAT_VERSION_MAJOR < 58 if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) { +#endif /* allocate output buffer */ /* assume we will never get codec output with more than 4 bytes per pixel... */ outbuf_size = width*height*4; outbuf = (uint8_t *) av_malloc(outbuf_size); +#if LIBAVFORMAT_VERSION_MAJOR < 58 } +#endif bool need_color_convert; need_color_convert = (c->pix_fmt != input_pix_fmt); @@ -2360,7 +2376,7 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CV_CODEC // some formats want stream headers to be seperate if (oc->oformat->flags & AVFMT_GLOBALHEADER) { - c->flags |= CODEC_FLAG_GLOBAL_HEADER; + c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; } #endif @@ -2461,7 +2477,7 @@ void OutputMediaStream_FFMPEG::write(unsigned char* data, int size, int keyFrame av_init_packet(&pkt); if (keyFrame) - pkt.flags |= PKT_FLAG_KEY; + pkt.flags |= AV_PKT_FLAG_KEY; pkt.stream_index = video_st_->index; pkt.data = data;