Fix alignment in track scanner

This commit is contained in:
Dustin 2022-01-23 12:10:48 -07:00
parent ec26539aeb
commit 167c2f3fc0
2 changed files with 11 additions and 7 deletions

View File

@ -84,6 +84,14 @@ public class AviExtractor implements Extractor {
//If partial read //If partial read
private transient AviTrack chunkHandler; private transient AviTrack chunkHandler;
static void alignInput(ExtractorInput input) throws IOException {
// This isn't documented anywhere, but most files are aligned to even bytes
// and can have gaps of zeros
if ((input.getPosition() & 1) == 1) {
input.skipFully(1);
}
}
public AviExtractor() { public AviExtractor() {
this(0); this(0);
} }
@ -406,11 +414,7 @@ public class AviExtractor implements Extractor {
} else { } else {
ByteBuffer byteBuffer = allocate(8); ByteBuffer byteBuffer = allocate(8);
final byte[] bytes = byteBuffer.array(); final byte[] bytes = byteBuffer.array();
// This isn't documented anywhere, but most files are aligned to even bytes alignInput(input);
// and can have gaps of zeros
if ((input.getPosition() & 1) == 1) {
input.skipFully(1);
}
input.readFully(bytes, 0, 1); input.readFully(bytes, 0, 1);
while (bytes[0] == 0) { while (bytes[0] == 0) {
input.readFully(bytes, 0, 1); input.readFully(bytes, 0, 1);

View File

@ -60,7 +60,7 @@ public class ListBox extends Box {
byte [] bytes = headerBuffer.array(); byte [] bytes = headerBuffer.array();
input.readFully(bytes, 0, 4); input.readFully(bytes, 0, 4);
final int listType = headerBuffer.getInt(); final int listType = headerBuffer.getInt();
//String listTypeName = AviExtractor.toString(listType);
long endPos = input.getPosition() + listSize - 4; long endPos = input.getPosition() + listSize - 4;
while (input.getPosition() + 8 < endPos) { while (input.getPosition() + 8 < endPos) {
headerBuffer.clear(); headerBuffer.clear();
@ -73,7 +73,7 @@ public class ListBox extends Box {
} else { } else {
box = boxFactory.createBox(type, size, input); box = boxFactory.createBox(type, size, input);
} }
AviExtractor.alignInput(input);
if (box != null) { if (box != null) {
list.add(box); list.add(box);
} }