Ratnesh-K / mp4parser

Automatically exported from code.google.com/p/mp4parser
0 stars 0 forks source link

Speed-up sample extraction #90

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
From ca3c0fa9d7bba2ffef24277236a8e49993877aa1 Mon Sep 17 00:00:00 2001
Date: Tue, 3 Jun 2014 11:57:18 +0400
Subject: [PATCH] Add sample offsets cache

This dramatically speeds up building new MP4 file

---
 .../mp4parser/authoring/samples/DefaultMp4SampleList.java         | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git 
a/isoparser/src/main/java/com/googlecode/mp4parser/authoring/samples/DefaultMp4S
ampleList.java 
b/isoparser/src/main/java/com/googlecode/mp4parser/authoring/samples/DefaultMp4S
ampleList.java
index 72b8880..0b60692 100644
--- 
a/isoparser/src/main/java/com/googlecode/mp4parser/authoring/samples/DefaultMp4S
ampleList.java
+++ 
b/isoparser/src/main/java/com/googlecode/mp4parser/authoring/samples/DefaultMp4S
ampleList.java
@@ -20,6 +20,7 @@ public class DefaultMp4SampleList extends 
AbstractList<Sample> {
     SoftReference<Sample>[] cache = null;
     int[] chunkNumsStartSampleNum;
     long[] chunkOffsets;
+    long[] sampleOffsets;
     SampleSizeBox ssb;

     public DefaultMp4SampleList(long track, Container topLevel) {
@@ -97,6 +98,7 @@ public class DefaultMp4SampleList extends 
AbstractList<Sample> {
         } while ((currentSampleNo += currentSamplePerChunk) <= lastSampleNo);
         chunkNumsStartSampleNum[currentChunkNo] = Integer.MAX_VALUE;

+        sampleOffsets = new long[size()];
     }

@@ -144,7 +146,11 @@ public class DefaultMp4SampleList extends 
AbstractList<Sample> {
         long offset = chunkOffsets[l2i(currentChunkNoZeroBased)];

         while (currentSampleNo < index + 1) {
-            offset += ssb.getSampleSizeAtIndex((currentSampleNo++) - 1);
+            if (sampleOffsets[currentSampleNo] == 0) {
+                sampleOffsets[currentSampleNo] = 
ssb.getSampleSizeAtIndex(currentSampleNo - 1);
+            }
+            offset += sampleOffsets[currentSampleNo];
+            currentSampleNo++;
         }
         final long sampleSize = ssb.getSampleSizeAtIndex(currentSampleNo - 1);
         SampleImpl sampleImpl = new SampleImpl(offset, sampleSize, topLevel);
--
1.9.1

Original issue reported on code.google.com by andrey.c...@gmail.com on 3 Jun 2014 at 12:03

GoogleCodeExporter commented 8 years ago
Hi,
I just changed the code to not map sample by sample. I made it to map 
chunk-wise. It should be faster already. You might want to check the trunk and 
see if it's acceptable to you.

Original comment by Sebastian.Annies on 19 Jun 2014 at 3:23

GoogleCodeExporter commented 8 years ago
I'll close the ticket - it should much faster than before now.

Original comment by Sebastian.Annies on 22 Jul 2014 at 6:58