Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed-up sample extraction #90

Closed
GoogleCodeExporter opened this issue Jul 12, 2015 · 2 comments
Closed

Speed-up sample extraction #90

GoogleCodeExporter opened this issue Jul 12, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

I'll close the ticket - it should much faster than before now.

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

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant