Skip to content

Commit

Permalink
FFmpeg - Fix errors wrt latest FFmpeg versions (#239)
Browse files Browse the repository at this point in the history
* Fix errors wrt latest FFmpeg version

* Introduce CMake flag to check FFmpeg version less than 4

* Minor warning fix

---------

Co-authored-by: Kiriti Gowda <[email protected]>
  • Loading branch information
fiona-gladwin and kiritigowda authored Dec 6, 2024
1 parent 2d092dd commit a077058
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
8 changes: 7 additions & 1 deletion cmake/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions rocAL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
4 changes: 4 additions & 0 deletions rocAL/include/decoders/image/hw_jpeg_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions rocAL/include/decoders/video/ffmpeg_video_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions rocAL/include/decoders/video/hardware_video_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rocAL/source/decoders/image/hw_jpeg_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(bd->size));

if (!buf_size)
return AVERROR_EOF;
Expand Down
10 changes: 3 additions & 7 deletions rocAL/source/readers/video/video_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down

0 comments on commit a077058

Please sign in to comment.