简体   繁体   中英

Change size of stored video using video writer?

我希望在处理后以缩小的尺寸存储视频。目前我使用与输入视频相同的大小。我正在使用c ++开放CV。

If you aim to change video resolution then use resize() function to a matrix that stores your image:

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

If you aim to reduce video size on a disk then try to create VideoWriter with various codecs such as:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM