hedgewars/uVideoRec.pas
author unc0rr
Wed, 29 May 2013 15:12:06 -0400
changeset 9080 9b42757d7e71
parent 8697 9624836094de
child 9203 bcc25cb9b122
permissions -rw-r--r--
bump copyright year for Andrey entries
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     1
(*
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9080
9b42757d7e71 bump copyright year for Andrey entries
unc0rr
parents: 8697
diff changeset
     3
 * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     4
 *
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     8
 *
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    13
 *
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    17
 *)
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    18
7286
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
    19
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    20
{$INCLUDE "options.inc"}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    21
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    22
unit uVideoRec;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    23
7286
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
    24
{$IFNDEF USE_VIDEO_RECORDING}
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
    25
interface
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
    26
implementation
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
    27
end.
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
    28
{$ELSE}
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
    29
7538
2d6e69b392cb better cmake script
Stepan777 <stepik-777@mail.ru>
parents: 7392
diff changeset
    30
{$IFNDEF WIN32}
8666
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    31
    {$linklib avcodec}
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    32
    {$linklib avformat}
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    33
    {$linklib avutil}
8697
9624836094de fix linking on osx
koda
parents: 8666
diff changeset
    34
    {$linklib avwrapper}
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    35
{$ENDIF}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    36
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    37
interface
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    38
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    39
var flagPrerecording: boolean = false;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    40
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    41
function BeginVideoRecording: Boolean;
7671
43f38923bc6e Fix some warnings
unc0rr
parents: 7540
diff changeset
    42
function LoadNextCameraPosition(out newRealTicks, newGameTicks: LongInt): Boolean;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    43
procedure EncodeFrame;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    44
procedure StopVideoRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    45
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    46
procedure BeginPreRecording;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    47
procedure StopPreRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    48
procedure SaveCameraPosition;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    49
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
    50
procedure initModule;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    51
procedure freeModule;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    52
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    53
implementation
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
    54
uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO, uMisc, uTypes;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    55
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    56
type TAddFileLogRaw = procedure (s: pchar); cdecl;
8666
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    57
const AvwrapperLibName = 'libavwrapper';
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    58
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    59
procedure AVWrapper_Init(
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    60
              AddLog: TAddFileLogRaw;
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
    61
              filename, desc, soundFile, format, vcodec, acodec: PChar;
8666
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    62
              width, height, framerateNum, framerateDen, vquality: LongInt); cdecl; external AvwrapperLibName;
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    63
procedure AVWrapper_Close; cdecl; external AvwrapperLibName;
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    64
procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external AvwrapperLibName;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    65
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    66
type TFrame = record
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
    67
                  realTicks: LongWord;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
    68
                  gameTicks: LongWord;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    69
                  CamX, CamY: LongInt;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    70
                  zoom: single;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    71
              end;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    72
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    73
var YCbCr_Planes: array[0..2] of PByte;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    74
    RGB_Buffer: PByte;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    75
    cameraFile: File of TFrame;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    76
    audioFile: File;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    77
    numPixels: LongWord;
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
    78
    startTime, numFrames, curTime, progress, maxProgress: LongWord;
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
    79
    soundFilePath: shortstring;
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
    80
    thumbnailSaved : Boolean;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    81
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    82
function BeginVideoRecording: Boolean;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    83
var filename, desc: shortstring;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    84
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    85
    AddFileLog('BeginVideoRecording');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    86
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    87
{$IOCHECKS OFF}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    88
    // open file with prerecorded camera positions
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
    89
    filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.txtin';
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
    90
    Assign(cameraFile, filename);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    91
    Reset(cameraFile);
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
    92
    maxProgress:= FileSize(cameraFile);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    93
    if IOResult <> 0 then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    94
    begin
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
    95
        AddFileLog('Error: Could not read from ' + filename);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    96
        exit(false);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    97
    end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    98
{$IOCHECKS ON}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    99
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   100
    // store some description in output file
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   101
    desc:= '';
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   102
    if UserNick <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   103
        desc:= desc + 'Player: ' + UserNick + #10;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   104
    if recordFileName <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   105
        desc:= desc + 'Record: ' + recordFileName + #10;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   106
    if cMapName <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   107
        desc:= desc + 'Map: ' + cMapName + #10;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   108
    if Theme <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   109
        desc:= desc + 'Theme: ' + Theme + #10;
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   110
    desc:= desc + 'prefix[' + RecPrefix + ']prefix';
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   111
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   112
    filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix;
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   113
    soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   114
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   115
    AVWrapper_Init(@AddFileLogRaw
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   116
        , PChar(ansistring(filename))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   117
        , PChar(ansistring(desc))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   118
        , PChar(ansistring(soundFilePath))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   119
        , PChar(ansistring(cAVFormat))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   120
        , PChar(ansistring(cVideoCodec))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   121
        , PChar(ansistring(cAudioCodec))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   122
        , cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cVideoQuality);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   123
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   124
    numPixels:= cScreenWidth*cScreenHeight;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   125
    YCbCr_Planes[0]:= GetMem(numPixels);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   126
    YCbCr_Planes[1]:= GetMem(numPixels div 4);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   127
    YCbCr_Planes[2]:= GetMem(numPixels div 4);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   128
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   129
    if (YCbCr_Planes[0] = nil) or (YCbCr_Planes[1] = nil) or (YCbCr_Planes[2] = nil) then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   130
    begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   131
        AddFileLog('Error: Could not allocate memory for video recording (YCbCr buffer).');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   132
        exit(false);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   133
    end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   134
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   135
    RGB_Buffer:= GetMem(4*numPixels);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   136
    if RGB_Buffer = nil then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   137
    begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   138
        AddFileLog('Error: Could not allocate memory for video recording (RGB buffer).');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   139
        exit(false);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   140
    end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   141
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   142
    curTime:= 0;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   143
    numFrames:= 0;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   144
    progress:= 0;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   145
    BeginVideoRecording:= true;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   146
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   147
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   148
procedure StopVideoRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   149
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   150
    AddFileLog('StopVideoRecording');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   151
    FreeMem(YCbCr_Planes[0], numPixels);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   152
    FreeMem(YCbCr_Planes[1], numPixels div 4);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   153
    FreeMem(YCbCr_Planes[2], numPixels div 4);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   154
    FreeMem(RGB_Buffer, 4*numPixels);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   155
    Close(cameraFile);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   156
    AVWrapper_Close();
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   157
    Erase(cameraFile);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   158
    DeleteFile(soundFilePath);
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   159
    SendIPC(_S'v'); // inform frontend that we finished
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   160
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   161
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   162
function pixel(x, y, color: LongInt): LongInt;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   163
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   164
    pixel:= RGB_Buffer[(cScreenHeight-y-1)*cScreenWidth*4 + x*4 + color];
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   165
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   166
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   167
procedure EncodeFrame;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   168
var x, y, r, g, b: LongInt;
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   169
    s: shortstring;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   170
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   171
    // read pixels from OpenGL
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   172
    glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, RGB_Buffer);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   173
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   174
    // convert to YCbCr 4:2:0 format
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   175
    // Y
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   176
    for y := 0 to cScreenHeight-1 do
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   177
        for x := 0 to cScreenWidth-1 do
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   178
            YCbCr_Planes[0][y*cScreenWidth + x]:= Byte(16 + ((16828*pixel(x,y,0) + 33038*pixel(x,y,1) + 6416*pixel(x,y,2)) shr 16));
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   179
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   180
    // Cb and Cr
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   181
    for y := 0 to cScreenHeight div 2 - 1 do
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   182
        for x := 0 to cScreenWidth div 2 - 1 do
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   183
        begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   184
            r:= pixel(2*x,2*y,0) + pixel(2*x+1,2*y,0) + pixel(2*x,2*y+1,0) + pixel(2*x+1,2*y+1,0);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   185
            g:= pixel(2*x,2*y,1) + pixel(2*x+1,2*y,1) + pixel(2*x,2*y+1,1) + pixel(2*x+1,2*y+1,1);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   186
            b:= pixel(2*x,2*y,2) + pixel(2*x+1,2*y,2) + pixel(2*x,2*y+1,2) + pixel(2*x+1,2*y+1,2);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   187
            YCbCr_Planes[1][y*(cScreenWidth div 2) + x]:= Byte(128 + ((-2428*r - 4768*g + 7196*b) shr 16));
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   188
            YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16));
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   189
        end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   190
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   191
    AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]);
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   192
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   193
    // inform frontend that we have encoded new frame
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   194
    s[0]:= #3;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   195
    s[1]:= 'p'; // p for progress
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   196
    SDLNet_Write16(progress*10000 div maxProgress, @s[2]);
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   197
    SendIPC(s);
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   198
    inc(numFrames);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   199
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   200
7671
43f38923bc6e Fix some warnings
unc0rr
parents: 7540
diff changeset
   201
function LoadNextCameraPosition(out newRealTicks, newGameTicks: LongInt): Boolean;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   202
var frame: TFrame = (realTicks: 0; gameTicks: 0; CamX: 0; CamY: 0; zoom: 0);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   203
begin
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   204
    // we need to skip or duplicate frames to match target framerate
7379
aa29a2f16cc7 fix bug with desynced camera positions
Stepan777 <stepik-777@mail.ru>
parents: 7376
diff changeset
   205
    while Int64(curTime)*cVideoFramerateNum <= Int64(numFrames)*cVideoFramerateDen*1000 do
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   206
    begin
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   207
    {$IOCHECKS OFF}
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   208
        if eof(cameraFile) then
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   209
            exit(false);
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   210
        BlockRead(cameraFile, frame, 1);
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   211
    {$IOCHECKS ON}
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   212
        curTime:= frame.realTicks;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   213
        WorldDx:= frame.CamX;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   214
        WorldDy:= frame.CamY + cScreenHeight div 2;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   215
        zoom:= frame.zoom*cScreenWidth;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   216
        ZoomValue:= zoom;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   217
        inc(progress);
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   218
        newRealTicks:= frame.realTicks;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   219
        newGameTicks:= frame.gameTicks;
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   220
    end;
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   221
    LoadNextCameraPosition:= true;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   222
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   223
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   224
// Callback which records sound.
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   225
// This procedure may be called from different thread.
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   226
procedure RecordPostMix(udata: pointer; stream: PByte; len: LongInt); cdecl;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   227
begin
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   228
    udata:= udata; // avoid warning
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   229
{$IOCHECKS OFF}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   230
    BlockWrite(audioFile, stream^, len);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   231
{$IOCHECKS ON}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   232
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   233
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   234
procedure SaveThumbnail;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   235
var thumbpath: shortstring;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   236
    k: LongInt;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   237
begin
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   238
    thumbpath:= '/VideoTemp/' + RecPrefix;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   239
    AddFileLog('Saving thumbnail ' + thumbpath);
7386
e82a076df09b Fix bug with isInLag picture displayed at end of some videos.
Stepan777 <stepik-777@mail.ru>
parents: 7379
diff changeset
   240
    k:= max(max(cScreenWidth, cScreenHeight) div 400, 1); // here 400 is minimum size of thumbnail
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   241
    MakeScreenshot(thumbpath, k);
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   242
    thumbnailSaved:= true;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   243
end;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   244
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   245
// copy file (free pascal doesn't have copy file function)
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   246
procedure CopyFile(src, dest: shortstring);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   247
var inF, outF: file;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   248
    buffer: array[0..1023] of byte;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   249
    result: LongInt;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   250
    i: integer;
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   251
begin
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   252
{$IOCHECKS OFF}
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   253
    result:= 0; // avoid compiler hint and warning
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   254
    for i:= 0 to 1023 do
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   255
        buffer[i]:= 0;
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   256
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   257
    Assign(inF, src);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   258
    Reset(inF, 1);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   259
    if IOResult <> 0 then
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   260
    begin
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   261
        AddFileLog('Error: Could not read from ' + src);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   262
        exit;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   263
    end;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   264
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   265
    Assign(outF, dest);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   266
    Rewrite(outF, 1);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   267
    if IOResult <> 0 then
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   268
    begin
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   269
        AddFileLog('Error: Could not write to ' + dest);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   270
        exit;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   271
    end;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   272
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   273
    repeat
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   274
        BlockRead(inF, buffer, 1024, result);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   275
        BlockWrite(outF, buffer, result);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   276
    until result < 1024;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   277
{$IOCHECKS ON}
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   278
end;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   279
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
   280
procedure BeginPreRecording;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   281
var format: word;
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   282
    filename: shortstring;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   283
    frequency, channels: LongInt;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   284
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   285
    AddFileLog('BeginPreRecording');
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   286
7369
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   287
    thumbnailSaved:= false;
7386
e82a076df09b Fix bug with isInLag picture displayed at end of some videos.
Stepan777 <stepik-777@mail.ru>
parents: 7379
diff changeset
   288
    RecPrefix:= 'hw-' + FormatDateTime('YYYY-MM-DD_HH-mm-ss-z', Now());
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   289
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   290
    // If this video is recorded from demo executed directly (without frontend)
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   291
    // then we need to copy demo so that frontend will be able to find it later.
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   292
    if recordFileName <> '' then
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   293
    begin
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   294
        if GameType <> gmtDemo then // this is save and game demo is not recording, abort
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   295
            exit;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   296
        CopyFile(recordFileName, UserPathPrefix + '/VideoTemp/' + RecPrefix + '.hwd');
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   297
    end;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   298
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   299
    Mix_QuerySpec(@frequency, @format, @channels);
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   300
    AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels));
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   301
    if format <> $8010 then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   302
    begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   303
        // TODO: support any audio format
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   304
        AddFileLog('Error: Unexpected audio format ' + IntToStr(format));
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
   305
        exit;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   306
    end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   307
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   308
{$IOCHECKS OFF}
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   309
    // create sound file
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   310
    filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   311
    Assign(audioFile, filename);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   312
    Rewrite(audioFile, 1);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   313
    if IOResult <> 0 then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   314
    begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   315
        AddFileLog('Error: Could not write to ' + filename);
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
   316
        exit;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   317
    end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   318
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   319
    // create file with camera positions
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   320
    filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.txtout';
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   321
    Assign(cameraFile, filename);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   322
    Rewrite(cameraFile);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   323
    if IOResult <> 0 then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   324
    begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   325
        AddFileLog('Error: Could not write to ' + filename);
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
   326
        exit;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   327
    end;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   328
7369
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   329
    // save audio parameters in sound file
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   330
    BlockWrite(audioFile, frequency, 4);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   331
    BlockWrite(audioFile, channels, 4);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   332
{$IOCHECKS ON}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   333
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   334
    // register callback for actual audio recording
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   335
    Mix_SetPostMix(@RecordPostMix, nil);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   336
7369
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   337
    startTime:= SDL_GetTicks();
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   338
    flagPrerecording:= true;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   339
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   340
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   341
procedure StopPreRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   342
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   343
    AddFileLog('StopPreRecording');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   344
    flagPrerecording:= false;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   345
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   346
    // call SDL_LockAudio because RecordPostMix may be executing right now
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   347
    SDL_LockAudio();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   348
    Close(audioFile);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   349
    Close(cameraFile);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   350
    Mix_SetPostMix(nil, nil);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   351
    SDL_UnlockAudio();
7369
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   352
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   353
    if not thumbnailSaved then
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   354
        SaveThumbnail();
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   355
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   356
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   357
procedure SaveCameraPosition;
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   358
var frame: TFrame;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   359
begin
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   360
    if (not thumbnailSaved) and (ScreenFade = sfNone) then
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   361
        SaveThumbnail();
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   362
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   363
    frame.realTicks:= SDL_GetTicks() - startTime;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   364
    frame.gameTicks:= GameTicks;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   365
    frame.CamX:= WorldDx;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   366
    frame.CamY:= WorldDy - cScreenHeight div 2;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   367
    frame.zoom:= zoom/cScreenWidth;
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7369
diff changeset
   368
    BlockWrite(cameraFile, frame, 1);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   369
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   370
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   371
procedure initModule;
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   372
begin
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   373
end;
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   374
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   375
procedure freeModule;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   376
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   377
    if flagPrerecording then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   378
        StopPreRecording();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   379
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   380
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   381
end.
7286
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
   382
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
   383
{$ENDIF} // USE_VIDEO_RECORDING