2 #include "output-drv.hpp"
13 class output_driver_rawi420
: public output_driver
16 output_driver_rawi420(const std::string
& filename
, bool _uvswap
)
20 out
= new std::ofstream(filename
.c_str(), std::ios_base::binary
);
24 throw std::runtime_error("Unable to open output file");
25 set_video_callback
<output_driver_rawi420
>(*this, &output_driver_rawi420::video_callback
);
28 ~output_driver_rawi420()
36 const video_settings
& v
= get_video_settings();
37 framesize
= 4 * v
.get_width() * v
.get_height();
38 width
= v
.get_width();
41 void video_callback(uint64_t timestamp
, const uint8_t* raw_rgbx_data
)
43 std::vector
<unsigned char> tmp(framesize
* 3 / 8);
44 size_t primarysize
= framesize
/ 4;
45 size_t offs1
= primarysize
/ 4;
48 std::swap(offs1
, offs2
);
49 Convert32To_I420Frame(raw_rgbx_data
, &tmp
[0], framesize
/ 4, width
);
51 out
->write((const char*)&tmp
[0], primarysize
);
53 std::stringstream str
;
54 str
<< "Error writing frame to file (requested " << primarysize
<< ", got " << r
56 throw std::runtime_error(str
.str());
59 out
->write((const char*)&tmp
[primarysize
+ offs1
], primarysize
/ 4);
61 std::stringstream str
;
62 str
<< "Error writing frame to file (requested " << primarysize
/ 4 << ", got "
64 throw std::runtime_error(str
.str());
66 out
->write((const char*)&tmp
[primarysize
+ offs2
], primarysize
/ 4);
68 std::stringstream str
;
69 str
<< "Error writing frame to file (requested " << primarysize
/ 4 << ", got "
71 throw std::runtime_error(str
.str());
81 class output_driver_rawi420_factory
: output_driver_factory
84 output_driver_rawi420_factory(const std::string
& name
, bool _uvswap
)
85 : output_driver_factory(name
)
90 output_driver
& make(const std::string
& type
, const std::string
& name
, const std::string
& parameters
)
93 throw std::runtime_error("rawi420 output does not take parameters");
94 return *new output_driver_rawi420(name
, uvswap
);
99 output_driver_rawi420_factory
fact1("rawi420", false);
100 output_driver_rawi420_factory
fact2("rawi420-uvswap", true);