Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleVideoSinkFFmpeg.cpp
1 
2 #include <Utils/Param.hh>
3 #include <Utils/IOUtils.hh>
4 #include <VideoSink/VideoSink_FFmpeg.hh>
5 
6 using namespace std;
7 using namespace BIAS;
8 
9 int main(int argc, char** argv) {
10 
11  Param params(true);
12 
13  string* videoFile = params.AddParamString("resultVideoFile",
14  "path to the result video file", "result.mkv", 'o');
15 
16  string* imageList = params.AddParamString("imageList",
17  "path to image list", "", 'i');
18 
19  bool* losslessCoding = params.AddParamBool("lossLessCoding", "choose loss less video coder", false);
20 
21 
22  if (!IOUtils::ParseCommandLineEvalHelp(params, argc, argv))
23  return 0;
24 
25  vector<string> imageNames;
26 
27  if (Param::ParseListFile(*imageList, imageNames) != 0) {
28  BIASERR("error: loading list " << *imageList << endl)
29  return -1;
30  } else {
31  cout << "loaded image list: " << *imageList << endl;;
32  }
33 
34  VideoSink_FFmpeg encoder;
35 
37  if (ImageIO::Load(imageNames[0],image)!=0) {
38  BIASERR("could not load first image from list")
39  return -1;
40  }
41 
42  encoder.SetSize(image.GetWidth(),image.GetHeight());
43 
44  if (*losslessCoding) {
45  encoder.SetEncoder(CODEC_ID_FFV1);
46  } else {
47  encoder.SetEncoder(CODEC_ID_MPEG4);
48  }
49 
50  int res = encoder.Open(*videoFile);
51 
52  if (res == 0) {
53 
54  res = encoder.AddFrames(imageNames);
55 
56  if (res!=0) {
57  cout << encoder.GetError() << endl;
58  }
59  } else {
60  BIASERR(encoder.GetError())
61  }
62 
63  return 0;
64 }
void SetEncoder(enum CodecID codecId)
Set encoder.
Video encoding using FFmpeg library.
int AddFrames(std::vector< std::string > filenames)
Load each Image from a list of files and add them to the video output file.
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:305
int Open(std::string filename)
Open a file for video output and init the codec.
This class Param provides generic support for parameters.
Definition: Param.hh:231
std::string GetError()
Get the last error message.
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