Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleVideoSourceFFmpeg.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 #include <Utils/Param.hh>
26 #include <Utils/IOUtils.hh>
27 #include <VideoSource/VideoSource_FFmpeg.hh>
28 
29 using namespace std;
30 using namespace BIAS;
31 
32 int main(int argc, char** argv) {
33 
34 
35 
36  Param params(true);
37 
38  string* videoFile = params.AddParamString("videoFile",
39  "path to the video file", "", 'i');
40 
41  int* maxNumberOfFrames = params.AddParamInt("maxNumberOfFrames",
42  "maximal number of frames",INT_MAX, 0, INT_MAX, 'n');
43 
44  if (!IOUtils::ParseCommandLineEvalHelp(params, argc, argv))
45  return 0;
46 
47  cout << "getting " << *maxNumberOfFrames << endl;
48 
49 
51 
52  VideoSource_FFmpeg decoder;
53 
54  if (decoder.OpenDevice(videoFile->c_str()) < 0 ) {
55  cout << decoder.GetError();
56  exit(1);
57  }
58  decoder.InitImage(image);
59  decoder.PreGrab();
60 
61 
62  string dir, base, suffix;
63  FileHandling::SplitName(*videoFile, dir, base, suffix);
64 
65  int res = 0;
66 
67  unsigned int numberOfImageSaved = 0;
68 
69 
70  while (res == 0 && (int)numberOfImageSaved < *maxNumberOfFrames) {
71 
72  cout << "got frame " << numberOfImageSaved << endl;
73  res = decoder.GrabSingle(image);
74  if(res != 0) BIASERR("Error:"<<decoder.GetError());
75  string imageName = base+"_"+FileHandling::LeadingZeroString(numberOfImageSaved, 4) + ".png";
76  ImageIO::Save(imageName,image);
77 
78  numberOfImageSaved ++;
79  }
80 
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.
virtual int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
This class Param provides generic support for parameters.
Definition: Param.hh:231
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327