0

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

结果如下:

输出

输出

4

1 回答 1

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

它奏效了!

结果如下: 在此处输入图像描述

于 2015-06-18T16:06:17.783 回答