diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake index e1a6891f2..79db7304c 100644 --- a/cmake/FindFFmpeg.cmake +++ b/cmake/FindFFmpeg.cmake @@ -161,7 +161,13 @@ else() set(FFMPEG_FOUND FALSE) message( "-- ${Yellow}NOTE: FindFFmpeg failed to find -- FFMPEG${ColourReset}" ) endif() - + + if(_FFMPEG_AVCODEC_VERSION VERSION_LESS 59.18.100 OR _FFMPEG_AVFORMAT_VERSION VERSION_LESS 59.16.100 OR _FFMPEG_AVUTIL_VERSION VERSION_LESS 57.17.100) + set(FFMPEG_VERSION_4 TRUE) + else() + set(FFMPEG_VERSION_4 FALSE) + endif() + if(FFMPEG_FOUND) set(FFMPEG_INCLUDE_DIR ${AVFORMAT_INCLUDE_DIR} CACHE INTERNAL "") set(FFMPEG_LIBRARIES diff --git a/rocAL/CMakeLists.txt b/rocAL/CMakeLists.txt index f58c525ab..3ac08af24 100644 --- a/rocAL/CMakeLists.txt +++ b/rocAL/CMakeLists.txt @@ -302,6 +302,11 @@ if(${BUILD_ROCAL}) if(NOT FFMPEG_FOUND) message("-- ${Yellow}NOTE: rocAL built without FFmpeg Video Decode Functionality${ColourReset}") else() + if (FFMPEG_VERSION_4) + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_FFMPEG_VERSION_4=1) + else() + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_FFMPEG_VERSION_4=0) + endif() include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} ${SWSCALE_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR}) set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) message("-- ${White}rocAL built with FFmpeg Video Decode Functionality${ColourReset}") diff --git a/rocAL/include/decoders/image/hw_jpeg_decoder.h b/rocAL/include/decoders/image/hw_jpeg_decoder.h index 25acca4fb..869d91f6b 100644 --- a/rocAL/include/decoders/image/hw_jpeg_decoder.h +++ b/rocAL/include/decoders/image/hw_jpeg_decoder.h @@ -80,7 +80,11 @@ class HWJpegDecoder : public Decoder { AVIOContext *_io_ctx = NULL; AVFormatContext *_fmt_ctx = NULL; AVCodecContext *_video_dec_ctx = NULL; +#if USE_FFMPEG_VERSION_4 AVCodec *_decoder = NULL; +#else + const AVCodec *_decoder = NULL; +#endif AVStream *_video_stream = NULL; int _video_stream_idx = -1; AVPixelFormat _dec_pix_fmt; diff --git a/rocAL/include/decoders/video/ffmpeg_video_decoder.h b/rocAL/include/decoders/video/ffmpeg_video_decoder.h index e66ee9f7b..5be738ff8 100644 --- a/rocAL/include/decoders/video/ffmpeg_video_decoder.h +++ b/rocAL/include/decoders/video/ffmpeg_video_decoder.h @@ -39,7 +39,11 @@ class FFmpegVideoDecoder : public VideoDecoder { const char *_src_filename = NULL; AVFormatContext *_fmt_ctx = NULL; AVCodecContext *_video_dec_ctx = NULL; +#if USE_FFMPEG_VERSION_4 AVCodec *_decoder = NULL; +#else + const AVCodec *_decoder = NULL; +#endif AVStream *_video_stream = NULL; int _video_stream_idx = -1; AVPixelFormat _dec_pix_fmt; diff --git a/rocAL/include/decoders/video/hardware_video_decoder.h b/rocAL/include/decoders/video/hardware_video_decoder.h index dad64e02b..561d4186f 100644 --- a/rocAL/include/decoders/video/hardware_video_decoder.h +++ b/rocAL/include/decoders/video/hardware_video_decoder.h @@ -39,7 +39,11 @@ class HardWareVideoDecoder : public VideoDecoder { const char *_src_filename = NULL; AVFormatContext *_fmt_ctx = NULL; AVCodecContext *_video_dec_ctx = NULL; +#if USE_FFMPEG_VERSION_4 AVCodec *_decoder = NULL; +#else + const AVCodec *_decoder = NULL; +#endif AVStream *_video_stream = NULL; int _video_stream_idx = -1; AVPixelFormat _dec_pix_fmt; diff --git a/rocAL/source/decoders/image/hw_jpeg_decoder.cpp b/rocAL/source/decoders/image/hw_jpeg_decoder.cpp index d148f47e3..1ebd96933 100644 --- a/rocAL/source/decoders/image/hw_jpeg_decoder.cpp +++ b/rocAL/source/decoders/image/hw_jpeg_decoder.cpp @@ -70,7 +70,7 @@ static enum AVPixelFormat get_vaapi_format(AVCodecContext *ctx, const enum AVPix // ffmpeg helper functions for custom AVIOContex for bitstream reading static int ReadFunc(void *ptr, uint8_t *buf, int buf_size) { struct buffer_data *bd = (struct buffer_data *)ptr; - buf_size = FFMIN(buf_size, bd->size); + buf_size = FFMIN(buf_size, static_cast(bd->size)); if (!buf_size) return AVERROR_EOF; diff --git a/rocAL/source/readers/video/video_properties.cpp b/rocAL/source/readers/video/video_properties.cpp index 8bd27fd8b..af7e1eaae 100644 --- a/rocAL/source/readers/video/video_properties.cpp +++ b/rocAL/source/readers/video/video_properties.cpp @@ -40,7 +40,6 @@ void substring_extraction(std::string const &str, const char delim, std::vector< // Opens the context of the Video file to obtain the width, heigh and frame rate info. void open_video_context(const char *video_file_path, Properties &props) { AVFormatContext *pFormatCtx = NULL; - AVCodecContext *pCodecCtx = NULL; int videoStream = -1; unsigned int i = 0; @@ -55,21 +54,18 @@ void open_video_context(const char *video_file_path, Properties &props) { ret = avformat_find_stream_info(pFormatCtx, NULL); assert(ret >= 0); for (i = 0; i < pFormatCtx->nb_streams; i++) { - if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && videoStream < 0) { + if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && videoStream < 0) { videoStream = i; } } assert(videoStream != -1); // Get a pointer to the codec context for the video stream - pCodecCtx = pFormatCtx->streams[videoStream]->codec; - assert(pCodecCtx != NULL); - props.width = pCodecCtx->width; - props.height = pCodecCtx->height; + props.width = pFormatCtx->streams[videoStream]->codecpar->width; + props.height = pFormatCtx->streams[videoStream]->codecpar->height; props.frames_count = pFormatCtx->streams[videoStream]->nb_frames; props.avg_frame_rate_num = pFormatCtx->streams[videoStream]->avg_frame_rate.num; props.avg_frame_rate_den = pFormatCtx->streams[videoStream]->avg_frame_rate.den; - avcodec_close(pCodecCtx); avformat_close_input(&pFormatCtx); }