12 #define PCLOSE _pclose
13 #define POPEN_MODE_WRITE "wb"
18 #define POPEN_MODE_WRITE "w"
28 const std::string & _identifier,
29 const std::string & _destination) :
31 s_identifier(_identifier),
32 destination(_destination),
36 pix_fmt = string(
"bayer_bggr8");
52 return {destination,
keepGoing?
"active":
"done"};
57 void FFMpegExtractor::openStream() {
62 "-sn -an -vcodec rawvideo -pix_fmt ", pix_fmt,
" ",
63 "-video_size ", width/reduction,
"x", height/reduction,
" ",
69 ffmpeg = POPEN(cmd.c_str(), POPEN_MODE_WRITE);
72 void FFMpegExtractor::closeStream() {
73 if(ffmpeg !=
nullptr) {
79 void FFMpegExtractor::handleSize(
unsigned int _width,
unsigned int _height,
unsigned int _bytesPerPixel) {
80 if((width != _width) | (height != _height) | (bytesPerPixel != _bytesPerPixel)) {
82 if(buffer !=
nullptr) {
87 bytesPerPixel = _bytesPerPixel;
89 buffer =
new unsigned char[width * height / (reduction * reduction)];
93 template<
typename D,
unsigned int shift,
unsigned int pattern_size>
94 void collectShift(
unsigned char* target,
void* source,
size_t width,
size_t height,
unsigned int reduction=1) {
95 D* d_source =
reinterpret_cast<D*
>(source);
97 for(
size_t i = 0; i < height; i+=reduction*pattern_size) {
98 for(
size_t ii = 0; ii < pattern_size; ++ii) {
99 for(
size_t j = 0; j < width; j+=reduction*pattern_size) {
100 for(
size_t jj = 0; jj < pattern_size; ++jj) {
101 target[k] = d_source[(i+ii)*width+(j+jj)] >> shift;
109 void FFMpegExtractor::extractImpl(
unsigned int _width,
110 unsigned int _height,
111 unsigned int _bytesPerPixel,
112 uint64_t highResTime,
114 zmq::message_t * sourceImage) {
115 handleSize(_width, _height, _bytesPerPixel);
116 if(bytesPerPixel == 1) {
117 collectShift<uint8_t, 0, 2>(buffer, sourceImage->data(), width, height, reduction);
118 }
else if(bytesPerPixel == 2) {
119 collectShift<uint16_t, 4, 2>(buffer, sourceImage->data(), width, height, reduction);
124 fwrite(buffer, width/reduction, height/reduction, ffmpeg);
129 void FFMpegExtractor::extractTeardown() {
std::string SSTR(Args &&...components)
Creates a temporary string stream for string concatenation.