我有两个 RIFF 文件,我正在将块从一个文件复制到另一个文件。我使用的 RIFF 格式是:
- 4 字节 ASCII 标识符
- 4 字节整数帧块长度(以字节为单位)
- 数据(给定长度)
我使用以下代码从源文件复制到目标文件。块被称为帧。
public void CopySegmentTo(VPCaptureSession captureSession, int StartFrame, int EndFrame) {
//captures several frames from this session onto the end of another one.
//binary-styles
Console.WriteLine(" captureSession.captureStream.Position: " + captureSession.captureStream.Position);
long lastCaptureDestPosition = 0;
captureSession.captureStream.Seek(0, SeekOrigin.End);
int chunkLength; long timestamp; char[] charTag;
for (int f = StartFrame; f <= EndFrame; f++)
{
Console.WriteLine("-----");
this.captureStream.Seek(FrameTimes.ElementAt(f).Item3, SeekOrigin.Begin);
Console.WriteLine("FrameIndex in this.captureStream: " + FrameTimes.ElementAt(f).Item3);
BinaryReader reader = new BinaryReader(this.captureStream);
byte[] tag = reader.ReadBytes(Tags.TAG_SIZE);
charTag = TagChunk.encode.GetChars(tag);
chunkLength = reader.ReadInt32();
BinaryWriter writer = new BinaryWriter(captureSession.captureStream);
writer.Write(tag);
writer.Write(chunkLength);
this.captureStream.CopyTo(captureSession.captureStream, chunkLength);
long CaptureDestDelta = captureSession.captureStream.Position - lastCaptureDestPosition;
Console.WriteLine("Loading " + f + " between " + StartFrame + "&" + EndFrame
+ ". chunkLength: " + chunkLength
+ " this.captureStream.Position: " + this.captureStream.Position
+ " captureSession.captureStream.Position: " + captureSession.captureStream.Position
+ " CaptureDestDelta: " + CaptureDestDelta
+ " Delta Factor: " + CaptureDestDelta/chunkLength);
lastCaptureDestPosition = captureSession.captureStream.Position;
}
}
复制速度很慢,生成的文件似乎很大。以下是Console
输出示例:
captureSession.captureStream.Position: 0
-----
FrameIndex in this.captureStream: 0
Loading 0 between 0&5. chunkLength: 266736 this.captureStream.Position: 121225207
captureSession.captureStream.Position: 121225207 CaptureDestDelta: 121225207
Delta Factor: 454
-----
FrameIndex in this.captureStream: 266744
Loading 1 between 0&5. chunkLength: 311398 this.captureStream.Position: 121225207
captureSession.captureStream.Position: 242183670 CaptureDestDelta: 120958463
Delta Factor: 388
-----
FrameIndex in this.captureStream: 578150
Loading 2 between 0&5. chunkLength: 356578 this.captureStream.Position: 121225207
captureSession.captureStream.Position: 362830727 CaptureDestDelta: 120647057
Delta Factor: 338
-----
FrameIndex in this.captureStream: 934736
Loading 3 between 0&5. chunkLength: 430445 this.captureStream.Position: 121225207
captureSession.captureStream.Position: 483121198 CaptureDestDelta: 120290471
Delta Factor: 279
-----
FrameIndex in this.captureStream: 1365189
Loading 4 between 0&5. chunkLength: 437468 this.captureStream.Position: 121225207
captureSession.captureStream.Position: 602981216 CaptureDestDelta: 119860018
Delta Factor: 273
-----
FrameIndex in this.captureStream: 1802665
Loading 5 between 0&5. chunkLength: 439870 this.captureStream.Position: 121225207
captureSession.captureStream.Position: 722403758 CaptureDestDelta: 119422542
Delta Factor: 271
肯定发生了一些奇怪的事情。这是我看到的主要内容:
captureSession.captureStream.Position
chunkLength
比每次都进步很多。this.captureStream.Position
每次复制后似乎总是一样的。
让我知道是否还有更多我可以记录的内容。我真的被困在这里了。