# How to record the 4k video in real time?

**URL:** https://forum.opencv.org/t/how-to-record-the-4k-video-in-real-time/10526
**Category:** Python
**Tags:** videoio
**Created:** [October 12, 2022, 8:49am UTC](https://forum.opencv.org/t/how-to-record-the-4k-video-in-real-time/10526 "2022-10-12T08:49:54Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)
#### Post date: [October 13, 2022, 5:34am UTC](https://forum.opencv.org/t/how-to-record-the-4k-video-in-real-time/10526/4 "2022-10-13T05:34:37Z")

</div>

> [@credox](#):
>
> 1. source is the /dev/video0

Ahh if it wasn’t hardware you could just directly read the raw encoded data and write to disk. I have done this on Windows with a slight modification but had limited success on linux see

> [@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…

and

> [@Not able to read Video from Capture Card with GPU (Unsupported Format) while Reading with CPU works fine](https://forum.opencv.org/t/not-able-to-read-video-from-capture-card-with-gpu-unsupported-format-while-reading-with-cpu-works-fine/9506/2):
>
> cv::cuda::VideoReader uses the FFMPEG backend so if you can’t use cv::VideoCapture(src, CAP\_FFMPEG) then it won’t work with cv::cuda::VideoReader. That said I did manage to get the FFMPEG backend to work with direct show you may be able to follow a similar procedure with V4L2 devices on linux but I coudn’t guarantee it. An alternative would be to write your own parser to read the raw input from your stereo cams by inheriting from cv::cudacodec::RawVideoSource.

if you are interested.

> [@credox](#):
>
> 1. output.mp4 with the mp4v fourcc .

Hopefully soon the `cv::cudacodec::VideoWriter` class will be fixed so if you have an Nvidia GPU this would be an option, however you would only be able to encode to raw h264|hevc files. To get container formats like mp4 you would have to post process the output files with FFmpeg or similar.

---

_[View the full topic](https://forum.opencv.org/t/how-to-record-the-4k-video-in-real-time/10526)._
