Wildhoney / ngVideo

Modularised ~13KB HTML5 audio/video implementation using Angular.js
http://ng-video.herokuapp.com/
MIT License
227 stars 57 forks source link

Playback rate = 1/fps possible? Callback for each frame? #13

Closed farazhassan closed 10 years ago

farazhassan commented 10 years ago

I'm using a playback rate of say 0.033 which is 1/30 so that I can view the video frame by frame. Now I have two problems:

1) I'm not sure its actually playing it at that rate. 2) Is there any way I can extend the directive to get a callback every time the frame is changed? I need to do some drawing based on the frame number.

farazhassan commented 10 years ago

I've been reading the code, from what I understand, the drawing should work with the currentTime variable of the feedback directive. Use the currentTime variable to approximate the frame number and then draw accordingly, but that'd be an estimation, not an exact thing. Before ngVideo I was manually playing the video frame by frame, and was able to draw on the exact frame. Any pointers?

farazhassan commented 10 years ago

Not sure if this is the right way to do it, since theres some delay in the feedback directive updates. Heres what I did. Made a feedback directive, enclosed my drawing controller inside it and set up a watch for the currentTime variable and each time a value is received, I draw a frame. Works fine when the playbackRate is very low and as you increase the playbackRate, the performance deteriorates understandably.

Wildhoney commented 10 years ago

That seems like a good idea! Could you post some code please?

farazhassan commented 10 years ago

Sure.

HTML:

`

      </section>

`

JS:

  var app = angular.module('ingrainStudioApp');

  app.controller('DrawingController', ['$scope', '$window', '$element', 'MetadataService', '$rootScope',   function($scope, $element, metadataService, $rootScope){
      $scope.$watch("currentTime", function(){
        if($scope.playing){
          $scope.drawFrame($scope.currentTime * 30); 
        }
      });
    }]);
  })();

Sorry for the formatting, not sure how to paste it here.

Edit: The html wont even show. MUST check how to paste code here.

Edit: Getting a hold of it now. Will fix the format.

Wildhoney commented 10 years ago

Thanks! :thumbsup: That seems like a good solution.