cvCreateVideoWriter
cvVideoWriter digunakan untuk menginisiasi sebuah file writer yang akan menuliskan suatu komponen tertentu ke frame video yang kita proses.cvCreateVideoWriter memungkinkan kita untuk membuat sebuah kopi video dari video asli dan melakukan pemrosesan frame per frame dari video tersebut. Namun, beberapa masalah penggunaan fungsi ini kadang muncul, terutama masalah codec yang digunakan untuk kompresi video hasil pengolahan citra. Beberapa codec mensyaratkan adanya library khusus yang diinstall dikomputer kita, sehingga ia menghasilkan video yang bisa dibaca oleh codec tersebut. Dari beberapa percobaan yang saya lakukan, saya berhasil menjalankan dengan codec CV_FOURCC(‘I’, ‘V’, ’4′, ’1′) dengan hasil jadi file *.avi. Berikut ini keterangan lebih lanjut tentang cvCreateVideoWriter.
typedef struct CvVideoWriter CvVideoWriter;
CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
double fps, CvSize frame_size, int is_color=1 );
# Initializing a video writer:
CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 25; // or 30
int frameW = 640; // 744 for firewire cameras
int frameH = 480; // 480 for firewire cameras
writer=cvCreateVideoWriter(“out.avi”,CV_FOURCC(‘P’,'I’,'M’,’1′),
fps,cvSize(frameW,frameH),isColor);
Other possible codec codes:
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
A codec code of -1 will open a codec selection window (in windows).
# Writing the video file:
IplImage* img = 0;
int nFrames = 50;
for(i=0;i<nFrames;i++){
cvGrabFrame(capture); // capture a frame
img=cvRetrieveFrame(capture); // retrieve the captured frame
cvWriteFrame(writer,img); // add the frame to the file
}
To view the captured frames during capture, add the following in the loop:
cvShowImage(“mainWin”, img);
key=cvWaitKey(20); // wait 20 ms
Note that without the 20[msec] delay the captured sequence is not displayed properly.
# Releasing the video writer:
cvReleaseVideoWriter(&writer);


No comments
Be the first one to leave a comment.