Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ set(FFMPEG_AVAILABLE OFF)
# FFMPEG_FOUND - system has ffmpeg or libav
# FFMPEG_INCLUDE_DIR - the ffmpeg include directory
# FFMPEG_LIBRARIES
# FFMPEG_LIBAVCODEC
# FFMPEG_LIBAVFORMAT
# FFMPEG_LIBAVUTIL
# FFMPEG_LIBAVCODEC_LIBRARIES
# FFMPEG_LIBAVFORMAT_LIBRARIES
# FFMPEG_LIBAVUTIL_LIBRARIES
if(FFMPEG_FOUND)
message("Found FFMPEG/LibAV libraries")
include_directories(${FFMPEG_INCLUDE_DIR})
Expand Down
243 changes: 69 additions & 174 deletions cmake/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
@@ -1,230 +1,125 @@
#
# Find the native FFMPEG includes and library
# This module defines
# FFMPEG_INCLUDE_DIR, where to find avcodec.h, avformat.h ...
# FFMPEG_LIBRARIES, the libraries to link against to use FFMPEG.
# FFMPEG_FOUND, If false, do not try to use FFMPEG.
# FFMPEG_ROOT, if this module use this path to find FFMPEG headers
# and libraries.

# Macro to find header and lib directories
# example: FFMPEG_FIND(AVFORMAT avformat avformat.h)
MACRO(FFMPEG_FIND varname shortname headername)
# old version of ffmpeg put header in $prefix/include/[ffmpeg]
# so try to find header in include directory
FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername}
PATHS
${FFMPEG_ROOT}/include/lib${shortname}
$ENV{FFMPEG_DIR}/include/lib${shortname}
~/Library/Frameworks/lib${shortname}
/Library/Frameworks/lib${shortname}
/usr/local/include/lib${shortname}
/usr/include/lib${shortname}
/sw/include/lib${shortname} # Fink
/opt/local/include/lib${shortname} # DarwinPorts
/opt/csw/include/lib${shortname} # Blastwave
/opt/include/lib${shortname}
/usr/freeware/include/lib${shortname}
PATH_SUFFIXES ffmpeg
DOC "Location of FFMPEG Headers"
)

FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername}
PATHS
${FFMPEG_ROOT}/include
$ENV{FFMPEG_DIR}/include
~/Library/Frameworks
/Library/Frameworks
/usr/local/include
/usr/include
/sw/include # Fink
/opt/local/include # DarwinPorts
/opt/csw/include # Blastwave
/opt/include
/usr/freeware/include
PATH_SUFFIXES ffmpeg
DOC "Location of FFMPEG Headers"
)

FIND_LIBRARY(FFMPEG_${varname}_LIBRARIES
NAMES ${shortname}
PATHS
${FFMPEG_ROOT}/lib
$ENV{FFMPEG_DIR}/lib
~/Library/Frameworks
/Library/Frameworks
/usr/local/lib
/usr/local/lib64
/usr/lib/x86_64-linux-gnu
/usr/lib
/usr/lib64
/sw/lib
/opt/local/lib
/opt/csw/lib
/opt/lib
/usr/freeware/lib64
DOC "Location of FFMPEG Libraries"
)

IF (FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)
SET(FFMPEG_${varname}_FOUND 1)
ENDIF(FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)

ENDMACRO(FFMPEG_FIND)

SET(FFMPEG_ROOT "$ENV{FFMPEG_DIR}" CACHE PATH "Location of FFMPEG")

# find stdint.h
IF(WIN32)

FIND_PATH(FFMPEG_STDINT_INCLUDE_DIR stdint.h
PATHS
${FFMPEG_ROOT}/include
$ENV{FFMPEG_DIR}/include
~/Library/Frameworks
/Library/Frameworks
/usr/local/include
/usr/include
/sw/include # Fink
/opt/local/include # DarwinPorts
/opt/csw/include # Blastwave
/opt/include
/usr/freeware/include
PATH_SUFFIXES ffmpeg
DOC "Location of FFMPEG stdint.h Header"
)

IF (FFMPEG_STDINT_INCLUDE_DIR)
SET(STDINT_OK TRUE)
ENDIF()

ELSE()

SET(STDINT_OK TRUE)

ENDIF()

FFMPEG_FIND(LIBAVFORMAT avformat avformat.h)
FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h)
FFMPEG_FIND(LIBAVCODEC avcodec avcodec.h)
FFMPEG_FIND(LIBAVUTIL avutil avutil.h)
FFMPEG_FIND(LIBSWSCALE swscale swscale.h) # not sure about the header to look for here.
FFMPEG_FIND(LIBX264 x264 x264.h)
FFMPEG_FIND(LIBX265 x265 x265.h)

SET(FFMPEG_FOUND "NO")

# Note we don't check FFMPEG_LIBSWSCALE_FOUND, FFMPEG_LIBAVDEVICE_FOUND,
# and FFMPEG_LIBAVUTIL_FOUND as they are optional.
IF (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND STDINT_OK)

SET(FFMPEG_FOUND "YES")

SET(FFMPEG_INCLUDE_DIR ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS})

SET(FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBAVFORMAT_LIBRARY_DIRS})
# Find the native FFmpeg includes and libraries.
#
# This module defines:
# FFMPEG_FOUND - True if FFmpeg was found
# FFMPEG_INCLUDE_DIR - FFmpeg include directory
# FFMPEG_INCLUDE_DIRS - Same as above (alias)
# FFMPEG_LIBRARIES - All FFmpeg libraries
# FFMPEG_LIBAVCODEC_LIBRARIES - avcodec library
# FFMPEG_LIBAVFORMAT_LIBRARIES - avformat library
# FFMPEG_LIBAVUTIL_LIBRARIES - avutil library
# FFMPEG_LIBSWSCALE_LIBRARIES - swscale library (optional)
#
# Accepts:
# FFMPEG_ROOT or ENV{FFMPEG_DIR} or ENV{FFMPEG_ROOT} - Custom search path
#

# Note we don't add FFMPEG_LIBSWSCALE_LIBRARIES here,
# it will be added if found later.
SET(FFMPEG_LIBRARIES
${FFMPEG_LIBAVFORMAT_LIBRARIES}
${FFMPEG_LIBAVDEVICE_LIBRARIES}
${FFMPEG_LIBAVCODEC_LIBRARIES}
${FFMPEG_LIBAVUTIL_LIBRARIES}
${FFMPEG_LIBSWSCALE_LIBRARIES}
${FFMPEG_LIBX264_LIBRARIES}
${FFMPEG_LIBX265_LIBRARIES})
ENDIF()
set(FFMPEG_ROOT "$ENV{FFMPEG_DIR}" CACHE PATH "Location of FFmpeg")

# Find FFmpeg components
# Try pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(FFMPEG QUIET
pkg_check_modules(PC_FFMPEG QUIET
libavcodec
libavformat
libavutil
libswscale
)
endif()

# Find individual components
# Find include directory
find_path(FFMPEG_INCLUDE_DIR
NAMES libavcodec/avcodec.h libavformat/avformat.h libavutil/avutil.h libswscale/swscale.h
NAMES libavcodec/avcodec.h libavformat/avformat.h libavutil/avutil.h
PATHS
${FFMPEG_INCLUDE_DIRS}
${FFMPEG_ROOT}/include
$ENV{FFMPEG_ROOT}/include
${PC_FFMPEG_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{FFMPEG_ROOT}/include
PATH_SUFFIXES ffmpeg
)

# Find libraries
find_library(AVCODEC_LIBRARY
# Find required libraries
find_library(FFMPEG_LIBAVCODEC_LIBRARIES
NAMES avcodec
PATHS
${FFMPEG_LIBRARY_DIRS}
${FFMPEG_ROOT}/lib
$ENV{FFMPEG_ROOT}/lib
${PC_FFMPEG_LIBRARY_DIRS}
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib64
/usr/local/lib
$ENV{FFMPEG_ROOT}/lib
/usr/local/lib64
)

find_library(AVFORMAT_LIBRARY
find_library(FFMPEG_LIBAVFORMAT_LIBRARIES
NAMES avformat
PATHS
${FFMPEG_LIBRARY_DIRS}
${FFMPEG_ROOT}/lib
$ENV{FFMPEG_ROOT}/lib
${PC_FFMPEG_LIBRARY_DIRS}
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib64
/usr/local/lib
$ENV{FFMPEG_ROOT}/lib
/usr/local/lib64
)

find_library(AVUTIL_LIBRARY
find_library(FFMPEG_LIBAVUTIL_LIBRARIES
NAMES avutil
PATHS
${FFMPEG_LIBRARY_DIRS}
${FFMPEG_ROOT}/lib
$ENV{FFMPEG_ROOT}/lib
${PC_FFMPEG_LIBRARY_DIRS}
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib64
/usr/local/lib
$ENV{FFMPEG_ROOT}/lib
/usr/local/lib64
)

find_library(SWSCALE_LIBRARY
# Find optional libraries
find_library(FFMPEG_LIBSWSCALE_LIBRARIES
NAMES swscale
PATHS
${FFMPEG_LIBRARY_DIRS}
${FFMPEG_ROOT}/lib
$ENV{FFMPEG_ROOT}/lib
${PC_FFMPEG_LIBRARY_DIRS}
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib64
/usr/local/lib
$ENV{FFMPEG_ROOT}/lib
)

# Set FFmpeg libraries
set(FFMPEG_LIBRARIES
${AVCODEC_LIBRARY}
${AVFORMAT_LIBRARY}
${AVUTIL_LIBRARY}
${SWSCALE_LIBRARY}
/usr/local/lib64
)

# Handle the QUIETLY and REQUIRED arguments
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFmpeg
REQUIRED_VARS
FFMPEG_INCLUDE_DIR
AVCODEC_LIBRARY
AVFORMAT_LIBRARY
AVUTIL_LIBRARY
SWSCALE_LIBRARY
FFMPEG_LIBAVCODEC_LIBRARIES
FFMPEG_LIBAVFORMAT_LIBRARIES
FFMPEG_LIBAVUTIL_LIBRARIES
)

# Mark as advanced
mark_as_advanced(
FFMPEG_INCLUDE_DIR
AVCODEC_LIBRARY
AVFORMAT_LIBRARY
AVUTIL_LIBRARY
SWSCALE_LIBRARY
FFMPEG_LIBAVCODEC_LIBRARIES
FFMPEG_LIBAVFORMAT_LIBRARIES
FFMPEG_LIBAVUTIL_LIBRARIES
FFMPEG_LIBSWSCALE_LIBRARIES
)

# Set variables for use in the project
if(FFMPEG_FOUND)
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR})
set(FFMPEG_DEFINITIONS ${FFMPEG_CFLAGS_OTHER})
endif()
set(FFMPEG_LIBRARIES
${FFMPEG_LIBAVCODEC_LIBRARIES}
${FFMPEG_LIBAVFORMAT_LIBRARIES}
${FFMPEG_LIBAVUTIL_LIBRARIES}
)
if(FFMPEG_LIBSWSCALE_LIBRARIES)
list(APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBSWSCALE_LIBRARIES})
endif()
endif() # FFMPEG_FOUND
3 changes: 3 additions & 0 deletions vk_video_decoder/demos/vk-video-dec/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ int main(int argc, const char **argv)
if (result != VK_SUCCESS) {
fprintf(stderr, "Error: Failed to initialize VideoStreamDemuxer for file: %s\n",
decoderConfig.videoFileName.c_str());
#ifndef FFMPEG_DEMUXER_SUPPORT
fprintf(stderr, "Note: This build does not include FFmpeg demuxer support.\n");
#endif
return EXIT_FAILURE;
}

Expand Down
18 changes: 14 additions & 4 deletions vk_video_decoder/libs/VkDecoderUtils/VideoStreamDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,20 @@ VkResult VideoStreamDemuxer::Create(const char *pFilePath,
} else
#endif // FFMPEG_DEMUXER_SUPPORT
{
assert(codecType != VK_VIDEO_CODEC_OPERATION_NONE_KHR);
assert(defaultWidth > 0);
assert(defaultHeight > 0);
assert((defaultBitDepth == 8) || (defaultBitDepth == 10) || (defaultBitDepth == 12));
if (codecType == VK_VIDEO_CODEC_OPERATION_NONE_KHR) {
fprintf(stderr, "Error: No video codec specified for %s.\n", pFilePath);
return VK_ERROR_FORMAT_NOT_SUPPORTED;
}
if (defaultWidth <= 0 || defaultHeight <= 0) {
fprintf(stderr, "Error: Invalid video dimensions %dx%d for %s.\n",
defaultWidth, defaultHeight, pFilePath);
return VK_ERROR_FORMAT_NOT_SUPPORTED;
}
if (defaultBitDepth != 8 && defaultBitDepth != 10 && defaultBitDepth != 12) {
fprintf(stderr, "Error: Unsupported bit depth %d for %s. Must be 8, 10, or 12.\n",
defaultBitDepth, pFilePath);
return VK_ERROR_FORMAT_NOT_SUPPORTED;
}
return ElementaryStreamCreate(pFilePath,
codecType,
defaultWidth,
Expand Down
3 changes: 3 additions & 0 deletions vk_video_decoder/test/vulkan-video-simple-dec/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ int main(int argc, const char** argv)
if (result != VK_SUCCESS) {
fprintf(stderr, "Error: Failed to initialize VideoStreamDemuxer for file: %s\n",
decoderConfig.videoFileName.c_str());
#ifndef FFMPEG_DEMUXER_SUPPORT
fprintf(stderr, "Note: This build does not include FFmpeg demuxer support.\n");
#endif
return EXIT_FAILURE;
}

Expand Down
Loading