Skip to content

Commit

Permalink
VideoWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbraden committed Mar 6, 2013
1 parent daca1a1 commit 1322e58
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
1 change: 1 addition & 0 deletions binding.gyp
Expand Up @@ -9,6 +9,7 @@
, "src/Contours.cc" , "src/Contours.cc"
, "src/Point.cc" , "src/Point.cc"
, "src/VideoCaptureWrap.cc" , "src/VideoCaptureWrap.cc"
, "src/VideoWriter.cc"
, "src/CamShift.cc" , "src/CamShift.cc"
, "src/HighGUI.cc" , "src/HighGUI.cc"
] ]
Expand Down
12 changes: 8 additions & 4 deletions lib/opencv.js
Expand Up @@ -129,10 +129,14 @@ videostream.read = function(){


var frame = function(){ var frame = function(){
self.video.read(function(mat){ self.video.read(function(mat){
self.emit('data', mat) if (mat.width() && mat.height()){
if (!this.paused){ self.emit('data', mat)
process.nextTick(frame) if (!this.paused){
} process.nextTick(frame)
}
} else {
self.emit('end')
}


}) })
} }
Expand Down
77 changes: 77 additions & 0 deletions src/VideoWriter.cc
@@ -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());
}

15 changes: 15 additions & 0 deletions src/VideoWriter.h
@@ -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&);
};
2 changes: 2 additions & 0 deletions src/init.cc
Expand Up @@ -3,6 +3,7 @@
#include "Matrix.h" #include "Matrix.h"
#include "CascadeClassifierWrap.h" #include "CascadeClassifierWrap.h"
#include "VideoCaptureWrap.h" #include "VideoCaptureWrap.h"
#include "VideoWriter.h"
#include "Contours.h" #include "Contours.h"
#include "CamShift.h" #include "CamShift.h"
#include "HighGUI.h" #include "HighGUI.h"
Expand All @@ -16,6 +17,7 @@ init(Handle<Object> target) {
Matrix::Init(target); Matrix::Init(target);
CascadeClassifierWrap::Init(target); CascadeClassifierWrap::Init(target);
VideoCaptureWrap::Init(target); VideoCaptureWrap::Init(target);
VideoWriterWrap::Init(target);
Contour::Init(target); Contour::Init(target);
TrackedObject::Init(target); TrackedObject::Init(target);


Expand Down

1 comment on commit 1322e58

@tc
Copy link

@tc tc commented on 1322e58 Apr 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.