Ask Your Question
0

VideoWriter not writing frames to H264 output file [closed]

asked 2016-10-14 16:29:04 -0600

AssemblerX86 gravatar image

updated 2016-10-18 12:50:01 -0600

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.

I am using OpenCV 3.1, and I have put openh264 1.4 dll file in the same path.

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);

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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2016-10-18 15:23:20.730136

1 answer

Sort by » oldest newest most voted
0

answered 2016-10-15 02:49:24 -0600

LBerger gravatar image

updated 2016-10-18 15:20:17 -0600

I think now it is now openh264-1.5. : from alalek

OpenH264 is updated to 1.5.0 (1.6.0 is not supported by ffmpeg yet)
Environment variable name is changed to OPENH264_LIBRARY

I have tried your program. It works. I have changed cv::Size(het, wid) to cv::Size(wid,het). It could be a problem if you haven't got a multiple of 4.

I have tried to read this video (original is here and it gives this video My configuration is Windows 10 VS2015 opencv 3.1 master from github (last commit 1ae27eb) using opencv_ffmpeg310_64 and openh264-1.5.0-win64msvc.dll

edit flag offensive delete link more

Comments

For OpenCV 3.1 its still 1.4.0, and I doubt the version has to do with this problem.

AssemblerX86 gravatar imageAssemblerX86 ( 2016-10-15 13:27:10 -0600 )edit
1

I have tried your program. It works. I have changed cv::Size(het, wid) to cv::Size(wid,het). It could be a problem if you haven't got a multiple of 4.

I have tried to read this video (original is here and it gives this video My configuration is Windows 10 VS2015 opencv 3.1 master from github (last commit 1ae27eb) using opencv_ffmpeg310_64 and openh264-1.5.0-win64msvc.dll

LBerger gravatar imageLBerger ( 2016-10-15 15:28:07 -0600 )edit

"changed cv::Size(het, wid) to cv::Size(wid,het). It could be a problem" <- that solved it

AssemblerX86 gravatar imageAssemblerX86 ( 2016-10-18 12:49:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-14 16:29:04 -0600

Seen: 5,174 times

Last updated: Oct 18 '16