support mp4 output
This commit is contained in:
parent
47ea6fb27e
commit
7ad190513a
@ -39,7 +39,7 @@ size_t ImageBuffer::bufferLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ImageBuffer::resize(size_t new_size) {
|
void ImageBuffer::resize(size_t new_size) {
|
||||||
std::cerr << "Buffer Resize" << std::endl;
|
qDebug() << "Buffer Resize";
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
|
||||||
buffer_size = new_size;
|
buffer_size = new_size;
|
||||||
@ -54,9 +54,8 @@ void ImageBuffer::resize(size_t new_size) {
|
|||||||
void ImageBuffer::push(MyImage *img) {
|
void ImageBuffer::push(MyImage *img) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
if (buffer[current_write_index] != nullptr) {
|
if (buffer[current_write_index] != nullptr) {
|
||||||
std::cerr << "possible frame drop detected!!" << std::endl;
|
qWarning() << "possible frame drop detected!!";
|
||||||
std::cerr << "buffer.push write: " << current_write_index << " read: " << current_read_index << " load: " << load << std::endl;
|
qWarning() << "buffer.push write: " << current_write_index << " read: " << current_read_index << " load: " << load;
|
||||||
|
|
||||||
delete(buffer[current_write_index]);
|
delete(buffer[current_write_index]);
|
||||||
}
|
}
|
||||||
buffer[current_write_index] = img;
|
buffer[current_write_index] = img;
|
||||||
@ -93,7 +92,7 @@ MyImage* ImageBuffer::pop() {
|
|||||||
load -= 1;
|
load -= 1;
|
||||||
}
|
}
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
std::cerr << "buffer.pop write: " << current_write_index << " read: " << current_read_index << " load: " << load << std::endl;
|
// std::cerr << "buffer.pop write: " << current_write_index << " read: " << current_read_index << " load: " << load << std::endl;
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
@ -688,7 +688,7 @@ VideoSpecs PylonRecorder::getVideoSpecs(const ImageSettings &settings) {
|
|||||||
|
|
||||||
void PylonRecorder::startRecording() {
|
void PylonRecorder::startRecording() {
|
||||||
qDebug() << "start recording!";
|
qDebug() << "start recording!";
|
||||||
std::string filename = createFilename();
|
std::string filename = createFilename(".mp4");
|
||||||
fileLabel->setText(QString::fromStdString(filename));
|
fileLabel->setText(QString::fromStdString(filename));
|
||||||
qDebug() << "storing to file " << filename.c_str();
|
qDebug() << "storing to file " << filename.c_str();
|
||||||
|
|
||||||
@ -697,6 +697,7 @@ void PylonRecorder::startRecording() {
|
|||||||
|
|
||||||
VideoSpecs specs = getVideoSpecs(settings);
|
VideoSpecs specs = getVideoSpecs(settings);
|
||||||
specs.filename = filename;
|
specs.filename = filename;
|
||||||
|
specs.format = VideoFormat::mp4;
|
||||||
qDebug() << "got video specifications";
|
qDebug() << "got video specifications";
|
||||||
|
|
||||||
if (buffer != nullptr) {
|
if (buffer != nullptr) {
|
||||||
@ -825,11 +826,10 @@ QColor PylonRecorder::progressColor(int value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string PylonRecorder::createFilename() {
|
std::string PylonRecorder::createFilename(const std::string &extension) {
|
||||||
QDateTime dt(QDateTime::currentDateTimeUtc());
|
QDateTime dt(QDateTime::currentDateTimeUtc());
|
||||||
QDate date = dt.date();
|
QDate date = dt.date();
|
||||||
std::string base = (date.toString("yyyy.MM.dd") + "_").toStdString();
|
std::string base = (date.toString("yyyy.MM.dd") + "_").toStdString();
|
||||||
std::string extension = ".raw";
|
|
||||||
QString idx = QString::number(movieCount);
|
QString idx = QString::number(movieCount);
|
||||||
std::string fname = base + idx.toStdString() + extension;
|
std::string fname = base + idx.toStdString() + extension;
|
||||||
while (QFile::exists(QString::fromStdString(fname))) {
|
while (QFile::exists(QString::fromStdString(fname))) {
|
||||||
|
@ -78,7 +78,7 @@ private:
|
|||||||
void setExperimenterName();
|
void setExperimenterName();
|
||||||
void setSubjectID();
|
void setSubjectID();
|
||||||
QColor progressColor(int value);
|
QColor progressColor(int value);
|
||||||
std::string createFilename();
|
std::string createFilename(const std::string &extension=".raw");
|
||||||
void cameraConfiguration();
|
void cameraConfiguration();
|
||||||
VideoSpecs getVideoSpecs(const ImageSettings &settings);
|
VideoSpecs getVideoSpecs(const ImageSettings &settings);
|
||||||
|
|
||||||
|
4
util.h
4
util.h
@ -25,4 +25,8 @@ struct CameraLayout {
|
|||||||
CameraMode mode;
|
CameraMode mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class VideoFormat {
|
||||||
|
raw,
|
||||||
|
mp4
|
||||||
|
};
|
||||||
#endif /*UTIL_H*/
|
#endif /*UTIL_H*/
|
46
writer.cpp
46
writer.cpp
@ -2,6 +2,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <pylon/VideoWriter.h>
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
void Writer::setVideoSpecs(VideoSpecs specs) {
|
void Writer::setVideoSpecs(VideoSpecs specs) {
|
||||||
@ -28,21 +29,28 @@ void Writer::run() {
|
|||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
size_t chunksize = 256;
|
size_t chunksize = 256;
|
||||||
// size_t framecount = 0;
|
// size_t framecount = 0;
|
||||||
|
std::ofstream myFile;
|
||||||
|
if (videoSpecs.format == VideoFormat::mp4 && !Pylon::CVideoWriter::IsSupported()) {
|
||||||
|
qWarning() << "VideoWriter is not supported at the moment. Please install the pylon Supplementary Package for MPEG-4 which is available on the Basler website.";
|
||||||
|
// Releases all pylon resources.
|
||||||
|
// PylonTerminate();
|
||||||
|
// Return with error code 1.
|
||||||
|
emit writingDone();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pylon::CVideoWriter videoWriter;
|
||||||
if (specs_valid) {
|
if (specs_valid) {
|
||||||
stop_request = false;
|
stop_request = false;
|
||||||
stopNow = false;
|
stopNow = false;
|
||||||
|
if (videoSpecs.format == VideoFormat::raw) {
|
||||||
std::ofstream myFile;
|
|
||||||
myFile.open(videoSpecs.filename, std::ios::out | std::ios::binary);
|
myFile.open(videoSpecs.filename, std::ios::out | std::ios::binary);
|
||||||
myFile.write((char*)&videoSpecs.width, 4);
|
myFile.write((char*)&videoSpecs.width, 4);
|
||||||
myFile.write((char*)&videoSpecs.height, 4);
|
myFile.write((char*)&videoSpecs.height, 4);
|
||||||
// Pylon::CVideoWriter videoWriter;
|
} else {
|
||||||
// videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType, videoSpecs.fps, videoSpecs.quality);
|
||||||
// videoSpecs.fps, videoSpecs.quality);
|
videoWriter.Open(videoSpecs.filename.c_str());
|
||||||
// std::cout << !Pylon::CVideoWriter::IsSupported() << std::endl;
|
}
|
||||||
// videoWriter.SetParameter();
|
|
||||||
// videoWriter.Open(videoSpecs.filename.c_str());
|
|
||||||
// std::cerr << "Video writer is open!" << videoWriter.IsOpen() << std::endl;
|
|
||||||
nix::File nix_file =nix::File::open(videoSpecs.filename + ".nix", nix::FileMode::Overwrite, "hdf5", nix::Compression::DeflateNormal);
|
nix::File nix_file =nix::File::open(videoSpecs.filename + ".nix", nix::FileMode::Overwrite, "hdf5", nix::Compression::DeflateNormal);
|
||||||
nix::Block b = nix_file.createBlock("Recording", "nix.recording");
|
nix::Block b = nix_file.createBlock("Recording", "nix.recording");
|
||||||
nix::Section s = nix_file.createSection("Recording", "nix.recording");
|
nix::Section s = nix_file.createSection("Recording", "nix.recording");
|
||||||
@ -88,17 +96,17 @@ void Writer::run() {
|
|||||||
if (img != nullptr) {
|
if (img != nullptr) {
|
||||||
auto start = high_resolution_clock::now();
|
auto start = high_resolution_clock::now();
|
||||||
// framecount += 1;
|
// framecount += 1;
|
||||||
|
if (videoSpecs.format == VideoFormat::raw) {
|
||||||
myFile.write((char*)img->data(), img->size());
|
myFile.write((char*)img->data(), img->size());
|
||||||
|
} else {
|
||||||
// Pylon::CPylonImage pyImage;
|
Pylon::CPylonImage pyImage;
|
||||||
// try {
|
try {
|
||||||
// pyImage.AttachUserBuffer(img->data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
pyImage.AttachUserBuffer(img->data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
||||||
// // Test duration of writing...
|
videoWriter.Add(pyImage);
|
||||||
// videoWriter.Add( pyImage );
|
} catch (const Pylon::GenericException &e) {
|
||||||
|
std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||||
// } catch (const Pylon::GenericException &e) {
|
}
|
||||||
// std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
}
|
||||||
// }
|
|
||||||
auto stop = high_resolution_clock::now();
|
auto stop = high_resolution_clock::now();
|
||||||
auto duration = duration_cast<microseconds>(stop - start);
|
auto duration = duration_cast<microseconds>(stop - start);
|
||||||
std::cerr << "wrote binary to file " << duration.count() << std::endl;
|
std::cerr << "wrote binary to file " << duration.count() << std::endl;
|
||||||
|
2
writer.h
2
writer.h
@ -10,6 +10,7 @@
|
|||||||
#include "imagebuffer.h"
|
#include "imagebuffer.h"
|
||||||
#include "projectsettings.h"
|
#include "projectsettings.h"
|
||||||
#include <opencv2/opencv.hpp>
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct VideoSpecs {
|
struct VideoSpecs {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
@ -20,6 +21,7 @@ struct VideoSpecs {
|
|||||||
double detectorGain;
|
double detectorGain;
|
||||||
Pylon::EPixelType pixelType;
|
Pylon::EPixelType pixelType;
|
||||||
Pylon::EImageOrientation orientation;
|
Pylon::EImageOrientation orientation;
|
||||||
|
VideoFormat format = VideoFormat::raw;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Writer : public QThread
|
class Writer : public QThread
|
||||||
|
Loading…
Reference in New Issue
Block a user