ffmpeg_test.cpp

Furqan Khan, 2012-04-11 03:54 am

Download (2 kB)

 
1
#include "stdafx.h"
2
#include<iostream>
3
#include<vector>
4
using namespace std;
5
6
#include "opencv2/opencv.hpp"
7
using namespace cv;
8
9
int main(int argc, char* argv[])
10
{
11
        char buffer[1024] = "";
12
        char vname[512] = "inp.mov";
13
14
        VideoCapture video(vname);
15
        if(!video.isOpened()) {
16
                cout << "Can't open video: " << vname << endl;
17
                return 0;
18
        }
19
        int nFrames = video.get(CV_CAP_PROP_FRAME_COUNT);
20
        int fWidth = video.get(CV_CAP_PROP_FRAME_WIDTH);
21
        int fHeight = video.get(CV_CAP_PROP_FRAME_HEIGHT);
22
23
        bool done = false;
24
        bool next = false;
25
        int key;
26
27
        Mat display(fHeight + 200, fWidth, CV_8UC3);
28
        display(Rect(0,fHeight,fWidth,200)) = 0;
29
30
        namedWindow("Display");
31
32
        int fNum = 0;
33
        Mat currFrame;
34
        while(!done) {
35
                bool val = video.set(CV_CAP_PROP_POS_FRAMES, fNum);
36
                video >> currFrame;
37
                if(currFrame.empty()) {
38
                        cout << "Frame not found" << endl;
39
                }
40
                currFrame.copyTo(display(Rect(0, 0, fWidth, fHeight)));
41
                sprintf(buffer,"%d",fNum);
42
                putText(display, buffer, Point(fWidth - 50, 30), FONT_HERSHEY_PLAIN, 1, CV_RGB(0, 155, 0));
43
                imshow("Display", display);
44
45
                next = false;
46
                while(!next) {
47
                        key = waitKey(0);
48
                        switch(key) {
49
                                case 'n':
50
                                case 'N':
51
                                case ' ':
52
                                        fNum += 20;
53
                                        display(Rect(0, fHeight+100, fWidth, 100)) = 0;
54
                                        if(fNum >= nFrames) {
55
                                                putText(display, "Reached end of the video!", Point(fWidth/2 - 100, fHeight + 180), FONT_HERSHEY_PLAIN, 1, CV_RGB(255,0,0));
56
                                                fNum -= 20;
57
                                        }
58
                                        else
59
                                                next = true;
60
                                        break;
61
                                case 'p':
62
                                case 'P':
63
                                        fNum -= 20;
64
                                        display(Rect(0, fHeight+100, fWidth, 100)) = 0;
65
                                        if(fNum < 0) {
66
                                                putText(display, "Reached start of the video!", Point(fWidth/2 - 100, fHeight + 180), FONT_HERSHEY_PLAIN, 1, CV_RGB(255,0,0));
67
                                                fNum += 20;
68
                                        }
69
                                        else {
70
                                                //video.set(CV_CAP_PROP_POS_FRAMES, 0);
71
                                                next = true;
72
                                        }
73
                                        break;
74
                                case 'q':
75
                                        next = true;
76
                                        done = true;
77
                                        break;
78
                        }
79
                }
80
        }
81
        return 0;
82
}