Hi Charlie,
I want to take a snapshot from a FLV-File which was recorded some time ago.
Therefore I don’t have a IMediaStream Object at the
time I want to create the snapshot.
My first step is to “load” the file via:
BufferedInputStream is = new BufferedInputStream(new FileInputStream(snapshot.getFlvFile()));
Then I search the AMFPacket at the given timecode by:
FLVUtils.readHeader(is);
AMFPacket amfPacket;
while ((amfPacket = FLVUtils.readChunk(is)) != null)
{
if (lastVideoKeyFrame != null && amfPacket.getTimecode() > timecodeInMillis)
break;
if (amfPacket.getType() != IVHost.CONTENTTYPE_VIDEO)
continue;
if (FLVUtils.getFrameType(amfPacket.getFirstByte()) == FLVUtils.FLV_KFRAME)
lastVideoKeyFrame = amfPacket;
}
is.close();
In a last step I write this packet (lastVideoKeyFrame) to a new flv-File.
The code for this step is:
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(snapshot.getFlvSnapshotFile(), false));
FLVUtils.writeHeader(out, 0, null);
//FLVUtils.writeChunk(out, lastVideoKeyFrame.getDataBuffer(), lastVideoKeyFrame.getSize(), 0, (byte)lastVideoKeyFrame.getType());
AMFPacket codecConfig = [COLOR="Red"]stream[/COLOR].getVideoCodecConfigPacket(packet.getAbsTimecode());
if (codecConfig != null){
FLVUtils.writeChunk(out, codecConfig.getDataBuffer(), codecConfig.getSize(), 0, (byte)codecConfig.getType());
}
FLVUtils.writeChunk(out, lastVideoKeyFrame.getDataBuffer(), lastVideoKeyFrame.getSize(), 0, (byte)lastVideoKeyFrame.getType());
out.close();
Regards,
Markus