From f800a09297e200e481a7bc51eb1b61ba19531566 Mon Sep 17 00:00:00 2001 From: Jakob Schindegger Date: Sun, 10 Sep 2017 17:23:24 +0200 Subject: [PATCH 1/5] Adding GetPosition, GetPositionMS, GetFPS, GetFourCC and renaming GetFrameAt to SetPositionMS --- src/VideoCaptureWrap.cc | 44 +++++++++++++++++++++++++++++++++++++++-- src/VideoCaptureWrap.h | 18 +++++++++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/VideoCaptureWrap.cc b/src/VideoCaptureWrap.cc index b4e4634c..476e54a9 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, "getFPS", GetFPS); + Nan::SetPrototypeMethod(ctor, "getFourCC", GetFourCC); Nan::SetPrototypeMethod(ctor, "getFrameCount", GetFrameCount); Nan::SetPrototypeMethod(ctor, "release", Release); Nan::SetPrototypeMethod(ctor, "ReadSync", ReadSync); @@ -43,6 +47,42 @@ 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::GetFPS) { + Nan::HandleScope scope; + VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); + + int cnt = int(v->cap.get(CV_CAP_PROP_FPS)); + + 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; @@ -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(info.This()); diff --git a/src/VideoCaptureWrap.h b/src/VideoCaptureWrap.h index 55a73f67..52be30f2 100755 --- a/src/VideoCaptureWrap.h +++ b/src/VideoCaptureWrap.h @@ -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); From 215cf906ac80f8d84eaf430ba63a2832f58ddc00 Mon Sep 17 00:00:00 2001 From: Jakob Schindegger Date: Tue, 12 Sep 2017 17:16:38 +0200 Subject: [PATCH 2/5] changing comment --- src/VideoCaptureWrap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VideoCaptureWrap.h b/src/VideoCaptureWrap.h index 52be30f2..f1443510 100755 --- a/src/VideoCaptureWrap.h +++ b/src/VideoCaptureWrap.h @@ -31,7 +31,7 @@ class VideoCaptureWrap: public Nan::ObjectWrap { // to set frame position in milliseconds static NAN_METHOD(SetPositionMS); - // to get frame position + // to get 0-based index of the frame to be decoded/captured next static NAN_METHOD(GetPosition); // to get frame position in milliseconds From 892e29f4f47124a71fe9508f8f6991e7445aa3ee Mon Sep 17 00:00:00 2001 From: Jakob Schindegger Date: Sun, 15 Oct 2017 16:40:20 +0200 Subject: [PATCH 3/5] Added GetFrameAt back in --- src/VideoCaptureWrap.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/VideoCaptureWrap.cc b/src/VideoCaptureWrap.cc index 476e54a9..cb7e5156 100755 --- a/src/VideoCaptureWrap.cc +++ b/src/VideoCaptureWrap.cc @@ -35,6 +35,7 @@ void VideoCaptureWrap::Init(Local target) { 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); @@ -191,6 +192,20 @@ NAN_METHOD(VideoCaptureWrap::SetPosition) { return; } +NAN_METHOD(VideoCaptureWrap::GetFrameAt) { + 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::SetPositionMS) { Nan::HandleScope scope; VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); From 4fdedbf3bc3719ad402092183317119a4a421498 Mon Sep 17 00:00:00 2001 From: Jakob Schindegger Date: Sun, 15 Oct 2017 16:43:20 +0200 Subject: [PATCH 4/5] added comment and getframe at in .h file --- src/VideoCaptureWrap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/VideoCaptureWrap.h b/src/VideoCaptureWrap.h index f1443510..79eab435 100755 --- a/src/VideoCaptureWrap.h +++ b/src/VideoCaptureWrap.h @@ -30,6 +30,7 @@ class VideoCaptureWrap: public Nan::ObjectWrap { // 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); From 6855c818f550a4905c2badb9eb2912865665cf07 Mon Sep 17 00:00:00 2001 From: Jakob Schindegger Date: Mon, 30 Oct 2017 19:32:06 +0100 Subject: [PATCH 5/5] removed duplicate method - getFPS --- src/VideoCaptureWrap.cc | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/VideoCaptureWrap.cc b/src/VideoCaptureWrap.cc index fd419113..1e10b31f 100755 --- a/src/VideoCaptureWrap.cc +++ b/src/VideoCaptureWrap.cc @@ -37,7 +37,6 @@ void VideoCaptureWrap::Init(Local target) { 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, "getFPS", GetFPS); @@ -67,15 +66,6 @@ NAN_METHOD(VideoCaptureWrap::GetPositionMS) { info.GetReturnValue().Set(Nan::New(cnt)); } -NAN_METHOD(VideoCaptureWrap::GetFPS) { - Nan::HandleScope scope; - VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); - - int cnt = int(v->cap.get(CV_CAP_PROP_FPS)); - - info.GetReturnValue().Set(Nan::New(cnt)); -} - NAN_METHOD(VideoCaptureWrap::GetFourCC) { Nan::HandleScope scope; VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap(info.This()); @@ -163,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)); }