[mjpeg @ 0x27ee9e0] buffer smaller than minimum size

  

在利用opencv读取视频,去除视频画面上的水印、台标和logo,并重新在生成新的视频。VideoWriter 类出现报错 “[mjpeg @ 0x27ee9e0] buffer smaller than minimum size”,查了很久都没有找到原因。

代码如下:

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include 
#include 
#include 
#include "opencv2/photo/photo.hpp"

#include 

using namespace std;
using namespace cv;
int  main()
{
	clock_t start, finish;
	start = clock();
	cout << "start!!" << endl;
	string video_path = "/home/dyx/Desktop/test_logs/";
	VideoCapture capture(video_path + "test.mp4");
	if (!capture.isOpened())
		cout << "fail to open!" << endl;
	//获取帧率
	double fps =capture.get( CV_CAP_PROP_FPS);
	cout << "帧率为:" << fps << endl;
	Size videoSize(capture.get( CV_CAP_PROP_FRAME_WIDTH),capture.get( CV_CAP_PROP_FRAME_HEIGHT));

	int tem=CV_FOURCC('F', 'L', 'V', '1');
	cout<> frame;
		if (!capture.read(frame)||i>=10000)// get a new frame from camera or video
		{
			cout<<"finlish!"<

最后,通过调试发现是代码的问题,主要是VideoWriter的videoSize出了问题。把“Size videoSize(CV_CAP_PROP_FRAME_WIDTH,CV_CAP_PROP_FRAME_HEIGHT) ”改为“Size videoSize(capture.get( CV_CAP_PROP_FRAME_WIDTH),capture.get( CV_CAP_PROP_FRAME_HEIGHT))”,即可解决!

因为CV_CAP_PROP_FRAME_WIDTH=3,CV_CAP_PROP_FRAME_HEIGHT=4,即为videoSize(3,4),新生成的视频的宽高太小导致的。视频videoSize的大小最好不要小于videoSize(320,240).





你可能感兴趣的:(图像识别和分类)