hedgewars/uVideoRec.pas
author Wuzzy <Wuzzy2@mail.ru>
Sat, 28 Jul 2018 13:15:59 +0200
changeset 13567 8f9b84d6991d
parent 13513 d8462cc9d42d
child 14199 3c36a4e66c82
permissions -rw-r--r--
Fix DrawHLinesExplosions setting invalid map pixels if called at wrap world edge This caused an errror message after the game when using hammer or pickhammer at wrap world edge.
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10633
diff changeset
     3
 * Copyright (c) 2004-2015 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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7180
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}
8697
9624836094de fix linking on osx
koda
parents: 8666
diff changeset
    31
    {$linklib avwrapper}
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    32
{$ENDIF}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    33
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    34
interface
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    35
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    36
var flagPrerecording: boolean = false;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    37
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    38
function BeginVideoRecording: Boolean;
7671
43f38923bc6e Fix some warnings
unc0rr
parents: 7540
diff changeset
    39
function LoadNextCameraPosition(out newRealTicks, newGameTicks: LongInt): Boolean;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    40
procedure EncodeFrame;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    41
procedure StopVideoRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    42
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    43
procedure BeginPreRecording;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    44
procedure StopPreRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    45
procedure SaveCameraPosition;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    46
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
    47
procedure initModule;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    48
procedure freeModule;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    49
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    50
implementation
13495
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
    51
uses uVariables, GLunit, SDLh, SysUtils, uUtils, uIO, uMisc, uConsts, uTypes, uDebug;
7180
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
type TAddFileLogRaw = procedure (s: pchar); cdecl;
8666
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8370
diff changeset
    54
const AvwrapperLibName = 'libavwrapper';
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    55
9925
113e61a8cadc Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 9545
diff changeset
    56
function AVWrapper_Init(
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    57
              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
    58
              filename, desc, soundFile, format, vcodec, acodec: PChar;
9925
113e61a8cadc Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 9545
diff changeset
    59
              width, height, framerateNum, framerateDen, vquality: LongInt): LongInt; cdecl; external AvwrapperLibName;
113e61a8cadc Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 9545
diff changeset
    60
function AVWrapper_Close: LongInt; cdecl; external AvwrapperLibName;
11612
b7d5d75469ee Move pixel format conversion from uVideoRec to AVWrapper
koda
parents: 11532
diff changeset
    61
function AVWrapper_WriteFrame(rgb: PByte): LongInt; cdecl; external AvwrapperLibName;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    62
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    63
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
    64
                  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
    65
                  gameTicks: LongWord;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    66
                  CamX, CamY: LongInt;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    67
                  zoom: single;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    68
              end;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    69
12621
d972b31f8881 fix some fpc hints
sheepluva
parents: 11821
diff changeset
    70
var RGB_Buffer: PByte;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    71
    cameraFile: File of TFrame;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    72
    audioFile: File;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    73
    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
    74
    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
    75
    soundFilePath: shortstring;
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
    76
    thumbnailSaved: boolean;
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
    77
    recordAudio: boolean;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    78
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    79
function BeginVideoRecording: Boolean;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    80
var filename, desc: shortstring;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    81
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    82
    AddFileLog('BeginVideoRecording');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    83
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    84
{$IOCHECKS OFF}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    85
    // 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
    86
    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
    87
    Assign(cameraFile, filename);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    88
    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
    89
    maxProgress:= FileSize(cameraFile);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    90
    if IOResult <> 0 then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    91
    begin
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
    92
        AddFileLog('Error: Could not read from ' + filename);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    93
        exit(false);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    94
    end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    95
{$IOCHECKS ON}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    96
13226
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
    97
    { Store some description in output file.
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
    98
    The comment must follow a particular format and must be in English.
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
    99
    This will be parsed by the frontend.
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
   100
    The frontend will parse lines of this format:
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
   101
        Key: Value
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
   102
    The key names will be localized in the frontend.
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
   103
    If you add a key/value pair, don't forget to add a localization
4028d7f85233 Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 12621
diff changeset
   104
    in the frontend! }
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   105
    desc:= '';
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   106
    if UserNick <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   107
        desc:= desc + 'Player: ' + UserNick + #10;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   108
    if recordFileName <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   109
        desc:= desc + 'Record: ' + recordFileName + #10;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   110
    if cMapName <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   111
        desc:= desc + 'Map: ' + cMapName + #10;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   112
    if Theme <> '' then
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   113
        desc:= desc + 'Theme: ' + Theme + #10;
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   114
    desc:= desc + 'prefix[' + RecPrefix + ']prefix';
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   115
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   116
    filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix;
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   117
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   118
    recordAudio:= (cAudioCodec <> 'no');
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   119
    if recordAudio then
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   120
        soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw'
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   121
    else
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   122
        soundFilePath:= '';
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   123
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11046
diff changeset
   124
    if checkFails(AVWrapper_Init(@AddFileLogRaw
7804
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   125
        , PChar(ansistring(filename))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   126
        , PChar(ansistring(desc))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   127
        , PChar(ansistring(soundFilePath))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   128
        , PChar(ansistring(cAVFormat))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   129
        , PChar(ansistring(cVideoCodec))
9122461ae32b Get rid of C-style operators
unc0rr
parents: 7671
diff changeset
   130
        , PChar(ansistring(cAudioCodec))
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   131
        , cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cVideoQuality) >= 0,
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   132
        'AVWrapper_Init failed',
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11046
diff changeset
   133
        true) then exit(false);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   134
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
   135
    numPixels:= cScreenWidth*cScreenHeight;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   136
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   137
    RGB_Buffer:= GetMem(4*numPixels);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   138
    if RGB_Buffer = nil then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   139
    begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   140
        AddFileLog('Error: Could not allocate memory for video recording (RGB buffer).');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   141
        exit(false);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   142
    end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   143
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
   144
    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
   145
    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
   146
    progress:= 0;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   147
    BeginVideoRecording:= true;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   148
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   149
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   150
procedure StopVideoRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   151
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   152
    AddFileLog('StopVideoRecording');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   153
    FreeMem(RGB_Buffer, 4*numPixels);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   154
    Close(cameraFile);
9925
113e61a8cadc Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 9545
diff changeset
   155
    if AVWrapper_Close() < 0 then
13495
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   156
        begin
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   157
        AddFileLog('AVWrapper_Close() has failed.');
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   158
        halt(HaltVideoRec);
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   159
        end;
13513
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   160
{$IOCHECKS OFF}
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   161
    // Provoke IOResult to be set
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   162
    FileSize(cameraFile);
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   163
    if IOResult = 0 then
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   164
        Erase(cameraFile)
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   165
    else
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   166
        AddFileLog('Warning: Tried to delete the cameraFile but it was already deleted');
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   167
{$IOCHECKS ON}
d8462cc9d42d Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents: 13495
diff changeset
   168
    if recordAudio and FileExists(soundFilePath) then
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   169
        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
   170
    SendIPC(_S'v'); // inform frontend that we finished
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   171
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   172
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   173
procedure EncodeFrame;
11612
b7d5d75469ee Move pixel format conversion from uVideoRec to AVWrapper
koda
parents: 11532
diff changeset
   174
var s: shortstring;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   175
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   176
    // read pixels from OpenGL
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   177
    glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, RGB_Buffer);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   178
11612
b7d5d75469ee Move pixel format conversion from uVideoRec to AVWrapper
koda
parents: 11532
diff changeset
   179
    if AVWrapper_WriteFrame(RGB_Buffer) < 0 then
13495
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   180
        begin
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   181
        AddFileLog('AVWrapper_WriteFrame(RGB_Buffer) has failed.');
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   182
        halt(HaltVideoRec);
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 13493
diff changeset
   183
        end;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   184
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
   185
    // 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
   186
    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
   187
    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
   188
    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
   189
    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
   190
    inc(numFrames);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   191
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   192
7671
43f38923bc6e Fix some warnings
unc0rr
parents: 7540
diff changeset
   193
function LoadNextCameraPosition(out newRealTicks, newGameTicks: LongInt): Boolean;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   194
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
   195
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
   196
    // 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
   197
    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
   198
    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
   199
    {$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
   200
        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
   201
            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
   202
        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
   203
    {$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
   204
        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
   205
        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
   206
        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
   207
        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
   208
        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
   209
        inc(progress);
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   210
        newRealTicks:= frame.realTicks;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   211
        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
   212
    end;
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   213
    LoadNextCameraPosition:= true;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   214
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   215
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   216
// 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
   217
// This procedure may be called from different thread.
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   218
procedure RecordPostMix(udata: pointer; stream: PByte; len: LongInt); cdecl;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   219
begin
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   220
    udata:= udata; // avoid warning
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   221
{$IOCHECKS OFF}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   222
    BlockWrite(audioFile, stream^, len);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   223
{$IOCHECKS ON}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   224
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   225
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   226
procedure SaveThumbnail;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   227
var thumbpath: shortstring;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   228
    k: LongInt;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   229
begin
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   230
    thumbpath:= '/VideoTemp/' + RecPrefix;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   231
    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
   232
    k:= max(max(cScreenWidth, cScreenHeight) div 400, 1); // here 400 is minimum size of thumbnail
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10309
diff changeset
   233
    MakeScreenshot(thumbpath, k, 0);
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   234
    thumbnailSaved:= true;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   235
end;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   236
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   237
// 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
   238
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
   239
var inF, outF: file;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   240
    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
   241
    result: LongInt;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   242
    i: integer;
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   243
begin
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   244
{$IOCHECKS OFF}
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   245
    result:= 0; // avoid compiler hint and warning
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   246
    for i:= 0 to 1023 do
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8279
diff changeset
   247
        buffer[i]:= 0;
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   248
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   249
    Assign(inF, src);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   250
    Reset(inF, 1);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   251
    if IOResult <> 0 then
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   252
    begin
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   253
        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
   254
        exit;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   255
    end;
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(outF, dest);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   258
    Rewrite(outF, 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 write to ' + dest);
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
    repeat
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   266
        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
   267
        BlockWrite(outF, buffer, result);
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   268
    until result < 1024;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   269
{$IOCHECKS ON}
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   270
end;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   271
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
   272
procedure BeginPreRecording;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   273
var format: word;
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   274
    filename: shortstring;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   275
    frequency, channels: LongInt;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   276
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   277
    AddFileLog('BeginPreRecording');
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   278
7369
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   279
    thumbnailSaved:= false;
7386
e82a076df09b Fix bug with isInLag picture displayed at end of some videos.
Stepan777 <stepik-777@mail.ru>
parents: 7379
diff changeset
   280
    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
   281
7392
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   282
    // 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
   283
    // 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
   284
    if recordFileName <> '' then
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   285
    begin
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   286
        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
   287
            exit;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   288
        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
   289
    end;
bc3306c59a08 Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents: 7386
diff changeset
   290
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   291
    if cIsSoundEnabled then
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   292
        begin
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   293
        Mix_QuerySpec(@frequency, @format, @channels);
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   294
        AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels));
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   295
        if format <> $8010 then
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   296
            begin
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   297
            // TODO: support any audio format
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   298
            AddFileLog('Error: Unexpected audio format ' + IntToStr(format));
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   299
            exit;
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   300
            end;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   301
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   302
{$IOCHECKS OFF}
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   303
        // create sound file
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   304
        filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   305
        Assign(audioFile, filename);
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   306
        Rewrite(audioFile, 1);
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   307
        if IOResult <> 0 then
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   308
            begin
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   309
            AddFileLog('Error: Could not write to ' + filename);
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   310
            exit;
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   311
            end;
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   312
        end;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   313
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents: 7198
diff changeset
   314
    // create file with camera positions
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   315
    filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.txtout';
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   316
    Assign(cameraFile, filename);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   317
    Rewrite(cameraFile);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   318
    if IOResult <> 0 then
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   319
        begin
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   320
        AddFileLog('Error: Could not write to ' + filename);
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
   321
        exit;
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   322
        end;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   323
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   324
    if cIsSoundEnabled then
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   325
        begin
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   326
        // save audio parameters in sound file
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   327
        BlockWrite(audioFile, frequency, 4);
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   328
        BlockWrite(audioFile, channels, 4);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   329
{$IOCHECKS ON}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   330
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   331
        // register callback for actual audio recording
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   332
        Mix_SetPostMix(@RecordPostMix, nil);
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   333
        end;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   334
7369
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   335
    startTime:= SDL_GetTicks();
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   336
    flagPrerecording:= true;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   337
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   338
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   339
procedure StopPreRecording;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   340
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   341
    AddFileLog('StopPreRecording');
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   342
    flagPrerecording:= false;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   343
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   344
    if cIsSoundEnabled then
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   345
        begin
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   346
        // call SDL_LockAudio because RecordPostMix may be executing right now
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   347
        SDL_LockAudio();
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   348
        Close(audioFile);
13493
3bb07c847886 Whoops. Syntax error in uVideoRec
Wuzzy <Wuzzy2@mail.ru>
parents: 13492
diff changeset
   349
        end;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   350
    Close(cameraFile);
13492
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   351
    if cIsSoundEnabled then
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   352
        begin
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   353
        Mix_SetPostMix(nil, nil);
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   354
        SDL_UnlockAudio();
c7df0d96da81 Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents: 13226
diff changeset
   355
        end;
7369
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   356
46921fbe76d3 Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents: 7363
diff changeset
   357
    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
   358
        SaveThumbnail();
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   359
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   360
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   361
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
   362
var frame: TFrame;
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   363
begin
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   364
    if (not thumbnailSaved) and (ScreenFade = sfNone) then
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   365
        SaveThumbnail();
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7286
diff changeset
   366
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
   367
    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
   368
    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
   369
    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
   370
    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
   371
    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
   372
    BlockWrite(cameraFile, frame, 1);
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   373
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   374
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   375
procedure initModule;
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   376
begin
9543
1826b5315369 Fix bug 656 by using the right resolution values
koda
parents: 9203
diff changeset
   377
    // we need to make sure these variables are initialized before the main loop
1826b5315369 Fix bug 656 by using the right resolution values
koda
parents: 9203
diff changeset
   378
    // or the wrapper will keep the default values of preinit
9545
f7a55d8e8f4d min->max
koda
parents: 9543
diff changeset
   379
    cScreenWidth:= max(cWindowedWidth, 640);
f7a55d8e8f4d min->max
koda
parents: 9543
diff changeset
   380
    cScreenHeight:= max(cWindowedHeight, 480);
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   381
end;
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7816
diff changeset
   382
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   383
procedure freeModule;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   384
begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   385
    if flagPrerecording then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   386
        StopPreRecording();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   387
end;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   388
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   389
end.
7286
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
   390
068adc6948e3 remaining IFDEFs
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
   391
{$ENDIF} // USE_VIDEO_RECORDING