【问题标题】:Creating a 25fps slow motion video from a 100fps GoPro .mp4 video with C++/OpenCV使用 C++/OpenCV 从 100fps GoPro .mp4 视频创建 25fps 慢动作视频
【发布时间】:2015-06-18 15:02:47
【问题描述】:

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

结果如下:

【问题讨论】:

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


    【解决方案1】:

    正如我所怀疑的,它是编码的!我用了很多,但后来我发现了这个问题: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
    

    它成功了!

    结果如下:

    【讨论】:

      猜你喜欢
      • 2020-09-24
      • 2018-08-10
      • 2015-08-11
      • 2013-08-08
      • 2020-09-14
      • 2014-04-20
      • 2017-08-20
      • 1970-01-01
      • 2013-08-03
      相关资源
      最近更新 更多