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) {
|
||||
std::cerr << "Buffer Resize" << std::endl;
|
||||
qDebug() << "Buffer Resize";
|
||||
mutex.lock();
|
||||
|
||||
buffer_size = new_size;
|
||||
@ -54,9 +54,8 @@ void ImageBuffer::resize(size_t new_size) {
|
||||
void ImageBuffer::push(MyImage *img) {
|
||||
mutex.lock();
|
||||
if (buffer[current_write_index] != nullptr) {
|
||||
std::cerr << "possible frame drop detected!!" << std::endl;
|
||||
std::cerr << "buffer.push write: " << current_write_index << " read: " << current_read_index << " load: " << load << std::endl;
|
||||
|
||||
qWarning() << "possible frame drop detected!!";
|
||||
qWarning() << "buffer.push write: " << current_write_index << " read: " << current_read_index << " load: " << load;
|
||||
delete(buffer[current_write_index]);
|
||||
}
|
||||
buffer[current_write_index] = img;
|
||||
@ -93,7 +92,7 @@ MyImage* ImageBuffer::pop() {
|
||||
load -= 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -688,7 +688,7 @@ VideoSpecs PylonRecorder::getVideoSpecs(const ImageSettings &settings) {
|
||||
|
||||
void PylonRecorder::startRecording() {
|
||||
qDebug() << "start recording!";
|
||||
std::string filename = createFilename();
|
||||
std::string filename = createFilename(".mp4");
|
||||
fileLabel->setText(QString::fromStdString(filename));
|
||||
qDebug() << "storing to file " << filename.c_str();
|
||||
|
||||
@ -697,6 +697,7 @@ void PylonRecorder::startRecording() {
|
||||
|
||||
VideoSpecs specs = getVideoSpecs(settings);
|
||||
specs.filename = filename;
|
||||
specs.format = VideoFormat::mp4;
|
||||
qDebug() << "got video specifications";
|
||||
|
||||
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());
|
||||
QDate date = dt.date();
|
||||
std::string base = (date.toString("yyyy.MM.dd") + "_").toStdString();
|
||||
std::string extension = ".raw";
|
||||
QString idx = QString::number(movieCount);
|
||||
std::string fname = base + idx.toStdString() + extension;
|
||||
while (QFile::exists(QString::fromStdString(fname))) {
|
||||
|
@ -78,7 +78,7 @@ private:
|
||||
void setExperimenterName();
|
||||
void setSubjectID();
|
||||
QColor progressColor(int value);
|
||||
std::string createFilename();
|
||||
std::string createFilename(const std::string &extension=".raw");
|
||||
void cameraConfiguration();
|
||||
VideoSpecs getVideoSpecs(const ImageSettings &settings);
|
||||
|
||||
|
4
util.h
4
util.h
@ -25,4 +25,8 @@ struct CameraLayout {
|
||||
CameraMode mode;
|
||||
};
|
||||
|
||||
enum class VideoFormat {
|
||||
raw,
|
||||
mp4
|
||||
};
|
||||
#endif /*UTIL_H*/
|
46
writer.cpp
46
writer.cpp
@ -2,6 +2,7 @@
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
|
||||
#include <pylon/VideoWriter.h>
|
||||
using namespace std::chrono;
|
||||
|
||||
void Writer::setVideoSpecs(VideoSpecs specs) {
|
||||
@ -28,21 +29,28 @@ void Writer::run() {
|
||||
size_t count = 0;
|
||||
size_t chunksize = 256;
|
||||
// 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) {
|
||||
stop_request = false;
|
||||
stopNow = false;
|
||||
|
||||
std::ofstream myFile;
|
||||
if (videoSpecs.format == VideoFormat::raw) {
|
||||
myFile.open(videoSpecs.filename, std::ios::out | std::ios::binary);
|
||||
myFile.write((char*)&videoSpecs.width, 4);
|
||||
myFile.write((char*)&videoSpecs.height, 4);
|
||||
// Pylon::CVideoWriter videoWriter;
|
||||
// videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
||||
// videoSpecs.fps, videoSpecs.quality);
|
||||
// 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;
|
||||
} else {
|
||||
videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType, videoSpecs.fps, videoSpecs.quality);
|
||||
videoWriter.Open(videoSpecs.filename.c_str());
|
||||
}
|
||||
|
||||
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::Section s = nix_file.createSection("Recording", "nix.recording");
|
||||
@ -88,17 +96,17 @@ void Writer::run() {
|
||||
if (img != nullptr) {
|
||||
auto start = high_resolution_clock::now();
|
||||
// framecount += 1;
|
||||
if (videoSpecs.format == VideoFormat::raw) {
|
||||
myFile.write((char*)img->data(), img->size());
|
||||
|
||||
// Pylon::CPylonImage pyImage;
|
||||
// try {
|
||||
// pyImage.AttachUserBuffer(img->data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
||||
// // Test duration of writing...
|
||||
// videoWriter.Add( pyImage );
|
||||
|
||||
// } catch (const Pylon::GenericException &e) {
|
||||
// std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||
// }
|
||||
} else {
|
||||
Pylon::CPylonImage pyImage;
|
||||
try {
|
||||
pyImage.AttachUserBuffer(img->data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
||||
videoWriter.Add(pyImage);
|
||||
} 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 duration = duration_cast<microseconds>(stop - start);
|
||||
std::cerr << "wrote binary to file " << duration.count() << std::endl;
|
||||
|
2
writer.h
2
writer.h
@ -10,6 +10,7 @@
|
||||
#include "imagebuffer.h"
|
||||
#include "projectsettings.h"
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "util.h"
|
||||
|
||||
struct VideoSpecs {
|
||||
std::string filename;
|
||||
@ -20,6 +21,7 @@ struct VideoSpecs {
|
||||
double detectorGain;
|
||||
Pylon::EPixelType pixelType;
|
||||
Pylon::EImageOrientation orientation;
|
||||
VideoFormat format = VideoFormat::raw;
|
||||
};
|
||||
|
||||
class Writer : public QThread
|
||||
|
Loading…
Reference in New Issue
Block a user