Even more bugfixing in metadata write.
This commit is contained in:
parent
a58b074873
commit
da61095fb3
4 changed files with 45 additions and 7 deletions
|
|
@ -50,8 +50,8 @@ public class FlvFilter extends OutputStream {
|
||||||
|
|
||||||
public FlvFilter(FlvReceiver receiver, FlvMetadata metadata) {
|
public FlvFilter(FlvReceiver receiver, FlvMetadata metadata) {
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.metadata = new FlvMetadata();
|
this.metadata = metadata;
|
||||||
this.extraMetadata = metadata;
|
this.extraMetadata = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -198,7 +198,7 @@ public class FlvFilter extends OutputStream {
|
||||||
out.write(fileHeader);
|
out.write(fileHeader);
|
||||||
metadata.setFileSize(fileHeader.length + metadataLength + bodyLen);
|
metadata.setFileSize(fileHeader.length + metadataLength + bodyLen);
|
||||||
metadata.setFileOffsetDelta(metadataLength - incomingMetadataLength);
|
metadata.setFileOffsetDelta(metadataLength - incomingMetadataLength);
|
||||||
metadata.writeOnMetadata(out);
|
metadata.writeOnMetadata(out, metadataLength);
|
||||||
|
|
||||||
receiver.writeHeader(out.toByteArray());
|
receiver.writeHeader(out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@ public class FlvMetadata {
|
||||||
|
|
||||||
public int calculateLength() throws IOException {
|
public int calculateLength() throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
writeOnMetadata(baos);
|
writeOnMetadata(baos, 0);
|
||||||
return baos.size();
|
return baos.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,7 +253,11 @@ public class FlvMetadata {
|
||||||
this.filePositionDelta = fileOffsetDelta;
|
this.filePositionDelta = fileOffsetDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeOnMetadata(OutputStream out) throws IOException {
|
public void writeOnMetadata(OutputStream out, int size) throws IOException {
|
||||||
|
|
||||||
|
out.write(18); // Script data tag
|
||||||
|
writeUint24(out, size - 15); //data size
|
||||||
|
writeUint32(out, 0); // timestamp
|
||||||
|
|
||||||
// ScriptDataObject
|
// ScriptDataObject
|
||||||
out.write(2);
|
out.write(2);
|
||||||
|
|
@ -347,6 +351,13 @@ public class FlvMetadata {
|
||||||
out.write((value >> 0) & 0xff);
|
out.write((value >> 0) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeUint24(OutputStream out, int value) throws IOException {
|
||||||
|
|
||||||
|
out.write((value >> 16) & 0xff);
|
||||||
|
out.write((value >> 8) & 0xff);
|
||||||
|
out.write((value >> 0) & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
void writeUint16(OutputStream out, int value) throws IOException {
|
void writeUint16(OutputStream out, int value) throws IOException {
|
||||||
|
|
||||||
out.write((value >> 8) & 0xff);
|
out.write((value >> 8) & 0xff);
|
||||||
|
|
@ -418,4 +429,20 @@ public class FlvMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setVideoCodecId(int videocodecid) {
|
||||||
|
this.videocodecid.set(Double.valueOf(videocodecid));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setAudioCodecId(int audioCodecId) {
|
||||||
|
this.audiocodecid.set(Double.valueOf(audioCodecId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setFramerate(double framerate) {
|
||||||
|
this.framerate.set(framerate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,9 @@ public class MovieCoder {
|
||||||
this.dbKey = key(file, targetSize);
|
this.dbKey = key(file, targetSize);
|
||||||
FlvMetadata meta = new FlvMetadata();
|
FlvMetadata meta = new FlvMetadata();
|
||||||
meta.setDuration(thumbnail.getDuration());
|
meta.setDuration(thumbnail.getDuration());
|
||||||
|
meta.setVideoCodecId(2);
|
||||||
|
meta.setAudioCodecId(2);
|
||||||
|
meta.setFramerate(15); // TODO (knut 10 JUL 2011) Need to make sure the ffmpeg args match
|
||||||
this.filter = new FlvFilter(this, meta);
|
this.filter = new FlvFilter(this, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,7 +233,7 @@ public class MovieCoder {
|
||||||
endLastChunk();
|
endLastChunk();
|
||||||
// Generate header again to get updated metadata
|
// Generate header again to get updated metadata
|
||||||
// TODO (knut 09 JUL 2011) Figure out why the generated header doesn't work
|
// TODO (knut 09 JUL 2011) Figure out why the generated header doesn't work
|
||||||
// filter.generateHeader();
|
filter.generateHeader();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("uh?", e);
|
log.error("uh?", e);
|
||||||
movieDb.delete(dbKey);
|
movieDb.delete(dbKey);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,14 @@ public class FlvFilterTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFoo() {
|
public void testFoo() {
|
||||||
System.out.println(0x40128);
|
System.out.println(Double.longBitsToDouble(0x4062c00000000000L));
|
||||||
|
System.out.println(Double.longBitsToDouble(0x4125c59a00000000L));
|
||||||
|
System.out.println(Double.longBitsToDouble(0x411dcc0c00000000L));
|
||||||
|
System.out.println(Long.toHexString(Double.doubleToLongBits(150d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue