cgv
Loading...
Searching...
No Matches
video_writer.cxx
1#include "video_writer.h"
2#include <cgv/base/register.h>
3#include <cgv/utils/scan.h>
4#include <vector>
5
6using namespace cgv::base;
7using namespace cgv::data;
8using namespace cgv::utils;
9
10namespace cgv {
11 namespace media {
12 namespace video {
13
14
16bool abst_video_writer::scan_codecs(std::vector<std::string>&) const
17{
18 return false;
19}
20
22bool abst_video_writer::set_codec(const std::string&)
23{
24 return false;
25}
26
29{
30 return "";
31}
32
35{
36 static std::vector<abst_video_writer*>& ref_writers()
37 {
38 static std::vector<abst_video_writer*> writers;
39 return writers;
40 }
41 std::string get_type_name() const
42 {
43 return "video_writer_listener";
44 }
45 void register_object(base_ptr object, const std::string&)
46 {
48 if (rd)
49 ref_writers().push_back(rd);
50 }
51 void unregister_object(base_ptr object, const std::string&)
52 {
53 for (unsigned int i=0; i<ref_writers().size(); ++i) {
54 if (object == ref_writers()[i]) {
55 ref_writers().erase(ref_writers().begin()+i);
56 ++i;
57 }
58 }
59 }
60};
61
65{
66 static std::string exts;
67 exts.clear();
68 std::vector<abst_video_writer*>& writers = video_writer_listener::ref_writers();
69 for (unsigned int i=0; i<writers.size(); ++i) {
70 if (!exts.empty())
71 exts += ';';
72 exts += writers[i]->get_supported_extensions();
73 }
74 if (sep != ';')
76 return exts;
77}
78
80{
81 std::string text = "Video Files (";
82 std::string exts = "*.";
83 text += get_supported_extensions(',');
84 text += "):";
86 replace(exts,",",";*.");
87 return text+exts;
88}
89
90
91
94{
95 wr = 0;
96 std::string ext = to_lower(file_extension);
97 std::vector<abst_video_writer*>& writers = video_writer_listener::ref_writers();
98 for (unsigned int i=0; i<writers.size(); ++i) {
100 wr = writers[i]->clone();
101 return;
102 }
103 }
104 last_error = "no video writer found for extension: ";
105 last_error += ext;
106}
107
109const std::string& video_writer::get_last_error() const
110{
111 if (!wr)
112 return last_error;
113 return wr->get_last_error();
114}
115
118{
119 if (wr)
120 return wr->get_type_name();
121 return "cmv::video_writer";
122}
123
125bool video_writer::scan_codecs(std::vector<std::string>& codec_names) const
126{
127 if (wr)
128 return wr->scan_codecs(codec_names);
129 return false;
130}
131
133bool video_writer::set_codec(const std::string& codec_name)
134{
135 if (wr)
136 return wr->set_codec(codec_name);
137 return false;
138}
139
141std::string video_writer::get_codec() const
142{
143 if (wr)
144 return wr->get_codec();
145 return "";
146}
147
155
157bool video_writer::set_void(const std::string& property, const std::string& type, const void* value)
158{
159 if (wr)
160 return wr->set_void(property, type, value);
161 return cgv::base::base::set_void(property, type, value);
162}
164bool video_writer::get_void(const std::string& property, const std::string& type, void* value)
165{
166 if (wr)
167 return wr->get_void(property, type, value);
168 return cgv::base::base::get_void(property, type, value);
169}
170
173bool video_writer::open(const std::string& file_name, const data_format& image_format, float fps, bool interactive)
174{
175 if (wr)
176 return wr->open(file_name, image_format, fps, interactive);
177 last_error = "no video writer available";
178 return false;
179}
183{
184 if (wr)
185 return wr->write_frame(image_data);
186 last_error = "no video writer available";
187 return false;
188}
189
192{
193 if (wr)
194 return wr->close();
195 last_error = "no video writer available";
196 return false;
197}
198
199
200object_registration<video_writer_listener> video_writer_listener_registration("register video writer listener");
201
202 }
203 }
204}
205
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
virtual std::string get_property_declarations()
return a semicolon separated list of property declarations
Definition base.cxx:264
T * get_interface()
use dynamic type cast to check for the given interface
Definition base.h:128
virtual bool set_void(const std::string &property, const std::string &value_type, const void *value_ptr)
abstract interface for the setter of a dynamic property.
Definition base.cxx:181
virtual std::string get_type_name() const
overload to return the type name of this object. By default the type interface is queried over get_ty...
Definition base.cxx:241
virtual bool get_void(const std::string &property, const std::string &value_type, void *value_ptr)
abstract interface for the getter of a dynamic property.
Definition base.cxx:215
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
The const_data_view has the functionality of the data_view but uses a const pointer and therefore doe...
Definition data_view.h:221
A data_format describes a multidimensional data block of data entries.
Definition data_format.h:17
abstract interface for video writers
virtual bool close()=0
close the video file
virtual bool scan_codecs(std::vector< std::string > &codec_names) const
dummy implementation provided that does nothing and returns false
virtual bool write_frame(const cgv::data::const_data_view &image_data)=0
write the next frame
virtual bool set_codec(const std::string &codec_name)
dummy empty implementation provided that does nothing and returns false
virtual bool open(const std::string &file_name, const cgv::data::data_format &image_format, float fps, bool interactive)=0
open file from given file name, format and fps
virtual const std::string & get_last_error() const =0
return a reference to the last error message
virtual std::string get_codec() const
return the currently selected codec, default implementation returns empty string
static const std::string & get_supported_extensions(char sep=';')
return a string with a list of supported extensions, where the list entries are separated with the pa...
std::string last_error
store the last error not resulting from video writer implementations
std::string get_codec() const
return the currently selected codec
video_writer(const std::string &file_extension)
construct a video writer from a file extension and choose an implementation based on the extension
bool write_frame(const cgv::data::const_data_view &image_data)
write the image data stored in the data view as next video frame to the previously opened video file.
bool close()
close the video file
bool open(const std::string &file_name, const cgv::data::data_format &image_format, float fps=25, bool interactive=false)
open a video file for writing images in the given format with the given fps.
std::string get_property_declarations()
return a semicolon separated list of property declarations supported by the selected codec.
const std::string & get_last_error() const
return a reference to the last error message
std::string get_type_name() const
returns the type name of the chosen video writer implementation
bool get_void(const std::string &property, const std::string &type, void *value)
abstract interface for the getter, uses the interface of the selected writer implementation
bool set_codec(const std::string &codec_name)
select a specific codec. This will chance the properties available with the property interface.
static std::string construct_filter_string()
use this to generate a file_open_dialog or file_save_dialog
bool scan_codecs(std::vector< std::string > &codec_names) const
return a list of supported codecs in text format
abst_video_writer * wr
store a pointer to the chosen reader
bool set_void(const std::string &property, const std::string &type, const void *value)
abstract interface for the setter, uses the interface of the selected writer implementation
the base namespace holds the base hierarchy, support for plugin registration and signals
Definition action.cxx:4
namespace for data management components
namespace that holds tools that dont fit any other namespace
unsigned int replace(std::string &s, char c1, char c2)
replace char c1 with c2 in the given string _s and return number of replacements
Definition scan.cxx:159
char to_lower(char c)
convert char to lower case
Definition scan.cxx:39
bool is_element(char c, const std::string &s)
check if char c arises in string s
Definition scan.cxx:291
the cgv namespace
Definition print.h:11
Helper functions to process strings.
interfaces that allows to listen to registration events.
Definition register.h:218
interfaces that allows to listen to registration events
std::string get_type_name() const
overload to return the type name of this object. By default the type interface is queried over get_ty...
void unregister_object(base_ptr object, const std::string &)
overload to handle unregistration events
void register_object(base_ptr object, const std::string &)
overload to handle registration events