Skip to content

Introduce libavdevice to make v4l2 available to the ffmpeg backend#22706

Merged
alalek merged 6 commits intoopencv:4.xfrom
kallaballa:libavdevice_for_ffmpeg_v4l2
Nov 11, 2022
Merged

Introduce libavdevice to make v4l2 available to the ffmpeg backend#22706
alalek merged 6 commits intoopencv:4.xfrom
kallaballa:libavdevice_for_ffmpeg_v4l2

Conversation

@kallaballa
Copy link
Copy Markdown
Contributor

@kallaballa kallaballa commented Oct 27, 2022

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

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

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)
Copy link
Copy Markdown
Member

@alalek alalek Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! makes sense. I am on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just about the first step. Shouldn't i do it like that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then like that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i figured it out right: eb7bc8e

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for update!

Comment on lines +161 to +164
if(FFMPEG_libavdevice_FOUND)
add_definitions(-DHAVE_FFMPEG_LIBAVDEVICE)
endif()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +32 to +36
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()
Copy link
Copy Markdown
Member

@alalek alalek Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ON default value could be added separately for 5.x branch only.

Created a separate branch rebased to 5.x with default value 'ON'.
Gonna create a pull request once this is through.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good!

CMakeLists.txt Outdated
Comment on lines +278 to +279
OCV_OPTION(OPENCV_FFMPEG_ENABLE_LIBAVDEVICE "Include FFMPEG/libavdevice library support." OFF
VISIBLE_IF WITH_FFMPEG)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@alalek alalek merged commit da4ac6b into opencv:4.x Nov 11, 2022
@kallaballa
Copy link
Copy Markdown
Contributor Author

Great! Thx!

@alalek alalek mentioned this pull request Jan 8, 2023
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants