Introduce libavdevice to make v4l2 available to the ffmpeg backend#22706
Introduce libavdevice to make v4l2 available to the ffmpeg backend#22706alalek merged 6 commits intoopencv:4.xfrom
Conversation
| set(_used_ffmpeg_libraries ${_required_ffmpeg_libraries}) | ||
| if(NOT HAVE_FFMPEG AND PKG_CONFIG_FOUND) | ||
| ocv_check_modules(FFMPEG libavcodec libavformat libavutil libswscale) | ||
| ocv_check_modules(FFMPEG libavcodec libavformat libavutil libswscale libavdevice) |
There was a problem hiding this comment.
Need to check if libavdevice module is optional or not in FFmpeg and libav packages.
If it is optional, then it should be added as optional into OpenCV (to avoid breaking of existed user configurations)
Update:
Looks like some configurations may miss libavdevice:
E.g., Ubuntu 20.04:
# ll /usr/lib/x86_64-linux-gnu/pkgconfig/{libav*,libswscale*}
-rw-r--r-- 1 root root 742 May 18 21:24 /usr/lib/x86_64-linux-gnu/pkgconfig/libavcodec.pc
-rw-r--r-- 1 root root 472 May 18 21:24 /usr/lib/x86_64-linux-gnu/pkgconfig/libavformat.pc
-rw-r--r-- 1 root root 386 May 18 21:24 /usr/lib/x86_64-linux-gnu/pkgconfig/libavutil.pc
-rw-r--r-- 1 root root 322 May 18 21:24 /usr/lib/x86_64-linux-gnu/pkgconfig/libswscale.pc
Installed through apt-get install libavcodec-dev libavformat-dev libswscale-dev (current configuration on CI)
Optional dependency means these steps:
- CMake cache variable to control behavior -
OPENCV_FFMPEG_ENABLE_LIBAVDEVICE - default value is OFF (to avoid breaking of user code)
- add compiler macro to pass into C++ code if libavdevice enabled and should be used (e.g.,
OPENCV_FFMPEG_LIBAVDEVICE=1) - related C++ code should be guarded by
#ifdef OPENCV_FFMPEG_LIBAVDEVICE
There was a problem hiding this comment.
Thanks! makes sense. I am on it.
There was a problem hiding this comment.
Just about the first step. Shouldn't i do it like that?
modules/videoio/CMakeLists.txt
Outdated
| if(FFMPEG_libavdevice_FOUND) | ||
| add_definitions(-DHAVE_FFMPEG_LIBAVDEVICE) | ||
| endif() | ||
|
|
There was a problem hiding this comment.
add_definitions
Definition should go through target. Need to patch this line instead:
ocv_add_external_target(ffmpeg "${FFMPEG_INCLUDE_DIRS}" "${FFMPEG_LIBRARIES}" "HAVE_FFMPEG")
| ocv_check_modules(FFMPEG_libavdevice libavdevice) # optional | ||
| if(FFMPEG_libavdevice_FOUND) | ||
| list(APPEND FFMPEG_LIBRARIES ${FFMPEG_libavdevice_LIBRARIES}) | ||
| list(APPEND _used_ffmpeg_libraries libavdevice) | ||
| endif() |
There was a problem hiding this comment.
Broken indentation.
Please add OPENCV_FFMPEG_ENABLE_LIBAVDEVICE pre-check to keep it configurable.
Keep value is OFF by default to preserve compatibility in current 4.x branch.
ON default value could be added separately for 5.x branch only.
There was a problem hiding this comment.
ONdefault value could be added separately for5.xbranch only.
Created a separate branch rebased to 5.x with default value 'ON'.
Gonna create a pull request once this is through.
There was a problem hiding this comment.
After merge to "4.x" these changes would be propagated to "5.x" branch in 1-3 weeks: https://github.com/opencv/opencv/wiki/Branches
Patch would be simple after that.
… through ocv_add_external_target
CMakeLists.txt
Outdated
| OCV_OPTION(OPENCV_FFMPEG_ENABLE_LIBAVDEVICE "Include FFMPEG/libavdevice library support." OFF | ||
| VISIBLE_IF WITH_FFMPEG) |
There was a problem hiding this comment.
Lets move it to the top of modules/videoio/cmake/detect_ffmpeg.cmake
This list is for high level configuration, "fine" tuning should go separately.
|
Great! Thx! |
…g_v4l2 Introduce libavdevice to make v4l2 available to the ffmpeg backend * introduce libavdevice to make v4l2 available to the ffmpeg backend * downgrade the min required libavdevice version to 53.2.0 * make libavdevice optional * create OCV_OPTION OPENCV_FFMPEG_ENABLE_LIBAVDEVICE and add definition through ocv_add_external_target * move OCV_OPTION 'OPENCV_FFMPEG_ENABLE_LIBAVDEVICE' to detect_ffmpeg.cmake
The pertaining issue: #22705
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.