iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VideoSink.H
Go to the documentation of this file.
1 /*! @file
2  @author Randolph Voorhies
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_IMAGEPROC_IO_IMAGESINK_VIDEOSINK_H
37 #define INCLUDE_NRT_IMAGEPROC_IO_IMAGESINK_VIDEOSINK_H
38 
41 
42 namespace nrt
43 {
44  class VideoWriterBase;
45 
46  namespace videosink
47  {
48  NRT_DECLARE_PARAMETER_WITH_CALLBACK(prefix, std::string, "String to prepend to all video filenames written", "",
50 
51  NRT_DECLARE_PARAMETER(ext, std::string, "File extension", "", nrt::imagesink::ParamCateg);
52 
53  NRT_DECLARE_PARAMETER_WITH_CALLBACK(quality, int,
54  "Encoded video quality. This number roughly describes the tradeoff a given encoder should "
55  "make between the size and the quality of the encoded video. A value of 1 represents "
56  "minimum size, and a value of 10 represents maximum quality.", 7,
58  }
59 
60  //! An ImageSinkType for writing to video files
61  /*! The VideoSink is a factory class which will construct for itself a set of video encoders (inheritors of
62  VideoWriterBase). When the out() method is called, a VideoSink will first check to see if it has a video file
63  already associated with the given label. If not, it will create a new one by querying the VideoWriterFactory which
64  will choose the correct encoder based on the extension specified with the --ext parameter. A new file then be
65  opened using that encoder, and then the given frame (and any subsequent frames with the same label) will be
66  written to the file. */
67  class VideoSink : public ImageSinkType,
68  public nrt::Parameter<videosink::prefix, videosink::ext, videosink::quality>
69  {
70  public:
71  VideoSink(std::string const& instanceID="video");
72  ~VideoSink();
73 
74  //! Append a frame to the video file specified by label.
75  /*! If no video file is open for the current label, then a new one will be opened using the label, the --prefix
76  Parameter, and the --ext Parameter as follows:
77 
78  \li If prefix points to a valid directory: filename = prefix/"video".ext
79  \li Otherwise, if the second to last token in prefix is a valid directory: filename = prefixvideo.ext
80  \li Otherwise, an exception is thrown. */
81  void out(GenericImage img, std::string label="");
82 
83  //! Get the name associated with our --in type
84  static std::string const id() { return "video"; }
85 
86  //! Get a description to show for --help
87  static std::string const description() { return "Writes a video file for each labeled destination."; }
88 
89  private:
90  std::string itsPrefix;
91  void onParamChange(nrt::videosink::prefix const & param, std::string const & pfx);
92  nrt::ParameterDef<std::string> createExtensionDef();
93  void onParamChange(nrt::videosink::quality const & param, int const & qual);
94  std::map<std::string/*filename*/, std::shared_ptr<VideoWriterBase>> itsWriters;
95  };
96 }
97 
98 #endif // INCLUDE_NRT_IMAGEPROC_IO_IMAGESINK_VIDEOSINK_H
99 
100