Last active
April 18, 2017 06:25
-
-
Save MareArts/651e46200a65c5cf41192e114156a6fc to your computer and use it in GitHub Desktop.
video_write.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://study.marearts.com/2017/04/video-show-and-write-keeping-original.html | |
void main() | |
{ | |
VideoCapture capture("rhinos.avi"); | |
Mat frame; | |
//Set properties | |
int askFileTypeBox = 0; //-1 is show box of codec | |
int Color = 1; | |
Size S = Size((int)capture.get(CV_CAP_PROP_FRAME_WIDTH), (int)capture.get(CV_CAP_PROP_FRAME_HEIGHT)); | |
//make output video file | |
VideoWriter outVideo; | |
//save video file by origin paramers | |
outVideo.open(".\\outVideo.avi", askFileTypeBox, capture.get(CV_CAP_PROP_FPS), S, Color); | |
double fps = capture.get(CV_CAP_PROP_FPS); | |
//check | |
if (!capture.isOpened()) | |
{ | |
printf("AVI file can not open.\n"); | |
return 0; | |
} | |
//create window | |
namedWindow("w"); | |
while (1) | |
{ | |
//grab frame from file & throw to Mat | |
capture >> frame; | |
if (frame.empty()) //Is video end? | |
break; | |
//processing example | |
//Sobel(frame, frame, frame.depth(), 1, 0); | |
//////////////////// | |
//outVideo.write(frame); | |
outVideo << frame; | |
//display and delay | |
imshow("w", frame); | |
//delay by origin fps | |
if (waitKey((1 / fps) * 1000) > 0) | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://study.marearts.com/2017/04/video-show-and-write-keeping-original.html