gpt4 book ai didi

c++ - 使用 C++/OpenCV 从 100fps GoPro .mp4 视频创建 25fps 慢动作视频

转载 作者:行者123 更新时间:2023-11-28 06:12:49 24 4
gpt4 key购买 nike

我有一个 100fps .mp4 GoPro 视频,我想用它创建一个 25fps 的慢动作视频。我已经尝试了两天,但无济于事。我可以播放视频,从 GoPro 的 WiFi 流中保存视频,但是当我尝试读取 100fps 并将其保存在另一个 25fps 的视频文件中时,我得到空文件!我怀疑编解码器用于对新的 mp4 视频进行编码,但我不确定。

这是代码(我在 Windows 10 预览版的 Visual Studio 2013 Community 上使用 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;
}

结果如下:

output

Output

最佳答案

正如我所怀疑的,这是编码!我用了很多,但后来我发现了这个问题:Create Video from images using VideoCapture (OpenCV)然后我在以下位置使用了编码的 MJPG:

outputVideo.open(name, CV_FOURCC('M', 'J', 'P', 'G'), 25, size, true); // create a new videoFile with 25fps

成功了!

结果如下: enter image description here

关于c++ - 使用 C++/OpenCV 从 100fps GoPro .mp4 视频创建 25fps 慢动作视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30919041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com