我希望在缩小尺寸处理后存储视频。目前我使用与输入视频相同的大小。我正在使用c ++打开CV。
答案 0 :(得分:2)
如果您的目标是更改视频分辨率,请将resize()
功能用于存储图像的矩阵:
Mat source, destination;
IplImage new_img;
int fps = 30;
// Apply resize
resize(source, destination, Size(640, 360), 1, 1, 1);
// Create writer
CvVideoWriter *new_writer = cvCreateVideoWriter("video.mp4",CV_FOURCC('M', 'P', '4', '2'), fps, destination.size(), 3);
new_img = destination.operator IplImage();
// 1-if image written or 0 if failed
int ret = cvWriteFrame(new_writer, (const IplImage*)&new_img);
printf("Written?: %d\n", ret);
// And finally release writer
cvReleaseVideoWriter(&new_writer);
如果您的目标是减少磁盘上的视频大小,请尝试使用各种编解码器创建VideoWriter,例如:
CV_FOURCC('P','I','M','1') = MPEG-1 codec
CV_FOURCC('M','J','P','G') = motion-jpeg codec (does not work well)
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec