OpenCV: FFMPEG: tag is not supported with codec id 12 and format 'mp4 / MP4

Tina J picture Tina J · Sep 4, 2019 · Viewed 10.4k times · Source

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();
}

I pass an input.mp4 file and specify a out.mp4 as well. 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?

Answer

robowolf picture robowolf · Mar 9, 2021

I basically replaced 'MP4V' with 'mp4v' and got rid of the issue. It seems like that the API is case sensitive.