[英]Creating a 25fps slow motion video from a 100fps GoPro .mp4 video with C++/OpenCV
我有一个100fps的.mp4 GoPro视频,我想从中创建一个25fps的慢动作视频。 我从两天后开始尝试,但无济于事。 我可以播放视频,从GoPro的WiFi流中保存视频,但是当我尝试读取100fps并将其保存为25fps的另一个视频文件时,我得到的是空文件! 我怀疑编解码器用于对新的mp4视频进行编码,但我不确定。
这是代码(我在Windows 10预览版的Visual Studio 2013社区中将OpenCV 3.0.0与Visual C ++一起使用)。
#include <iostream>
#include <vector>
#include <random>
#include <functional>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture inputVideo("GOPR1016.MP4"); // Open the video File
if (!inputVideo.isOpened()) {
cout << "Error opening the video" << endl;
return -1;
}
int frames_num = int(inputVideo.get(CAP_PROP_FRAME_COUNT)); // Get the number of frames in the video
cout << "Num of frames: " << frames_num << endl;
int fps = int(inputVideo.get(CAP_PROP_FPS)); // get the frame rate
cout << "FPS: " << fps << endl;
int frame_width = inputVideo.get(CAP_PROP_FRAME_WIDTH);
int frame_height = inputVideo.get(CAP_PROP_FRAME_HEIGHT);
VideoWriter outputVideo;
string name = "outputVideo.avi";
Size size = Size((int)inputVideo.get(CAP_PROP_FRAME_WIDTH), (int)inputVideo.get(CAP_PROP_FRAME_HEIGHT)); // get the resolution
outputVideo.open(name, CV_FOURCC('3', 'I', 'V', 'X'), 25, size, true); // create a new videoFile with 25fps
Mat src;
for (int i = 0; i < frames_num; i++)
{
inputVideo >> src; // read
if (src.empty()) {
break; // in case ther's nothing to read
}
outputVideo << src; // write
}
waitKey(0); // key press to close window
return 1;
}
结果如下:
正如我所怀疑的,这是编码! 我使用了很多,但后来发现了这个问题: 使用VideoCapture(OpenCV)从图像创建视频,然后在以下位置使用编码的MJPG:
outputVideo.open(name, CV_FOURCC('M', 'J', 'P', 'G'), 25, size, true); // create a new videoFile with 25fps
而且有效!
结果如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.