# Not able to read Video from Capture Card with GPU (Unsupported Format) while Reading with CPU works fine

**URL:** https://forum.opencv.org/t/not-able-to-read-video-from-capture-card-with-gpu-unsupported-format-while-reading-with-cpu-works-fine/9506
**Category:** C++
**Tags:** ffmpeg, cuda, videoio, cudacodec
**Created:** [July 14, 2022, 1:50pm UTC](https://forum.opencv.org/t/not-able-to-read-video-from-capture-card-with-gpu-unsupported-format-while-reading-with-cpu-works-fine/9506 "2022-07-14T13:50:03Z")
**Posts on this page:** 1
**Showing post:** 20

<div class="post-metadata">

### Author: ![data](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@data](https://forum.opencv.org/u/data)
#### Post date: [August 12, 2022, 4:09pm UTC](https://forum.opencv.org/t/not-able-to-read-video-from-capture-card-with-gpu-unsupported-format-while-reading-with-cpu-works-fine/9506/20 "2022-08-12T16:09:10Z")

</div>

Hello @cudawarped,  
i copied my project to Windows to try out your original solution for using ffmpeg with dshow:

> [@VideoCapture from camera with CAP\_PROP\_FORMAT -1 (raw) and DSHOW/FFMPEG/windows](https://forum.opencv.org/t/videocapture-from-camera-with-cap-prop-format-1-raw-and-dshow-ffmpeg-windows/7448/6):
>
> I performed a quick test and it appears that you can retrieve the raw encoded MJPEG data from directshow using CAP\_FFMPEG if you slightly modify the [source](https://github.com/opencv/opencv/blob/4.x/modules/videoio/src/cap_ffmpeg_impl.hpp) and link OpenCV against libavdevice. You need to add avdevice\_register\_all(); to [void CvCapture\_FFMPEG::init()](https://github.com/opencv/opencv/blob/46e1560678dba83d25d309d8fbce01c40f21b7be/modules/videoio/src/cap_ffmpeg_impl.hpp#L552) and #include \<libavdevice/avdevice.h\>. Unfortunatley this means you need to build OpenCV against FFMPEG libs and not use the precompiled dll - opencv\_videoio\_ffmpegxxx\_64.dll. Once the modification is in place you simply ne…

> **Build**
>
> OS: Windows 10 Pro (21H2)  
> OpenCV: 4.6.0  
> Cuda: 11.7

> **CMake Config**
>
> ```auto
> General configuration for OpenCV 4.6.0 =====================================
> Version control: unknown
> 
> Extra modules:
> Location (extra): C:/Users/NvidiaPC/OpenCV/opencv_contrib-4.6.0/modules
> Version control (extra): unknown
> 
> Platform:
> Timestamp: 2022-08-11T11:28:03Z
> Host: Windows 10.0.19044 AMD64
> CMake: 3.24.0-rc5
> CMake generator: Visual Studio 17 2022
> CMake build tool: C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
> MSVC: 1932
> Configuration: Release
> 
> CPU/HW features:
> Baseline: SSE SSE2 SSE3
> requested: SSE3
> Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
> requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
> SSE4_1 (18 files): + SSSE3 SSE4_1
> SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
> FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
> AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
> AVX2 (33 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
> AVX512_SKX (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
> 
> C/C++:
> Built as dynamic libs?: YES
> C++ standard: 11
> C++ Compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe (ver 19.32.31332.0)
> C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MD /O2 /Ob2 /DNDEBUG 
> C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MDd /Zi /Ob0 /Od /RTC1 
> C Compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe
> C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast /MP /MD /O2 /Ob2 /DNDEBUG 
> C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast /MP /MDd /Zi /Ob0 /Od /RTC1 
> Linker flags (Release): /machine:x64 /INCREMENTAL:NO 
> Linker flags (Debug): /machine:x64 /debug /INCREMENTAL 
> ccache: NO
> Precompiled headers: NO
> Extra dependencies: cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64
> 3rdparty dependencies:
> 
> OpenCV modules:
> To be built: aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
> Disabled: -
> Disabled by dependency: -
> Unavailable: alphamat cvv freetype hdf java julia matlab ovis python2 python3 sfm viz
> Applications: tests perf_tests apps
> Documentation: NO
> Non-free algorithms: NO
> 
> Windows RT support: NO
> 
> GUI: 
> Win32 UI: YES
> VTK support: NO
> 
> Media I/O: 
> ZLib: build (ver 1.2.12)
> JPEG: build-libjpeg-turbo (ver 2.1.2-62)
> WEBP: build (ver encoder: 0x020f)
> PNG: build (ver 1.6.37)
> TIFF: build (ver 42 - 4.2.0)
> JPEG 2000: build (ver 2.4.0)
> OpenEXR: build (ver 2.3.0)
> HDR: YES
> SUNRASTER: YES
> PXM: YES
> PFM: YES
> 
> Video I/O:
> DC1394: NO
> FFMPEG: YES (prebuilt binaries)
> avcodec: YES (58.134.100)
> avformat: YES (58.76.100)
> avutil: YES (56.70.100)
> swscale: YES (5.9.100)
> avresample: YES (4.0.0)
> GStreamer: NO
> DirectShow: YES
> Media Foundation: YES
> DXVA: YES
> 
> Parallel framework: Concurrency
> 
> Trace: YES (with Intel ITT)
> 
> Other third-party libraries:
> Intel IPP: 2020.0.0 Gold [2020.0.0]
> at: C:/Users/NvidiaPC/OpenCV/build/3rdparty/ippicv/ippicv_win/icv
> Intel IPP IW: sources (2020.0.0)
> at: C:/Users/NvidiaPC/OpenCV/build/3rdparty/ippicv/ippicv_win/iw
> Lapack: NO
> Eigen: NO
> Custom HAL: NO
> Protobuf: build (3.19.1)
> 
> NVIDIA CUDA: YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
> NVIDIA GPU arch: 86
> NVIDIA PTX archs:
> 
> cuDNN: NO
> 
> OpenCL: YES (NVD3D11)
> Include path: C:/Users/NvidiaPC/OpenCV/opencv-4.6.0/3rdparty/include/opencl/1.2
> Link libraries: Dynamic load
> 
> Python (for build): NO
> 
> Java:                          
> ant: NO
> JNI: NO
> Java wrappers: NO
> Java tests: NO
> 
> Install to: C:/Users/NvidiaPC/OpenCV/build/install
> -----------------------------------------------------------------
> 
> Configuring done
> Generating done
> 
> ```

Unfortunately it does not work on first try:

```auto
cv::VideoCapture cam(0, cv::VideoCaptureAPIs::CAP_FFMPEG);

```

leads to the following error message:

**Error Message** :

```auto
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.6.0) Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ...\OpenCV\opencv-4.6.0\modules\highgui\src\window.cpp, line 967

```

---

_[View the full topic](https://forum.opencv.org/t/not-able-to-read-video-from-capture-card-with-gpu-unsupported-format-while-reading-with-cpu-works-fine/9506)._
