| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata.mov.atoms; |
| 22 |
|
| 23 |
import com.drew.lang.SequentialReader; |
| 24 |
import com.drew.metadata.mov.QuickTimeContext; |
| 25 |
import com.drew.metadata.mov.media.QuickTimeVideoDirectory; |
| 26 |
|
| 27 |
import java.io.IOException; |
| 28 |
import java.util.ArrayList; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class TimeToSampleAtom extends FullAtom |
| 36 |
{ |
| 37 |
private final ArrayList<Entry> entries; |
| 38 |
|
| 39 |
public TimeToSampleAtom(SequentialReader reader, Atom atom) throws IOException |
| 40 |
{ |
| 41 |
super(reader, atom); |
| 42 |
|
| 43 |
long numberOfEntries = reader.getUInt32(); |
| 44 |
if (numberOfEntries < Integer.MAX_VALUE) { |
| 45 |
entries = new ArrayList<Entry>((int)numberOfEntries); |
| 46 |
for (int i = 0; i < numberOfEntries; i++) { |
| 47 |
entries.add(new Entry(reader)); |
| 48 |
} |
| 49 |
} else { |
| 50 |
entries = new ArrayList<Entry>(); |
| 51 |
|
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
static class Entry |
| 56 |
{ |
| 57 |
long sampleCount; |
| 58 |
long sampleDuration; |
| 59 |
|
| 60 |
public Entry(SequentialReader reader) throws IOException |
| 61 |
{ |
| 62 |
sampleCount = reader.getUInt32(); |
| 63 |
sampleDuration = reader.getUInt32(); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public void addMetadata(QuickTimeVideoDirectory directory, QuickTimeContext context) |
| 68 |
{ |
| 69 |
if (context.timeScale != null && entries.size() > 0) { |
| 70 |
float frameRate = (float)context.timeScale / (float)entries.get(0).sampleDuration; |
| 71 |
directory.setFloat(QuickTimeVideoDirectory.TAG_FRAME_RATE, frameRate); |
| 72 |
} |
| 73 |
} |
| 74 |
} |