Skip to content

Commit

Permalink
AMD_Media - support for ffmpeg version 4 and above (#1460)
Browse files Browse the repository at this point in the history
Co-authored-by: Kiriti Gowda <kiritigowda@gmail.com>
  • Loading branch information
rrawther and kiritigowda authored Dec 9, 2024
1 parent bf14ade commit ed7a547
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 34 deletions.
9 changes: 5 additions & 4 deletions amd_openvx_extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ if(GPU_SUPPORT)
find_package(FFmpeg QUIET)
if(FFMPEG_FOUND)
# TBD: FFMPEG multi-version support
if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100)
add_subdirectory(amd_media)
message("-- ${Green}AMD OpenVX Media Extension -- amd_media module added${ColourReset}")
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()
message("-- ${Red}WARNING: FFMPEG Version Not Supported -- amd_media module excluded${ColourReset}")
set(FFMPEG_VERSION_4 FALSE)
endif()
add_subdirectory(amd_media)
message("-- ${Green}AMD OpenVX Media Extension -- amd_media module added${ColourReset}")
else()
message("-- ${Red}WARNING: FFMPEG Not Found -- amd_media module excluded${ColourReset}")
endif(FFMPEG_FOUND)
Expand Down
5 changes: 5 additions & 0 deletions amd_openvx_extensions/amd_media/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ elseif (GPU_SUPPORT AND "${BACKEND}" STREQUAL "HIP")
target_link_libraries(${PROJECT_NAME} hip::host)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
if (FFMPEG_VERSION_4)
target_compile_definitions(${PROJECT_NAME} PUBLIC WITH_FFMPEG_VERSION_4=1)
else()
target_compile_definitions(${PROJECT_NAME} PUBLIC WITH_FFMPEG_VERSION_4=0)
endif()

# install MIVisionX libs -- {ROCM_PATH}/lib
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_SKIP)
Expand Down
39 changes: 10 additions & 29 deletions amd_openvx_extensions/amd_media/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,14 @@ vx_status CLoomIoMediaDecoder::Initialize()
const char * mediaFileName = inputMediaFileName[mediaIndex].c_str();
AVFormatContext * formatContext = nullptr;
AVInputFormat * inputFormat = nullptr;
AVCodec *decoder = NULL;
AVStream *video = NULL;
#if WITH_FFMPEG_VERSION_4
AVCodec *decoder = nullptr;
#else
const AVCodec *decoder = nullptr;
#endif
AVStream *video = nullptr;
AVCodecContext * codecContext = nullptr;
AVBufferRef *hw_device_ctx = NULL;
AVBufferRef *hw_device_ctx = nullptr;
int videostream;

// find if hardware decode is available
Expand Down Expand Up @@ -497,32 +501,9 @@ vx_status CLoomIoMediaDecoder::Initialize()
}
videostream = err;

if (!useVaapi[mediaIndex]) {
unsigned int streamIndex = -1;
for (unsigned int si = 0; si < formatContext->nb_streams; si++) {
AVCodecContext * vcc = formatContext->streams[si]->codec;
if (vcc->codec_type == AVMEDIA_TYPE_VIDEO) {
// pick video stream index with larger dimensions
if (!codecContext) {
codecContext = vcc;
streamIndex = si;
}
else if ((vcc->width > codecContext->width) && (vcc->height > codecContext->height)) {
codecContext = vcc;
streamIndex = si;
}
}
}
if (!codecContext) {
vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_VALUE, "ERROR: no video found in %s", mediaFileName);
return VX_ERROR_INVALID_VALUE;
}
} else
{
if (!(codecContext = avcodec_alloc_context3(decoder))){
vxAddLogEntry((vx_reference)node, VX_ERROR_NO_MEMORY, "ERROR: can't alloc codec context\n");
return VX_ERROR_NO_MEMORY;
}
if (!(codecContext = avcodec_alloc_context3(decoder))){
vxAddLogEntry((vx_reference)node, VX_ERROR_NO_MEMORY, "ERROR: can't alloc codec context\n");
return VX_ERROR_NO_MEMORY;
}
videoCodecContext[mediaIndex] = codecContext;
videoStreamIndex[mediaIndex] = videostream;
Expand Down
2 changes: 1 addition & 1 deletion amd_openvx_extensions/amd_media/kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ vx_status initialize_ffmpeg()
initialized = true;
av_log_set_callback(av_log_callback);
av_log_set_level(AV_LOG_ERROR);
av_register_all();
//av_register_all(); // this is depracated from FFMpeg >4.0
}
return VX_SUCCESS;
}
Expand Down

0 comments on commit ed7a547

Please sign in to comment.