From 17f59cee5f350652b5ab5309f7a4ee15133353d0 Mon Sep 17 00:00:00 2001 From: John Ludwig Date: Thu, 19 Jun 2014 12:10:12 -0700 Subject: [PATCH] Add SetPosition method Allows video read stream to advance to a particular frame --- src/VideoCaptureWrap.cc | 17 +++++++++++++++++ src/VideoCaptureWrap.h | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/VideoCaptureWrap.cc b/src/VideoCaptureWrap.cc index a23d6b3..fb8a796 100755 --- a/src/VideoCaptureWrap.cc +++ b/src/VideoCaptureWrap.cc @@ -36,6 +36,7 @@ VideoCaptureWrap::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor, "read", Read); NODE_SET_PROTOTYPE_METHOD(constructor, "setWidth", SetWidth); NODE_SET_PROTOTYPE_METHOD(constructor, "setHeight", SetHeight); + NODE_SET_PROTOTYPE_METHOD(constructor, "setPosition", SetPosition); target->Set(String::NewSymbol("VideoCapture"), constructor->GetFunction()); }; @@ -115,6 +116,22 @@ VideoCaptureWrap::SetHeight(const Arguments &args){ return Undefined(); } +Handle +VideoCaptureWrap::SetPosition(const Arguments &args){ + + HandleScope scope; + VideoCaptureWrap *v = ObjectWrap::Unwrap(args.This()); + + if(args.Length() != 1) + return scope.Close(Undefined()); + + int pos = args[0]->IntegerValue(); + + v->cap.set(CV_CAP_PROP_POS_FRAMES, pos); + + return Undefined(); +} + Handle VideoCaptureWrap::Read(const Arguments &args) { diff --git a/src/VideoCaptureWrap.h b/src/VideoCaptureWrap.h index 5d5f96c..b239273 100755 --- a/src/VideoCaptureWrap.h +++ b/src/VideoCaptureWrap.h @@ -14,8 +14,11 @@ class VideoCaptureWrap: public node::ObjectWrap { static Handle Read(const v8::Arguments&); //(Optional) For setting width and height of the input video stream - static Handle SetWidth(const v8::Arguments&); - static Handle SetHeight(const v8::Arguments&); + static Handle SetWidth(const v8::Arguments&); + static Handle SetHeight(const v8::Arguments&); + + // to set frame position + static Handle SetPosition(const v8::Arguments&); static Handle GetFrameAt(const v8::Arguments&);