Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding GetPosition, GetPositionMS, GetFPS, GetFourCC and renaming Get…
…FrameAt to SetPositionMS
  • Loading branch information
fakob committed Sep 10, 2017
commit f800a09297e200e481a7bc51eb1b61ba19531566
44 changes: 42 additions & 2 deletions src/VideoCaptureWrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ void VideoCaptureWrap::Init(Local<Object> target) {
Nan::SetPrototypeMethod(ctor, "setHeight", SetHeight);
Nan::SetPrototypeMethod(ctor, "getWidth", GetWidth);
Nan::SetPrototypeMethod(ctor, "getHeight", GetHeight);
Nan::SetPrototypeMethod(ctor, "getPosition", GetPosition);
Nan::SetPrototypeMethod(ctor, "getPositionMS", GetPositionMS);
Nan::SetPrototypeMethod(ctor, "setPosition", SetPosition);
Nan::SetPrototypeMethod(ctor, "getFrameAt", GetFrameAt);
Nan::SetPrototypeMethod(ctor, "setPositionMS", SetPositionMS);
Nan::SetPrototypeMethod(ctor, "getFPS", GetFPS);
Nan::SetPrototypeMethod(ctor, "getFourCC", GetFourCC);
Nan::SetPrototypeMethod(ctor, "getFrameCount", GetFrameCount);
Nan::SetPrototypeMethod(ctor, "release", Release);
Nan::SetPrototypeMethod(ctor, "ReadSync", ReadSync);
Expand All @@ -43,6 +47,42 @@ void VideoCaptureWrap::Init(Local<Object> target) {
target->Set(Nan::New("VideoCapture").ToLocalChecked(), ctor->GetFunction());
}

NAN_METHOD(VideoCaptureWrap::GetPosition) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

int cnt = int(v->cap.get(CV_CAP_PROP_POS_FRAMES));

info.GetReturnValue().Set(Nan::New<Number>(cnt));
}

NAN_METHOD(VideoCaptureWrap::GetPositionMS) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

int cnt = int(v->cap.get(CV_CAP_PROP_POS_MSEC));

info.GetReturnValue().Set(Nan::New<Number>(cnt));
}

NAN_METHOD(VideoCaptureWrap::GetFPS) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

int cnt = int(v->cap.get(CV_CAP_PROP_FPS));

info.GetReturnValue().Set(Nan::New<Number>(cnt));
}

NAN_METHOD(VideoCaptureWrap::GetFourCC) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

int cnt = int(v->cap.get(CV_CAP_PROP_FOURCC));

info.GetReturnValue().Set(Nan::New<Number>(cnt));
}

NAN_METHOD(VideoCaptureWrap::New) {
Nan::HandleScope scope;

Expand Down Expand Up @@ -151,7 +191,7 @@ NAN_METHOD(VideoCaptureWrap::SetPosition) {
return;
}

NAN_METHOD(VideoCaptureWrap::GetFrameAt) {
NAN_METHOD(VideoCaptureWrap::SetPositionMS) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

Expand Down
18 changes: 16 additions & 2 deletions src/VideoCaptureWrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ class VideoCaptureWrap: public Nan::ObjectWrap {

// to set frame position
static NAN_METHOD(SetPosition);
static NAN_METHOD(GetFrameCount);

static NAN_METHOD(GetFrameAt);
// to set frame position in milliseconds
static NAN_METHOD(SetPositionMS);

// to get frame position
static NAN_METHOD(GetPosition);

// to get frame position in milliseconds
static NAN_METHOD(GetPositionMS);

// to get frame rate
static NAN_METHOD(GetFPS);

// to get 4-character code of codec
static NAN_METHOD(GetFourCC);

static NAN_METHOD(GetFrameCount);

// release the stream
static NAN_METHOD(Release);
Expand Down