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

标签 c++ opencv video visual-studio-2013 slowmotion

我有一个 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/

相关文章:

opencv - 生成单 channel 掩码

jquery - 如何在响应式 fancyBox 中显示没有黑条的视频/使 iframe 适合视频内容?

c++ - 我可以列出核心转储中的所有 VTable 指针吗?

c++ - 创建 C++ 事件系统

c++ - OpenCV 中的嘈杂色调

opencv - 如何将 SIFT 描述符与局部敏感散列结合使用?

iphone - 像 iPhone 一样从浏览器自动启动 Android 中的视频播放器

ios - 从包含 YouTube 视频的 webView 返回时,如何防止我的 MPMoviePlayerController 变黑 - iOS

C++ 加密解密函数的 Java 实现(Cryptix 工具箱)

c++ - 使用OpenSSL和锁的多线程程序随机崩溃