Permalink
Browse files

VideoWriter

  • Loading branch information...
1 parent daca1a1 commit 1322e58bd92c2cfc0d5875ff7484f221cca484ce @peterbraden committed Mar 6, 2013
Showing with 103 additions and 4 deletions.
  1. +1 −0 binding.gyp
  2. +8 −4 lib/opencv.js
  3. +77 −0 src/VideoWriter.cc
  4. +15 −0 src/VideoWriter.h
  5. +2 −0 src/init.cc
View
@@ -9,6 +9,7 @@
, "src/Contours.cc"
, "src/Point.cc"
, "src/VideoCaptureWrap.cc"
+ , "src/VideoWriter.cc"
, "src/CamShift.cc"
, "src/HighGUI.cc"
]
View
@@ -129,10 +129,14 @@ videostream.read = function(){
var frame = function(){
self.video.read(function(mat){
- self.emit('data', mat)
- if (!this.paused){
- process.nextTick(frame)
- }
+ if (mat.width() && mat.height()){
+ self.emit('data', mat)
+ if (!this.paused){
+ process.nextTick(frame)
+ }
+ } else {
+ self.emit('end')
+ }
})
}
View
@@ -0,0 +1,77 @@
+#include "VideoWriter.h"
+#include "Matrix.h"
+#include "OpenCV.h"
+
+v8::Persistent<FunctionTemplate> VideoWriterWrap::constructor;
+
+void
+VideoWriterWrap::Init(Handle<Object> target) {
+ HandleScope scope;
+
+ // Constructor
+ constructor = Persistent<FunctionTemplate>::New(
+ FunctionTemplate::New(VideoWriterWrap::New));
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(String::NewSymbol("VideoWriter"));
+
+ // Prototype
+ //Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
+
+ NODE_SET_PROTOTYPE_METHOD(constructor, "write", Write);
+
+ target->Set(String::NewSymbol("VideoWriter"), constructor->GetFunction());
+};
+
+
+
+Handle<Value>
+VideoWriterWrap::New(const Arguments &args) {
+ HandleScope scope;
+
+ if (args.This()->InternalFieldCount() == 0)
+ return v8::ThrowException(
+ v8::Exception::TypeError(v8::String::New("Cannot Instantiate without new")));
+
+ VideoWriterWrap *v;
+ std::string filename;
+ int codec = CV_FOURCC('M','J','P','G'); // Default mjpg
+ double fps = 24.0;
+ cv::Size framesize = cv::Size(640, 320);
+ //bool isColor; // TODO
+
+ filename = std::string(*v8::String::AsciiValue(args[0]->ToString()));
+
+
+
+ v = new VideoWriterWrap(filename, codec, fps, framesize);
+ v->Wrap(args.This());
+
+ return args.This();
+}
+
+
+
+VideoWriterWrap::VideoWriterWrap(const std::string& filename, int codec,
+ double fps, cv::Size framesize){
+
+ writer = cv::VideoWriter(filename, codec, fps, framesize);
+
+
+ if (!writer.isOpened()){
+ std::cout << "VideoWriter: Could not be opened!"
+ }
+
+}
+
+
+Handle<Value>
+VideoWriterWrap::Write(const Arguments &args) {
+ SETUP_FUNCTION(VideoWriterWrap)
+
+ Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
+
+ self->writer << im->mat;
+
+ return scope.Close(v8::Undefined());
+}
+
View
@@ -0,0 +1,15 @@
+#include "OpenCV.h"
+
+class VideoWriterWrap: public node::ObjectWrap {
+ public:
+ cv::VideoWriter writer;
+
+ static Persistent<FunctionTemplate> constructor;
+ static void Init(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+
+ VideoWriterWrap(const std::string& filename, int codec,
+ double fps, cv::Size framesize);
+
+ static Handle<Value> Write(const v8::Arguments&);
+};
View
@@ -3,6 +3,7 @@
#include "Matrix.h"
#include "CascadeClassifierWrap.h"
#include "VideoCaptureWrap.h"
+#include "VideoWriter.h"
#include "Contours.h"
#include "CamShift.h"
#include "HighGUI.h"
@@ -16,6 +17,7 @@ init(Handle<Object> target) {
Matrix::Init(target);
CascadeClassifierWrap::Init(target);
VideoCaptureWrap::Init(target);
+ VideoWriterWrap::Init(target);
Contour::Init(target);
TrackedObject::Init(target);

1 comment on commit 1322e58

tc commented on 1322e58 Apr 11, 2014

Hi, what is the status of this branch? If there is a list of TODOs, i'll be happy to contribute.

Please sign in to comment.