Ask Your Question
1

Writing video fail with no error

asked 2017-01-23 12:32:52 -0500

ClementD gravatar image

Hello I am using QT and OpenCV 3.1.0 on a Win7 PC.

I am trying to record my camera and i don't know why but the file is always empty. i tired using other codec but it's always fails. any idea?

int main(int argc, char *argv[])

{

cv::VideoCapture cap(0);
cv::VideoWriter rec;
bool first = true;
for(;;)
{
    cv::Mat frame;

    cap >> frame;
    if (first)
    {
        qDebug()<< "init";
        rec.open("C:/Project/outi.avi", CV_FOURCC('X','V','I','D'), 24, cv::Size(frame.size().height,frame.size().width));
        if (!rec.isOpened())
        {
            qDebug()<< "open record fail";
            return 0;
        }
        first = false;
    }
    rec << frame;
    cv::imshow("test", frame);
    if (cv::waitKey(30) == 'q')
    {
        break;
    }
}
return 0;

}

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2017-01-24 01:39:57 -0500

berak gravatar image

cv::Size is Size(Width, Height). your arguments are in the wrong order, and you cannot open a videowriter with this wrong size.

edit flag offensive delete link more

Comments

Hi, I switched it and it's still not working. I don't know why but the file was openned. It does create a file "outi.avi" but the file is empty (like 6Ko). Do you know if the probleme could comme from the file ffmpeg.dll? do i have to rename it ?or put it somewhere? maybe include it in my ".pro" file?

ClementD gravatar imageClementD ( 2017-01-24 01:50:35 -0500 )edit

put the ffmpeg.dll either on the PATH, or next to your binary. (do NOT rename it)

berak gravatar imageberak ( 2017-01-24 01:52:37 -0500 )edit

Ok , i'll try tonight. Do you know where i can find all codec? or the most common codec? Moreover, is there a way to see VideoWriter status? because i don't have any error.

ClementD gravatar imageClementD ( 2017-01-24 01:56:20 -0500 )edit

sadly, the answer is NO, to all your questions.

berak gravatar imageberak ( 2017-01-24 01:59:11 -0500 )edit

Haha no problems. Thanks you.

ClementD gravatar imageClementD ( 2017-01-24 02:00:30 -0500 )edit

Do you have a working example on your pc?

ClementD gravatar imageClementD ( 2017-01-24 02:00:58 -0500 )edit
0

answered 2017-05-23 02:54:01 -0500

psykomusic gravatar image

Hi, I don't know if your question still unanswered, but you forgot to release the videowritter. After your while you can write :

rec.release();

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-01-23 12:32:52 -0500

Seen: 724 times

Last updated: May 23 '17