videwriter not working after image resize

asked 2015-12-17 23:33:59 -0500

Prakash gravatar image

i am using opencv 3 & visual studio. issue here is that i am unable to save video for any particular resolution other than default full camera resolution there is no error, only thing is video file doesn't grow. it stays at 5.54kb. here is my code

#include"opencv2\opencv.hpp"
using namespace cv;
using namespace std;

VideoCapture cap_cam1(0);

double Width = cap_cam1.get(CV_CAP_PROP_FRAME_WIDTH);
double Height = cap_cam1.get(CV_CAP_PROP_FRAME_HEIGHT); 
cv::Size frameSize(static_cast<int>(Width), static_cast<int>(Height));
string videoFileName = "D://current.avi";
VideoWriter cam1_write(videoFileName, CV_FOURCC('D', 'I', 'V', '3'), 10.0, frameSize, true);
Mat image;
int main()
{
    while (true)
    {
        cap_cam1 >> image;
        resize(image, image, Size(320, 240));
        imshow("image", image);
        cam1_write.write(image);
        if (waitKey(33) == 27)break;
    }

}

if i comment remove resize function, then file size grows and frames are added i also tried adding below lines after videowriter definition

cap_cam1.set(CV_CAP_PROP_FRAME_WIDTH, 240);
cap_cam1.set(CAP_PROP_FRAME_HEIGHT,320);

also tried changing resolution at videowriter definition, after everything file size remains at 5.54kb.

how to record video at custom resolution? Thanks

edit retag flag offensive close merge delete

Comments

4

if you want to write a 320x240 video, you have to pass this Size to the VideoWriter constructor, not the (original) frameSize !

berak gravatar imageberak ( 2015-12-18 00:04:16 -0500 )edit

Ok Thanks.

Prakash gravatar imagePrakash ( 2015-12-23 14:25:15 -0500 )edit