VideoCapture not work in linux

Phenomenon: No problem running on Mac environment, but an error occurs when running on Linux environment, unable to open video files;
Effort: Need to recompile OpenCV;
Issue: Unable to enable ffmpeg switch.

It has been bothering me for a long time, thank you very much for your help.


– Video I/O:
– DC1394: NO
– avcodec: NO
– avformat: NO
– avutil: NO
– swscale: NO
– avresample: NO
– AVFoundation: YES

(base) liupeng@okerdeMacBook-Pro build % cmake -DWITH_GSTREAMER=OFF \                                                         -DBUILD_opencv_highgui=OFF \
-DBUILD_opencv_dnn=OFF \
-DBUILD_opencv_ml=OFF \
-DBUILD_opencv_apps=OFF \
-DBUILD_opencv_js=OFF \
-DBUILD_opencv_ts=OFF \
-DBUILD_opencv_viz=OFF \
-DBUILD_opencv_lagacy=OFF \
-DBUILD_opencv_androidcamera=OFF \
-DBUILD_opencv_python2=OFF  \
-DBUILD_opencv_python3=OFF ../../opencv
-- Detected processor: x86_64
-- Looking for ccache - not found
-- AVX512_KNM is not supported by C++ compiler
-- libjpeg-turbo: VERSION = 2.1.3, BUILD = opencv-4.9.0-dev-libjpeg-turbo
-- libjpeg-turbo(SIMD): SIMD extensions disabled: could not find NASM compiler.  Performance will suffer.
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.9.0-dev-openjp2-2.5.0
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
-- IPPICV: Downloading ippicv_2021.9.1_mac_intel64_20230919_general.tgz from
-- Try 1 failed
CMake Warning at cmake/OpenCVDownload.cmake:248 (message):
  IPPICV: Download failed: 22;"HTTP response code said error"

  For details please refer to the download log file:


Call Stack (most recent call first):
  3rdparty/ippicv/ippicv.cmake:37 (ocv_download)
  cmake/OpenCVFindIPP.cmake:259 (download_ippicv)
  cmake/OpenCVFindLibsPerf.cmake:12 (include)
  CMakeLists.txt:820 (include)

-- LAPACK(LAPACK/Apple): LAPACK_LIBRARIES: /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/System/Library/Frameworks/Accelerate.framework;-lm;-ldl
-- LAPACK(LAPACK/Apple): Support is enabled.
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Allocator metrics storage type: 'long long'
-- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
-- Found 'misc' Python modules from /Users/liupeng/Downloads/opencv/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /Users/liupeng/Downloads/opencv/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from /Users/liupeng/Downloads/opencv/opencv/modules/gapi/misc/python/package
-- General configuration for OpenCV 4.9.0-dev =====================================
--   Version control:               4.9.0-300-geba158fb0c
--   Platform:
--     Timestamp:                   2024-03-31T19:30:18Z
--     Host:                        Darwin 22.2.0 x86_64
--     CMake:                       3.29.0
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1
--       requested:                 DETECT
--     Dispatched code generation:  SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_2 (1 files):          + POPCNT SSE4_2
--       FP16 (0 files):            + POPCNT SSE4_2 FP16 AVX
--       AVX (3 files):             + POPCNT SSE4_2 AVX
--       AVX2 (30 files):           + POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (3 files):      + POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--   C/C++:
--     Built as dynamic libs?:      NO
--     C++ standard:                11
--     C++ Compiler:                /Library/Developer/CommandLineTools/usr/bin/c++  (ver
--     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /Library/Developer/CommandLineTools/usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,-dead_strip
--     Linker flags (Debug):        -Wl,-dead_strip
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          -framework OpenCL /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl OpenEXR::OpenEXR -framework AppKit
--     3rdparty dependencies:       ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 zlib
--   OpenCV modules:
--     To be built:                 calib3d core features2d flann gapi imgcodecs imgproc objdetect photo stitching video videoio
--     Disabled:                    dnn highgui ml world
--     Disabled by dependency:      -
--     Unavailable:                 java python2 python3 ts
--     Applications:                -
--     Documentation:               NO
--     Non-free algorithms:         NO
--   GUI:
--     Cocoa:                       YES
--     VTK support:                 NO
--   Media I/O:
--     ZLib:                        build (ver 1.3.1)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.3-62)
--       SIMD Support Request:      YES
--       SIMD Support:              NO
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.6.0)
--     JPEG 2000:                   build (ver 2.5.0)
--     OpenEXR:                     OpenEXR::OpenEXR (ver 3.2.4)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     AVFoundation:                YES
--   Parallel framework:            GCD
--   Trace:                         YES (with Intel ITT)
--   Other third-party libraries:
--     Lapack:                      YES (/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl)
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--     Flatbuffers:                 builtin/3rdparty (23.5.9)
--   OpenCL:                        YES (no extra features)
--     Include path:                NO
--     Link libraries:              -framework OpenCL
--   Python (for build):            /Users/liupeng/anaconda3/bin/python3
--   Java:
--     ant:                         NO
--     Java:                        YES (ver 21.0.2)
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
-- Configuring done (9.7s)
-- Generating done (0.7s)
-- Build files have been written to: /Users/liupeng/Downloads/opencv/opencv/build

the cmake output is from apple, not linux, please edit.

Thank you for your correction, it has been modified.

There is no edit button and I can’t update the original text

I bumped your user level. try it now.

Still no edit button

Still no edit button

remember, you need to install dev versions (e.g. includes) for the ffmpeg libs, having so’s around is not enough

Thanks your help;

I copied the required .h files to the /usr/incloude directory. When recompiling opencv, I still couldn’t find the dependent packages.

cmake build-essential g++ openjdk-17-jdk wget unzip ant python3 python3-numpy libtbb-dev libeigen3-dev libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libswresample-dev liblzma-dev ffmpeg libpulse0 ../../opencv

-- Checking for modules 'libavcodec;libavformat;libavutil;libswscale'
--   No package 'libavcodec' found
--   No package 'libavformat' found
--   No package 'libavutil' found
--   No package 'libswscale' found
-- FFMPEG is disabled. Required libraries: libavcodec;libavformat;libavutil;libswscale. Missing libraries: libavcodec;libavformat;libavutil;libswscale```

ffmpeg has also been compiled from source code.

GCC 4.8.5

I would strongly recommend updating everything.

this is not due to your operating system.

Darwin 22.2.0
December 13, 2022
macOS 13.1, iOS 16.2, iPadOS 16.2, watchOS 9.2 and tvOS 16.2