|
|
@@ -268,6 +268,8 @@ jsmpeg.prototype.stopRecording = function() {
|
|
268
|
268
|
// Loading via Ajax
|
|
269
|
269
|
|
|
270
|
270
|
jsmpeg.prototype.intraFrames = [];
|
|
|
271
|
+jsmpeg.prototype.frameCount = 0;
|
|
|
272
|
+jsmpeg.prototype.duration = 0;
|
|
271
|
273
|
|
|
272
|
274
|
jsmpeg.prototype.load = function( url ) {
|
|
273
|
275
|
this.url = url;
|
|
|
@@ -320,6 +322,9 @@ jsmpeg.prototype.loadCallback = function(file) {
|
|
320
|
322
|
this.firstSequenceHeader = this.buffer.index;
|
|
321
|
323
|
this.decodeSequenceHeader();
|
|
322
|
324
|
|
|
|
325
|
+ // Calculate the duration. This only works if the video is seekable and we have a frame count.
|
|
|
326
|
+ this.duration = this.frameCount / this.pictureRate;
|
|
|
327
|
+
|
|
323
|
328
|
// Load the first frame
|
|
324
|
329
|
this.nextFrame();
|
|
325
|
330
|
|
|
|
@@ -334,7 +339,9 @@ jsmpeg.prototype.loadCallback = function(file) {
|
|
334
|
339
|
|
|
335
|
340
|
jsmpeg.prototype.collectIntraFrames = function() {
|
|
336
|
341
|
// Loop through the whole buffer and collect all intraFrames to build our seek index.
|
|
337
|
|
- for( var frame = 0; this.findStartCode(START_PICTURE) !== BitReader.NOT_FOUND; frame++ ) {
|
|
|
342
|
+ // We also keep track of total frame count here
|
|
|
343
|
+ var frame;
|
|
|
344
|
+ for( frame = 0; this.findStartCode(START_PICTURE) !== BitReader.NOT_FOUND; frame++ ) {
|
|
338
|
345
|
|
|
339
|
346
|
// Check if the found picture is an intra frame and remember the position
|
|
340
|
347
|
this.buffer.advance(10); // skip temporalReference
|
|
|
@@ -343,6 +350,8 @@ jsmpeg.prototype.collectIntraFrames = function() {
|
|
343
|
350
|
this.intraFrames.push({frame: frame, index: this.buffer.index - 13});
|
|
344
|
351
|
}
|
|
345
|
352
|
}
|
|
|
353
|
+
|
|
|
354
|
+ this.frameCount = frame;
|
|
346
|
355
|
};
|
|
347
|
356
|
|
|
348
|
357
|
jsmpeg.prototype.seekToFrame = function(seekFrame, seekExact) {
|
|
|
@@ -430,31 +439,6 @@ jsmpeg.prototype.fillArray = function(a, value) {
|
|
430
|
439
|
}
|
|
431
|
440
|
};
|
|
432
|
441
|
|
|
433
|
|
-jsmpeg.prototype.cachedFrameCount = 0;
|
|
434
|
|
-jsmpeg.prototype.calculateFrameCount = function() {
|
|
435
|
|
- if( !this.buffer || this.cachedFrameCount ) {
|
|
436
|
|
- return this.cachedFrameCount;
|
|
437
|
|
- }
|
|
438
|
|
-
|
|
439
|
|
- // Remember the buffer position, so we can rewind to the beginning and
|
|
440
|
|
- // reset to the current position afterwards
|
|
441
|
|
- var currentPlaybackIndex = this.buffer.index,
|
|
442
|
|
- frames = 0;
|
|
443
|
|
-
|
|
444
|
|
- this.buffer.index = 0;
|
|
445
|
|
- while( this.findStartCode(START_PICTURE) !== BitReader.NOT_FOUND ) {
|
|
446
|
|
- frames++;
|
|
447
|
|
- }
|
|
448
|
|
- this.buffer.index = currentPlaybackIndex;
|
|
449
|
|
-
|
|
450
|
|
- this.cachedFrameCount = frames;
|
|
451
|
|
- return frames;
|
|
452
|
|
-};
|
|
453
|
|
-
|
|
454
|
|
-jsmpeg.prototype.calculateDuration = function() {
|
|
455
|
|
- return this.calculateFrameCount() * (1/this.pictureRate);
|
|
456
|
|
-};
|
|
457
|
|
-
|
|
458
|
442
|
|
|
459
|
443
|
|
|
460
|
444
|
// ----------------------------------------------------------------------------
|