Skip to content

(4.x) reduce binaries size of FFmpeg Windows wrapper#19606

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
alalek:reduce_ffmpeg_wrapper_size_4.x
Mar 2, 2021
Merged

(4.x) reduce binaries size of FFmpeg Windows wrapper#19606
opencv-pushbot merged 1 commit intoopencv:masterfrom
alalek:reduce_ffmpeg_wrapper_size_4.x

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Feb 23, 2021

  • core: rework code locality to reduce binaries size of FFmpeg Windows wrapper
  • MinGW linker doesn't support -ffunction-sections (used for FFmpeg Windows wrapper)
  • move code to improve locality with its dependencies
  • move UMat::dot() to matmul.dispatch.cpp (Mat::dot() is already there)
  • move UMat::inv() to lapack.cpp
  • move UMat::mul() to arithm.cpp
  • move UMat:eye() to matrix_operations.cpp (near setIdentity() implementation)
  • move normalize(): convert_scale.cpp => norm.cpp
  • move convertAndUnrollScalar(): arithm.cpp => copy.cpp
  • move scalarToRawData(): array.cpp => copy.cpp
  • move transpose(): matrix_operations.cpp => matrix_transform.cpp
  • move flip(), rotate(): copy.cpp => matrix_transform.cpp (rotate90 uses flip and transpose)
  • add 'OPENCV_CORE_EXCLUDE_C_API' CMake variable to exclude compilation of C-API functions from the core module
  • matrix_wrap.cpp: add compile-time checks for CUDA/OpenGL calls
  • the steps above allow to reduce FFmpeg wrapper size for ~1.5Mb (initial size of OpenCV part is about 3Mb)

FFmpeg wrapper side without and with this patch:

-rwxr-xr-x 1 alalek alalek 22553088 Mar  2 13:20 ffmpeg/opencv_videoio_ffmpeg_64.dll
-rwxrwxr-x 1 alalek alalek 20913152 Mar  2 13:12 ffmpeg/opencv_videoio_ffmpeg_64.dll

-rwxr-xr-x 1 alalek alalek 21721088 Mar  2 13:21 ffmpeg/opencv_videoio_ffmpeg.dll
-rwxrwxr-x 1 alalek alalek 19918336 Mar  2 13:12 ffmpeg/opencv_videoio_ffmpeg.dll

Reduced used opencv files from 51 to 16:

$ strings ./opencv_videoio_ffmpeg_64.dll | grep '/src/' | grep opencv | uniq | wc -l
Details
/build/opencv/modules/videoio/src/cap_ffmpeg.cpp
/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp
/build/opencv/modules/videoio/src/cap_ffmpeg_hw.hpp
/build/opencv/modules/videoio/src/cap_interface.hpp
/build/opencv/modules/core/src/copy.cpp
/build/opencv/modules/core/src/matrix.cpp
/build/opencv/modules/core/src/matrix_iterator.cpp
/build/opencv/modules/core/src/matrix_transform.cpp
/build/opencv/modules/core/src/matrix_wrap.cpp
/build/opencv/modules/core/src/system.cpp
/build/opencv/modules/core/src/umatrix.cpp
/build/opencv/modules/core/src/utils/logtagmanager.cpp
/build/opencv/modules/core/src/alloc.cpp
/build/opencv/modules/core/src/convert.dispatch.cpp
/build/opencv/modules/core/src/convert.simd.hpp
/build/opencv/modules/core/src/convert_scale.dispatch.cpp

@alalek alalek mentioned this pull request Feb 23, 2021
@asmorkalov asmorkalov mentioned this pull request Feb 26, 2021
6 tasks
@alalek
Copy link
Copy Markdown
Member Author

alalek commented Feb 26, 2021

@vpisarev @asmorkalov @mshabunin Please add feedback which changes are excessive and should be reverted (see the list in PR's description).

Does it makes sense to move transpose() / flip() / rotate() to new "matrix_transform.cpp" file? (from copy.cpp / matrix_operations.cpp)

@mshabunin
Copy link
Copy Markdown
Contributor

I think the changes are fine. I'd move any function larger than 300-500 lines (CPU+OCL) to separate file, 1k-line files are not particularly convenient.
Also, I believe the size reduction can be further improved by introducing OPENCV_CORE_EXCLUDE_EXPRESSIONS switch, but it would require more intrusive changes.

- to reduce binaries size of FFmpeg Windows wrapper
- MinGW linker doesn't support -ffunction-sections (used for FFmpeg Windows wrapper)
- move code to improve locality with its used dependencies
- move UMat::dot() to matmul.dispatch.cpp (Mat::dot() is already there)
- move UMat::inv() to lapack.cpp
- move UMat::mul() to arithm.cpp
- move UMat:eye() to matrix_operations.cpp (near setIdentity() implementation)
- move normalize(): convert_scale.cpp => norm.cpp
- move convertAndUnrollScalar(): arithm.cpp => copy.cpp
- move scalarToRawData(): array.cpp => copy.cpp
- move transpose(): matrix_operations.cpp => matrix_transform.cpp
- move flip(), rotate(): copy.cpp => matrix_transform.cpp (rotate90 uses flip and transpose)
- add 'OPENCV_CORE_EXCLUDE_C_API' CMake variable to exclude compilation of C-API functions from the core module
- matrix_wrap.cpp: add compile-time checks for CUDA/OpenGL calls
- the steps above allow to reduce FFmpeg wrapper size for ~1.5Mb (initial size of OpenCV part is about 3Mb)
@alalek
Copy link
Copy Markdown
Member Author

alalek commented Mar 2, 2021

it makes sense to move transpose() / flip() / rotate() to new "matrix_transform.cpp" file

Done


@vpisarev @asmorkalov ping ^^^

@asmorkalov asmorkalov self-requested a review March 2, 2021 15:59
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@opencv-pushbot opencv-pushbot merged commit cbb0151 into opencv:master Mar 2, 2021
@alalek alalek mentioned this pull request Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: build/install category: core port/backport done Label for maintainers. Authors of PR can ignore this RFC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants