I'm trying to save an uncompressed raw video file given some frames with OpenCV. Going trough the doc, I can read:
If FFMPEG is enabled, using
codec=0
;fps=0
; you can create an uncompressed (raw) video file.
OpenCV seems to have FFMPEG enabled; indeed, cv::getBuildInformation()
gives me the following:
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
I'm trying the following:
#include <opencv2/videoio.hpp>
void testLosslessWriter()
{
cv::VideoCapture cap(0, cv::CAP_DSHOW);
int w = int(cap.get(cv::CAP_PROP_FRAME_WIDTH));
int h = int(cap.get(cv::CAP_PROP_FRAME_HEIGHT));
cv::VideoWriter writerUncompressed("test_raw", 0, 0, cv::Size(w, h));
}
I'm getting the following error:
OpenCV(4.7.0-dev) Error: Bad argument (CAP_IMAGES: can't find starting number (in the name of file): test_raw) in cv::icvExtractPattern, file C:\workspace\libs\opencv\modules\videoio\src\cap_images.cpp, line 253
[ERROR:0@0.325] global cap.cpp:597 cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.7.0-dev) C:\workspace\libs\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): test_raw in function 'cv::icvExtractPattern'
The same happens if I try, just for example, other formats as "test_raw.avi", "test_raw.mp4" or (made up) "test_raw.raw".
What's the right way to use the documentation hint?
Edit 1
Following Rotem answer, the problem was in fact with fps=0
; the issue above got solved with '.avi' and fourcc "RGBA".
However:
// Error returned:
// OpenCV: FFMPEG: tag 0x00000000/'????' is not supported with codec id 13 and format 'rawvideo / raw video'
cv::VideoWriter writerUncompressed("test_raw.rgb", 0, 1, cv::Size(w, h)); // the same for test_raw.yuv
The output file is written (and it is not zero-sized), but when I try to open it back with VideoCapture
using CAP_FFMPEG
or CAP_ANY
API preferences (actually using python, but that should be irrelevant) I got [IMGUTILS @ 0000003dbc7edaf0] Picture size 0x0 is invalid
and no frame is read