|
|
@@ -361,6 +361,31 @@ jsmpeg.prototype.fillArray = function(a, value) {
|
|
361
|
361
|
}
|
|
362
|
362
|
};
|
|
363
|
363
|
|
|
|
364
|
+jsmpeg.prototype.cachedFrameCount = 0;
|
|
|
365
|
+jsmpeg.prototype.calculateFrameCount = function() {
|
|
|
366
|
+ if( !this.buffer || this.cachedFrameCount ) {
|
|
|
367
|
+ return this.cachedFrameCount;
|
|
|
368
|
+ }
|
|
|
369
|
+
|
|
|
370
|
+ // Remember the buffer position, so we can rewind to the beginning and
|
|
|
371
|
+ // reset to the current position afterwards
|
|
|
372
|
+ var currentPlaybackIndex = this.buffer.index,
|
|
|
373
|
+ frames = 0;
|
|
|
374
|
+
|
|
|
375
|
+ this.buffer.index = 0;
|
|
|
376
|
+ while( this.findStartCode(START_PICTURE) !== BitReader.NOT_FOUND ) {
|
|
|
377
|
+ frames++;
|
|
|
378
|
+ }
|
|
|
379
|
+ this.buffer.index = currentPlaybackIndex;
|
|
|
380
|
+
|
|
|
381
|
+ this.cachedFrameCount = frames;
|
|
|
382
|
+ return frames;
|
|
|
383
|
+};
|
|
|
384
|
+
|
|
|
385
|
+jsmpeg.prototype.calculateDuration = function() {
|
|
|
386
|
+ return this.calculateFrameCount() * (1/this.pictureRate);
|
|
|
387
|
+};
|
|
|
388
|
+
|
|
364
|
389
|
|
|
365
|
390
|
|
|
366
|
391
|
// ----------------------------------------------------------------------------
|