I am VideoWriter to write frames which are read from VideoCapture. The H264 file has the header and tail information written, but no frames are written in the file, the file is just 1KB large. Here is my code:
#include <iostream>
#include <stdio.h>
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat testFrame;
VideoCapture vidReader("vid.mp4");
//vidReader.read(testFrame);
unsigned int frameCount = vidReader.get(CV_CAP_PROP_FRAME_COUNT);
double FPS = vidReader.get(CV_CAP_PROP_FPS);
int format = vidReader.get(CV_CAP_PROP_FOURCC);
int wid = vidReader.get(CV_CAP_PROP_FRAME_WIDTH);
int het = vidReader.get(CV_CAP_PROP_FRAME_HEIGHT);
//int fcount = vidReader.get(CV_CAP_PROP_FRAME_COUNT);
Mat injectFrame;
injectFrame.create(het, wid, CV_32F);
VideoWriter vidWriter;
vidWriter.open("vid2.mp4", CV_FOURCC('H', '2', '6', '4'), FPS, cv::Size(het, wid), true);
//for(int i = 0; i < 120; i++) vidWriter.write(injectFrame);
if (!vidWriter.isOpened())
{
printf("\nFailed to open\n");
return 1;
}
int ct = 0;
while (1)
{
printf("Frame: %d\n", ct);
Mat nxtFrame;
if (!vidReader.read(nxtFrame))
{
printf("Couldn't read next frame\n");
break;
}
else printf("grabbed frame\n");
vidWriter.write(nxtFrame);
ct++;
}
//printf("Frames: %d\n", fcount);
vidWriter.release();
}
Thanks in advance.