Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- type
- TGameRecorder = record
- Timer: TMMLTimer;
- Path: String;
- FPS, Duration: Int32;
- Frames: array of TMufasaBitmap;
- CanFree: Boolean;
- end;
- var
- GameRecorder: TGameRecorder;
- procedure TGameRecorder.Capture(Junk, Sender: Pointer); static;
- var
- i,W,H, FrameCount: Int32;
- Proc: TProcess;
- begin
- GameRecorder.CanFree := False;
- FrameCount := Length(GameRecorder.Frames);
- if FrameCount * (1000 div GameRecorder.FPS) >= GameRecorder.Duration then
- begin
- for i:=0 to FrameCount-1 do
- begin
- GameRecorder.Frames[i].SaveToFile(Format('%s/tmp/img%d.jpg', [GameRecorder.Path, i+1]));
- GameRecorder.Frames[i].Free();
- end;
- SetLength(GameRecorder.Frames, 0);
- client.WriteLn('Generating video...');
- Proc.Init(nil);
- Proc.SetExecutable('ffmpeg -vtag xvid -framerate ' + ToStr(GameRecorder.FPS) + ' -i "'+GameRecorder.Path+'/tmp/img%01d.jpg" "'+GameRecorder.Path+'/'+FormatDateTime('dd.mm.yy hh.nn.ss',Now())+'.avi"');
- Proc.SetOptions(Proc.GetOptions + [poWaitOnExit]);
- Proc.Execute();
- Proc.Free();
- end else
- begin
- SetLength(GameRecorder.Frames, FrameCount+1);
- Client.GetIOManager.GetDimensions(W,H);
- GameRecorder.Frames[FrameCount].Init(client.GetMBitmaps);
- if W mod 2 = 1 then Dec(W);
- if H mod 2 = 1 then Dec(H);
- GameRecorder.Frames[FrameCount].CopyClientToBitmap(client.GetIOManager, True, 0,0, W-1, H-1);
- end;
- GameRecorder.CanFree := True;
- end;
- procedure TGameRecorder.Init(ClipPath: String; ClipFPS, ClipDuration: Int32);
- begin
- Self.Path := ClipPath;
- Self.FPS := ClipFPS;
- Self.Duration := ClipDuration;
- CreateDirectory(Self.Path+'/');
- CreateDirectory(Self.Path+'/tmp/');
- Self.Timer.Init();
- Self.Timer.SetInterval(1000 div Self.FPS);
- Self.Timer.SetOnTimer(natify(@TGameRecorder.Capture));
- end;
- procedure TGameRecorder.Start();
- begin
- Self.Timer.SetEnabled(True);
- end;
- procedure TGameRecorder.Stop();
- begin
- Self.Timer.SetEnabled(False);
- end;
- procedure TGameRecorder.Free();
- var i: Int32;
- begin
- Self.Timer.SetEnabled(False);
- while not Self.CanFree do Wait(5);
- Self.Timer.Free();
- for i:=0 to High(self.Frames) do Self.Frames[i].Free();
- SetLength(Self.Frames, 0);
- end;
- begin
- GameRecorder.Init('C:/Simba/Videos', 10, 15*1000);
- GameRecorder.Start();
- Wait(17*1000);
- GameRecorder.Stop();
- GameRecorder.Free();
- end.
Add Comment
Please, Sign In to add comment