OpenCV: FOUR_CC tag is not supported

asked 2019-09-04 16:23:31 -0500

Tina  J gravatar image

I was trying to run a repo located HERE. Basically, just targeting SimpleVideoSummarizer.cc which uses OpenCV for some basic video processing. I'm using Ubuntu 14.04. Following is the save part of the code:

void SimpleVideoSummarizer::playAndSaveSummaryVideo(char* videoFileSave) {
    cv::VideoCapture capture(videoFile);
    cv::Mat frame;
    capture.set(CV_CAP_PROP_POS_FRAMES, 0);
    cv::VideoWriter videoWriter;
    if (videoFileSave != "") {
        videoWriter = cv::VideoWriter(videoFileSave, CV_FOURCC('M', 'J', 'P', 'G'), static_cast<int>(capture.get(CV_CAP_PROP_FPS)), cv::Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)));
    }
    for (std::set<int>::iterator it = summarySet.begin(); it != summarySet.end(); it++) {
        capture.set(CV_CAP_PROP_POS_FRAMES, segmentStartTimes[*it] * frameRate);
        for (int i = segmentStartTimes[*it]; i < segmentStartTimes[*it + 1]; i++) {
            for (int j = 0; j < frameRate; j++) {
                capture >> frame;
                cv::putText(frame, "Time: " + IntToString(i) + " seconds", cvPoint(30, 30),
                            cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(200, 200, 250), 1, CV_AA);
                if (frame.data) {
                    cv::imshow("Summary Video", frame);
                }
                if (videoFileSave != "") {
                    videoWriter.write(frame);
                }
                // Press  ESC on keyboard to exit
                char c = static_cast<char>(cv::waitKey(25));
                if (c == 27) {
                    break;
                }
            }
        }
    }
    capture.release();
}

Unfortunately, when the example is trying to save the output video file, it throws errors on the FOURCC:

OpenCV: FFMPEG: tag 0x44495658/'XVID' is not supported with codec id 12 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'

or another one:

OpenCV: FFMPEG: tag 0x3234504d/'MP42' is not supported with codec id 15 and format 'mp4 / MP4 (MPEG-4 Part 14)'
[mp4 @ 0x16bc700] Could not find tag for codec msmpeg4v2 in stream #0, codec not currently supported in container

I tried to change the FOURCC in this part of the code which writes the video, and applied XVID, MJPG, X264, MP42, MP4V. None worked and threw similar errors.

What is the problem? How to fix it?

edit retag flag offensive close merge delete

Comments

which opencv version is it ?

did you build it locally ?

berak gravatar imageberak ( 2019-09-05 06:09:36 -0500 )edit
1

3.2.4...yes I had to build it locally (I don't think there are any binaries available!)

Tina  J gravatar imageTina J ( 2019-09-05 08:29:04 -0500 )edit
1

try .avi for the filename

berak gravatar imageberak ( 2019-09-05 08:32:14 -0500 )edit

Yes, that worked! What if I want a .mp4 file? What codec should I specify?

Tina  J gravatar imageTina J ( 2019-09-05 09:14:50 -0500 )edit