First, define the video writer as follow
CvVideoWriter* writer = cvCreateVideoWriter(filepath,fourcc, fps, frame_size, iscolor);
โดยที่
filepath เป็นที่อยู่ของวิดีโอที่ต้องการจะบันทึก ในที่นี้ใช้นามสกุล avi
fourcc เป็น codec ของวิดีโอที่จะบันทึก ในที่นี้ใช้ CV_FOURCC('M','J','P','G')
where
filepath is the path of output video file, in this case, file extension is avi
fourcc is the codec of video, in this case, CV_FOURCC('M','J','P','G') is used
ขั้นที่สอง เขียนเฟรมแต่ละเฟรมไปยังวิดีโอที่บันทึก
Second, write frame to output video as follow
cvWriteFrame(writer, frame);
ขั้นสุดท้าย ปลดปล่อยหน่วยความจำสำหรับตัวแปรที่ใช้เขียนไฟล์วิดีโอ
Last, release the video writer
cvReleaseVideoWriter(&writer);