我试图运行一个位于HERE的仓库。基本上,只是针对SimpleVideoSummarizer.cc
使用 OpenCV 进行一些基本视频处理。我正在使用 Ubuntu 14.04。以下是代码的保存部分:
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();
}
我传递了一个input.mp4
文件并指定了一个out.mp4
。不幸的是,当示例尝试保存输出视频文件时,它会在 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'
或另一个:
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
我尝试在编写视频的这部分代码中更改 FOURCC,并应用 XVID、MJPG、X264、MP42、MP4V。没有工作并抛出类似的错误。
问题是什么?如何解决?