2015-06-18 2 views
0

У меня есть видеоролик GoPro 100fps .mp4 GoPro, и я хочу создать из него медленный движок с 25 кадрами в секунду. Я пытаюсь с двух дней, но безрезультатно. Я мог бы воспроизвести видео, сохранить видео из потока Wi-Fi GoPro, но когда я попытаюсь прочитать 100 кадров в секунду и сохранить его в другом видеофайле с частотой 25 кадров в секунду, я получаю пустые файлы! Я подозреваю, что Codec используется для кодирования нового видео mp4, но я не уверен.Создание видео с медленным движением с частотой 25 кадров в секунду с видео с частотой 10 кадров в секунду GoPro .mp4 с C++/OpenCV

Вот код (я использую OpenCV 3.0.0 с Visual C++ в Visual Studio 2013 Community при предварительном просмотре Windows 10).

#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

ответ

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 

и это сработало!

Вот результат: enter image description here

Смежные вопросы