1

I am trying to read and write a video file using opencv in C++. However, when I use cv::VideoWriter, I get the following exception: enter image description here

My code is as follows: This is all the code there is.

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

int main() {
    cv::VideoCapture cap("C:\\myVid.mp4", cv::VideoCaptureAPIs::CAP_FFMPEG);
    int frame_width = cap.get(cv::CAP_PROP_FRAME_WIDTH);
    int frame_height = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
    cv::VideoWriter video("C:\\outcpp.mp4", cv::VideoWriter::fourcc('h', '2', '6', '4'), 10, cv::Size(frame_width, frame_height));

    return 0;
}

I am not able to figure out what is going wrong. The existing similar queries don't help either. I am getting the same behaviour with .avi extension and the corresponding MJPG codec.

The error snippet is as follows:

[ERROR:0@0.503] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (597) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.5) C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): └B⌐↨V☻ in function 'cv::icvExtractPattern'

Upon removing cv::VideoCaptureAPIs::CAP_FFMPEG, I get te following error:

[ERROR:0@1.000] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (166) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.5) C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap_images.cpp:235: error: (-5:Bad argument) CAP_IMAGES: error, expected '0?[1-9][du]' pattern, got: ÿ⌡∩.Ä in function 'cv::icvExtractPattern'


[ERROR:0@1.006] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (175) cv::VideoCapture::open VIDEOIO(CV_MJPEG): raised C++ exception:

bad allocation

[ERROR:0@1.016] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (597) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.5) C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): `╦┬╤▬☻ in function 'cv::icvExtractPattern'
Tree Big
  • 113
  • 9

0 Answers0