Repository: opencv
Issue: Compiling to WebAssembly doesn't build libopencv_videoio.a
Labels: feature,category: video,category: javascript (js)

##### System information (version)

- OpenCV => 4.5.1
- Operating System / Platform => Ubuntu 18.04.5 LTS
- Compiler => em++

##### Detailed description

My goal is to include OpenCV in an executable (opencv_video.cc) that I want to compile with emcc to WebAssembly. My first step is to build OpenCV by running [build_js.py](https://github.com/opencv/opencv/blob/4.5.1/platforms/js/build_js.py). The problem is that the `libopencv_videoio.a` library is not built (which I suppose is needed to read video files) and afterwards the emscripten linker complains that the definition of VideoCapture::read() can't be found (which makes sense because it is defined in libopencv_videoio.a):

```
Scanning dependencies of target opencv_video
[ 50%] Building CXX object CMakeFiles/opencv_video.dir/opencv_video.cc.o
[100%] Linking CXX executable opencv_video.js
error: undefined symbol: _ZN2cv12VideoCapture4readERKNS_12_OutputArrayE (referenced by top-level compiled C/C++ code)
```

I saw [here](https://github.com/opencv/opencv/blob/4.5.1/platforms/js/build_js.py#L128) that the `BUILD_opencv_videoio` argument is turned off and I wonder why? Nevertheless, setting it ON doesn't change the outcome.

##### Steps to reproduce

###### Step 1: Build OpenCV 
Switch to opencv/platforms/js, create a build directory and run
`emcmake python build_js.py build`

###### Step 2: Create a file opencv_video.cc with the following sample source code

```cpp
#include <iostream>
#include <stdexcept>
#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"

int main() {
  cv::VideoCapture cap("/home/sample.mp4");
  if (!cap.isOpened()) {
    std::cerr << "Failed to open video file" << std::endl;
    throw std::invalid_argument(
        "Error loading the video file: Did you specify the correct video "
        "path?");
  }

  cv::Mat frame;
  int frameCount = 0;
  for (;;) {
    if (!cap.read(frame)) break;
    frameCount++;
  }
  std::cout << "Frame count: " << frameCount << std::endl;
  return 0;
}
```

###### Step 3: Create a CMakeLists.txt file with the following content

```cmake
cmake_minimum_required(VERSION 3.17)
PROJECT (opencvtest)

set(EMCC_LINKER_FLAGS "-s WASM=1 --preload-file /home/sample.mp4")

include_directories(opencv/include)
include_directories(opencv/platforms/js/build)

file(GLOB opencv_include_modules "opencv/modules/*/include")
include_directories(${opencv_include_modules})

add_executable(opencv_video opencv_video.cc)
file(GLOB opencv_js "opencv/platforms/js/build/lib/*.a")
target_link_libraries(opencv_video ${opencv_js})
```

###### Step 4: Create a new build folder, cd and run
```
emcmake cmake ..
emmake make
```

Result:
```
user:~/build$ emmake make
make: make
Scanning dependencies of target opencv_video
[ 50%] Building CXX object CMakeFiles/opencv_video.dir/opencv_video.cc.o
[100%] Linking CXX executable opencv_video.js
error: undefined symbol: _ZN2cv12VideoCapture4readERKNS_12_OutputArrayE (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN2cv12VideoCapture4readERKNS_12_OutputArrayE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCaptureC1ERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi (ref
erenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCaptureC1ERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCaptureD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCaptureD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZNK2cv12VideoCapture8isOpenedEv (referenced by top-level compiled C/C++ code)
warning: __ZNK2cv12VideoCapture8isOpenedEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
```


##### Issue submission checklist

 - [x] I report the issue, it's not a question
 - [x] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found solution
 - [x] I updated to latest OpenCV version and the issue is still there
 - [x] There is reproducer code and related data files: videos, images, onnx, etc