OpenCV4.5.1 VideoWriter cannot open, returns fail regardless, with Qt+MinGW

Viewed 180

The code is simple like this:

cv::VideoWriter writer;
cout<<writer.open("./test001.avi",cv::CAP_FFMPEG,-1,25.0, frame.size(),1)<<endl;

I've tried different codecs and 0 (said to be for uncompressed), none of them worked and returned false. Then I tried -1 for codec select hoping a manu would appear but still nothing.

Then I think this may relate to a missing ffmpeg DLL file. I copied the file "opencv_videoio_ffmpeg_64.dll" to the directory but still nothing.

3 Answers

Instead of trying different type fourcc enumerators to get the right one , you can get the exact codec of your video(streamer source) source. Simply like:

cv::VideoCapture cap(0);

int codecType = static_cast<int>(cap.get(cv::CAP_PROP_FOURCC)); 

I thought the reason of output is false that because of the codec type is not correct. Also when I tried some examples related to this and even sometimes it gives output as false, it is saving frames with no problem.

The reason you are using the overloaded function is really about convenience as documentation mentioned ? If not, better use the other open function which is more standard.

Sorry for wasting your time. I copied the wrong dll file. It's supposed to be the opencv_videoio_ffmpeg451_64.dll in the /bin folder, rather than the opencv_videoio_ffmpeg_64.dll in /3rdparty/ffmpeg folder.

The content of the two files should be the same but names are different.

I had the same issue and would like to reiterate Janus Li's answer. If you failed to build with FFMPEG and didn't realize it, the VIDEO IO will silently fail. It will not throw an exception, but no file will be created and nothing will happen.

The solution was to make sure to either build with FFMPEG or copy the dll from 3rdparty/ffmpeg to bin with the rest of the DLLs and RENAME IT with to fit the format of the other DLLs "opencv_videoio_ffmpeg452.dll".

Related