0

I have been trying to implement the cv::VideoWriter function from OpenCV to generate a an uncompressed video file. I started this because of a statement within the OpenCV Documentation which I will link here along with the statement.

cv::VideoWriter::VideoWriter    (   const String &  filename,
int     fourcc,
double  fps,
Size    frameSize,
bool    isColor = true 
)       

"If FFMPEG is enabled, using codec=0; fps=0; you can create an uncompressed (raw) video file."

Ref. https://docs.opencv.org/3.4/dd/d9e/classcv_1_1VideoWriter.html

However whilst troubleshooting the function I came across the refuting statement,

" VideoCapture and VideoWriter do not provide interface to access raw compressed video stream, except maybe MJPEG in some cases. Make sure you actually use FFmpeg backend by setting apiPreference parameter: VideoWriter("outfile.avi", cv2.CAP_FFMPEG, ...)"

Ref. https://github.com/opencv/opencv/issues/14573

I am now confused about how I go about writing the cv::VideoWriter function to satisfy the requirements to create an uncompressed video file (.avi) and if it is even possible. If it is not possible how do I achieve the outcome of saving an raw uncompressed video file, as I assume it would use some combination of FFMPEG, OpenCV,or Gstreamer.

Note: My code is implemented in c++

  • Note it says "raw **compressed** video stream", it means the compressed video stream without any file wrapper, not the raw uncompressed stream. The exception for mjpeg is because a mjpeg stream is just jpegs concatenated together and therefore doesn't need a file wrapper – Alan Birtles Sep 20 '22 at 07:47
  • Selecting FOURCC=`'RGBA'` creates uncompressed AVI with RGBA pixel format. Usually uncompressed AVI uses BGR pixel format. According to [this post](https://stackoverflow.com/a/40823045/4926757), FOURCC = `'DIB '` supposed to work, but it's not working... "Raw" and "Uncompressed" sometimes refer to two different things: "raw" may refer to "raw binary format" (without the AVI container). "Uncompressed" may refer to "not encoded", but YUV420 pixels format (for example) is still considered "uncompressed". Please do some research, and be more specific. – Rotem Sep 20 '22 at 20:57
  • Thank you the added direction, I believe that I am trying to generate an uncompressed file to avoid the generation of compression artefacts (I will append the post accordingly). In the original method implmented the files where being compressed and saved as .mkv, however now the demand has shifted to creating a method which will avoid the compression of the frames. Would you recommend pursuing the `cv::VideoWriter` function with a corresponding FOURCC value to achieve the desired outcome or is there a more suited method that you are aware of? –  Sep 21 '22 at 00:24
  • Please start your comment with @Rotem if you want me to see it. In case the main issue is compression artefacts, select a lossless codec. For example, you may use FOURCC = `'FFV1'` and `'.mkv'` file type. Using `cv::VideoWriter` is recommended, because it's the most convenient way (I know) for creating video file in C++. – Rotem Sep 21 '22 at 20:05
  • @Rotem, I have a constructor written however i keep generating the same follow up issue that any video file only contains the meta data being 336 bytes large? This is something i cannot find on the OpenCV Documentation do you have an understanding of why this occurs? –  Sep 22 '22 at 10:19
  • I don't understand your question. Are you asking something about your C++ specific implementation? In case you are **not** writing video frames to the file, it might be 336 bytes large. – Rotem Sep 22 '22 at 12:16

0 Answers0