testffmpeg.cpp

source code for reproducing the problem. - Jack Tan, 2012-04-17 01:55 pm

Download (1.3 kB)

 
1
/*
2
 * test_video.cpp
3
 *
4
 *  Created on: April 17, 2012
5
 *      Author: Zhigang Tan
6
 *
7
 * */
8
#include "opencv2/highgui/highgui.hpp"
9
#include <opencv2/objdetect/objdetect.hpp>
10
#include <opencv2/imgproc/imgproc.hpp>
11
#include <iostream>
12
#include <vector>
13
#include <stdio.h>
14
15
using namespace cv;
16
using namespace std;
17
18
void help(char** av)
19
{
20
}
21
22
int processVideo(VideoCapture& capture)
23
{
24
  int n = 0;
25
  char filename[200];
26
  string window_name = "video | q or esc to quit";
27
  namedWindow(window_name, CV_WINDOW_KEEPRATIO); 
28
  Mat frame;
29
        int i = 2000;
30
  for (;;)
31
  {
32
                capture.set(CV_CAP_PROP_POS_FRAMES, i);
33
    capture >> frame;
34
                if (frame.empty())
35
                {
36
                        break;
37
                }
38
                
39
                int j = capture.get(CV_CAP_PROP_POS_FRAMES);
40
                cout<< "get =" << j << "| set:" << i<<endl;
41
42
                i -= 2;
43
                
44
                int bQuit = false;
45
    imshow(window_name, frame);
46
    char key = (char) waitKey(5); 
47
    switch (key)
48
    {
49
    case 'q':
50
    case 'Q':
51
    case 27: //escape key
52
                        bQuit = true;
53
      break;
54
    default:
55
      break;
56
    }
57
                if (bQuit)
58
                {
59
                        break;
60
                }
61
                
62
  }
63
        waitKey();
64
  return 0;
65
}
66
67
int main(int ac, char** av)
68
{
69
70
  if (ac != 2)
71
  {
72
    help(av);
73
    return 1;
74
  }
75
  std::string arg = av[1];
76
  VideoCapture capture(arg); 
77
  if (!capture.isOpened()) 
78
  {
79
    cerr << "Failed to open a video file!\n" << arg<< endl;
80
    help(av);
81
    return 1;
82
  }
83
  return processVideo(capture);
84
}