diff --git a/src/VideoCaptureWrap.cc b/src/VideoCaptureWrap.cc index 6b24d65d..1e10b31f 100755 --- a/src/VideoCaptureWrap.cc +++ b/src/VideoCaptureWrap.cc @@ -32,8 +32,12 @@ void VideoCaptureWrap::Init(Local 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, "getFourCC", GetFourCC); Nan::SetPrototypeMethod(ctor, "getFrameCount", GetFrameCount); Nan::SetPrototypeMethod(ctor, "getFPS", GetFPS); Nan::SetPrototypeMethod(ctor, "release", Release); @@ -44,6 +48,33 @@ void VideoCaptureWrap::Init(Local target) { target->Set(Nan::New("VideoCapture").ToLocalChecked(), ctor->GetFunction()); } +NAN_METHOD(VideoCaptureWrap::GetPosition) { + Nan::HandleScope scope; + VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); + + int cnt = int(v->cap.get(CV_CAP_PROP_POS_FRAMES)); + + info.GetReturnValue().Set(Nan::New(cnt)); +} + +NAN_METHOD(VideoCaptureWrap::GetPositionMS) { + Nan::HandleScope scope; + VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); + + int cnt = int(v->cap.get(CV_CAP_PROP_POS_MSEC)); + + info.GetReturnValue().Set(Nan::New(cnt)); +} + +NAN_METHOD(VideoCaptureWrap::GetFourCC) { + Nan::HandleScope scope; + VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); + + int cnt = int(v->cap.get(CV_CAP_PROP_FOURCC)); + + info.GetReturnValue().Set(Nan::New(cnt)); +} + NAN_METHOD(VideoCaptureWrap::New) { Nan::HandleScope scope; @@ -122,7 +153,7 @@ NAN_METHOD(VideoCaptureWrap::GetFPS) { int fps = int(v->cap.get(CV_CAP_PROP_FPS)); - info.GetReturnValue().Set(Nan::New(fps)); + info.GetReturnValue().Set(Nan::New(fps)); } @@ -177,6 +208,20 @@ NAN_METHOD(VideoCaptureWrap::GetFrameAt) { return; } +NAN_METHOD(VideoCaptureWrap::SetPositionMS) { + Nan::HandleScope scope; + VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); + + if(info.Length() != 1) + return; + + int pos = info[0]->IntegerValue(); + + v->cap.set(CV_CAP_PROP_POS_MSEC, pos); + + return; +} + NAN_METHOD(VideoCaptureWrap::Release) { Nan::HandleScope scope; VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); diff --git a/src/VideoCaptureWrap.h b/src/VideoCaptureWrap.h index a8a2dc2c..79eab435 100755 --- a/src/VideoCaptureWrap.h +++ b/src/VideoCaptureWrap.h @@ -27,11 +27,24 @@ class VideoCaptureWrap: public Nan::ObjectWrap { // to set frame position static NAN_METHOD(SetPosition); - static NAN_METHOD(GetFrameCount); + // to set frame position in milliseconds + static NAN_METHOD(SetPositionMS); + static NAN_METHOD(GetFrameAt); // would deprecate as naming is confusing + + // to get 0-based index of the frame to be decoded/captured next + static NAN_METHOD(GetPosition); + + // to get frame position in milliseconds + static NAN_METHOD(GetPositionMS); + + // to get frame rate static NAN_METHOD(GetFPS); - static NAN_METHOD(GetFrameAt); + // to get 4-character code of codec + static NAN_METHOD(GetFourCC); + + static NAN_METHOD(GetFrameCount); // release the stream static NAN_METHOD(Release);