Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestVideoSource_FFmpeg.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /**
27  @file TestVideoSource_FFmpeg.cpp
28  @brief Test VideoSource_FFmpeg
29  @relates VideoSource_FFmpeg
30  @ingroup g_tests
31  @author MIP
32 */
33 
34 
35 #include <iostream>
36 #include <VideoSource/VideoSource_FFmpeg.hh>
37 #include <Base/Image/ImageBase.hh>
38 #include <Base/Image/ImageIO.hh>
39 #include <Base/Common/FileHandling.hh>
40 
41 using namespace std;
42 using namespace BIAS;
43 
44 
45 int main(int argc, char* argv[])
46 {
48 
50  string videoFile;
51  if(argc < 2) videoFile = "test.avi";
52  else videoFile = argv[1];
53  cout << "Opening video: "<<videoFile<<endl;
54  if (vid.OpenDevice(videoFile.c_str())!=0)
55  {
56  cout << "Error opening file:" << vid.GetError()<<endl;
57  return -1;
58  }
59  cout << "Initializing image..." << endl;
60  vid.InitImage(img);
61  vid.PreGrab();
62 
63 
64  int ret = 0;
65  int i = 0;
66  while (ret==0)
67  {
68  cout << "Getting frame " << i << "..." << endl;
69  if ((ret = vid.GrabSingle(img)) && i % 1 == 0)
70  {
71  cout << "Writing frame "<<i<<" to disk..." << endl;
72  if(!ImageIO::Save("frame-"+BIAS::FileHandling::LeadingZeroString(i,5)+".mip", img))
73  cout << "Error writing frame!" << endl;
74  }
75  i++;
76  }
77 
78 
79  cout << "Closing video..." << endl;
80  vid.CloseDevice();
81 
82  return 0;
83 }
virtual int InitImage(BIAS::ImageBase &Image)
virtual int OpenDevice(const char *filename)
Open video file.
virtual int GrabSingle(Camera< unsigned char > &image)
Get the next frame from the video file.
Simple video decoding of video files using FFmpeg library.
std::string GetError()
Get the last error message.
static std::string LeadingZeroString(const int &n, const unsigned int &digits=DEFAULT_LEADING_ZEROS)
Create a string with leading zeroes from number.
virtual int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
virtual int CloseDevice()
Close video file.