0

100fps の .mp4 GoPro ビデオがあり、そこから 25fps のスローモーション ビデオを作成したいと考えています。2日前からやってるけどダメ。ビデオを再生し、GoPro の WiFi ストリームからビデオを保存することはできましたが、100 fps を読み取って別のビデオ ファイルに 25 fps で保存しようとすると、空のファイルが表示されます! 新しい mp4 ビデオのエンコードに使用されたコーデックを疑っていますが、よくわかりません。

コードは次のとおりです(Windows 10プレビューのVisual Studio 2013 CommunityでVisual C++でOpenCV 3.0.0を使用しています)。

#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

私が疑ったように、それはコーデッドです!私はそれらの多くを使用しましたが、次の質問を見つけました: 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 に答える