author | Wuzzy <Wuzzy2@mail.ru> |
Sun, 05 Jul 2020 02:03:08 +0200 | |
branch | ui-scaling |
changeset 15694 | b3c9f5463cee |
parent 15357 | f53bfe04065e |
child 15488 | a7d54832fad6 |
permissions | -rw-r--r-- |
7180 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
7180 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
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 | 17 |
*) |
18 |
||
7286 | 19 |
|
7180 | 20 |
{$INCLUDE "options.inc"} |
21 |
||
22 |
unit uVideoRec; |
|
23 |
||
7286 | 24 |
{$IFNDEF USE_VIDEO_RECORDING} |
25 |
interface |
|
26 |
implementation |
|
27 |
end. |
|
28 |
{$ELSE} |
|
29 |
||
14220 | 30 |
{$IFNDEF WINDOWS} |
8697 | 31 |
{$linklib avwrapper} |
7180 | 32 |
{$ENDIF} |
33 |
||
34 |
interface |
|
35 |
||
36 |
var flagPrerecording: boolean = false; |
|
37 |
||
38 |
function BeginVideoRecording: Boolean; |
|
14482
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
14220
diff
changeset
|
39 |
function LoadNextCameraPosition(var newRealTicks, newGameTicks: LongInt): Boolean; |
7180 | 40 |
procedure EncodeFrame; |
41 |
procedure StopVideoRecording; |
|
42 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
43 |
procedure BeginPreRecording; |
7180 | 44 |
procedure StopPreRecording; |
45 |
procedure SaveCameraPosition; |
|
46 |
||
7850 | 47 |
procedure initModule; |
7180 | 48 |
procedure freeModule; |
49 |
||
50 |
implementation |
|
15288
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
51 |
uses uVariables, GLunit, SDLh, SysUtils, uUtils, uSound, uIO, uMisc, uTypes, uDebug; |
7180 | 52 |
|
53 |
type TAddFileLogRaw = procedure (s: pchar); cdecl; |
|
15357 | 54 |
const AvwrapperLibName = {$IFDEF WIN32_VCPKG}'avwrapper'{$ELSE}'libavwrapper'{$ENDIF}; |
7180 | 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 | 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 | 70 |
var RGB_Buffer: PByte; |
14900
002f7d41f5ce
VideoRec: Replace "File of" syntax to make Pas2C happy
Wuzzy <Wuzzy2@mail.ru>
parents:
14482
diff
changeset
|
71 |
cameraFile: File; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
72 |
cameraFileName: shortstring; |
7180 | 73 |
audioFile: File; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
soundFilePath: shortstring; |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
77 |
thumbnailSaved: boolean; |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
78 |
recordAudio: boolean; |
7180 | 79 |
|
80 |
function BeginVideoRecording: Boolean; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
81 |
var filename, desc: shortstring; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
82 |
filenameA, descA, soundFilePathA, cAVFormatA, cVideoCodecA, cAudioCodecA: ansistring; |
7180 | 83 |
begin |
84 |
AddFileLog('BeginVideoRecording'); |
|
85 |
||
86 |
{$IOCHECKS OFF} |
|
87 |
// open file with prerecorded camera positions |
|
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
88 |
cameraFileName:= shortstring(UserPathPrefix) + '/VideoTemp/' + shortstring(RecPrefix) + '.txtin'; |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
89 |
Assign(cameraFile, cameraFileName); |
14900
002f7d41f5ce
VideoRec: Replace "File of" syntax to make Pas2C happy
Wuzzy <Wuzzy2@mail.ru>
parents:
14482
diff
changeset
|
90 |
Reset(cameraFile, SizeOf(TFrame)); |
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
|
91 |
maxProgress:= FileSize(cameraFile); |
7180 | 92 |
if IOResult <> 0 then |
93 |
begin |
|
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
94 |
AddFileLog('Error: Could not read from ' + cameraFileName); |
7180 | 95 |
exit(false); |
96 |
end; |
|
97 |
{$IOCHECKS ON} |
|
98 |
||
13226
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12621
diff
changeset
|
99 |
{ Store some description in output file. |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12621
diff
changeset
|
100 |
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
|
101 |
This will be parsed by the frontend. |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12621
diff
changeset
|
102 |
The frontend will parse lines of this format: |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12621
diff
changeset
|
103 |
Key: Value |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12621
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
in the frontend! } |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
107 |
desc:= ''; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
108 |
if UserNick <> '' then |
7804 | 109 |
desc:= desc + 'Player: ' + UserNick + #10; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
110 |
if recordFileName <> '' then |
7804 | 111 |
desc:= desc + 'Record: ' + recordFileName + #10; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
112 |
if cMapName <> '' then |
7804 | 113 |
desc:= desc + 'Map: ' + cMapName + #10; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
114 |
if Theme <> '' then |
7804 | 115 |
desc:= desc + 'Theme: ' + Theme + #10; |
116 |
desc:= desc + 'prefix[' + RecPrefix + ']prefix'; |
|
117 |
||
14914
66b510a8b81c
Pas2C: Fix path concatenation in uVideoRec
Wuzzy <Wuzzy2@mail.ru>
parents:
14908
diff
changeset
|
118 |
filename:= shortstring(UserPathPrefix) + '/VideoTemp/' + shortstring(RecPrefix); |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
119 |
|
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
120 |
recordAudio:= (cAudioCodec <> 'no'); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
121 |
if recordAudio then |
14914
66b510a8b81c
Pas2C: Fix path concatenation in uVideoRec
Wuzzy <Wuzzy2@mail.ru>
parents:
14908
diff
changeset
|
122 |
soundFilePath:= shortstring(UserPathPrefix) + '/VideoTemp/' + shortstring(RecPrefix) + '.sw' |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
123 |
else |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
124 |
soundFilePath:= ''; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
125 |
|
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
126 |
filenameA:= ansistring(filename); |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
127 |
descA:= ansistring(desc); |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
128 |
soundFilePathA:= ansistring(soundFilePath); |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
129 |
cAVFormatA:= ansistring(cAVFormat); |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
130 |
cVideoCodecA:= ansistring(cVideoCodec); |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
131 |
cAudioCodecA:= ansistring(cAudioCodec); |
11532 | 132 |
if checkFails(AVWrapper_Init(@AddFileLogRaw |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
133 |
, PChar(filenameA) |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
134 |
, PChar(descA) |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
135 |
, PChar(soundFilePathA) |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
136 |
, PChar(cAVFormatA) |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
137 |
, PChar(cVideoCodecA) |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
138 |
, PChar(cAudioCodecA) |
10309 | 139 |
, cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cVideoQuality) >= 0, |
140 |
'AVWrapper_Init failed', |
|
11532 | 141 |
true) then exit(false); |
7180 | 142 |
|
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
|
143 |
numPixels:= cScreenWidth*cScreenHeight; |
7180 | 144 |
|
145 |
RGB_Buffer:= GetMem(4*numPixels); |
|
146 |
if RGB_Buffer = nil then |
|
147 |
begin |
|
148 |
AddFileLog('Error: Could not allocate memory for video recording (RGB buffer).'); |
|
149 |
exit(false); |
|
150 |
end; |
|
151 |
||
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
|
152 |
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
|
153 |
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
|
154 |
progress:= 0; |
7180 | 155 |
BeginVideoRecording:= true; |
156 |
end; |
|
157 |
||
158 |
procedure StopVideoRecording; |
|
159 |
begin |
|
160 |
AddFileLog('StopVideoRecording'); |
|
161 |
FreeMem(RGB_Buffer, 4*numPixels); |
|
162 |
Close(cameraFile); |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9545
diff
changeset
|
163 |
if AVWrapper_Close() < 0 then |
13499
b5f8864a38d3
Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
164 |
begin |
14973
8e4e508d153c
Use HaltFatalError for all VideoRec failures
Wuzzy <Wuzzy2@mail.ru>
parents:
14935
diff
changeset
|
165 |
OutError('AVWrapper_Close() has failed.', true); |
13499
b5f8864a38d3
Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
166 |
end; |
13519
d8462cc9d42d
Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents:
13499
diff
changeset
|
167 |
{$IOCHECKS OFF} |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
168 |
if FileExists(cameraFileName) then |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
169 |
DeleteFile(cameraFileName) |
13519
d8462cc9d42d
Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents:
13499
diff
changeset
|
170 |
else |
d8462cc9d42d
Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents:
13499
diff
changeset
|
171 |
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:
13499
diff
changeset
|
172 |
{$IOCHECKS ON} |
d8462cc9d42d
Fix engine crash when trying to delete cameraFile but it doesn't exist
Wuzzy <Wuzzy2@mail.ru>
parents:
13499
diff
changeset
|
173 |
if recordAudio and FileExists(soundFilePath) then |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
174 |
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
|
175 |
SendIPC(_S'v'); // inform frontend that we finished |
7180 | 176 |
end; |
177 |
||
178 |
procedure EncodeFrame; |
|
11612
b7d5d75469ee
Move pixel format conversion from uVideoRec to AVWrapper
koda
parents:
11532
diff
changeset
|
179 |
var s: shortstring; |
7180 | 180 |
begin |
181 |
// read pixels from OpenGL |
|
182 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, RGB_Buffer); |
|
183 |
||
11612
b7d5d75469ee
Move pixel format conversion from uVideoRec to AVWrapper
koda
parents:
11532
diff
changeset
|
184 |
if AVWrapper_WriteFrame(RGB_Buffer) < 0 then |
13499
b5f8864a38d3
Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
185 |
begin |
14973
8e4e508d153c
Use HaltFatalError for all VideoRec failures
Wuzzy <Wuzzy2@mail.ru>
parents:
14935
diff
changeset
|
186 |
OutError('AVWrapper_WriteFrame(RGB_Buffer) has failed.', true); |
13499
b5f8864a38d3
Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
187 |
end; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
188 |
|
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
|
189 |
// 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
|
190 |
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
|
191 |
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
|
192 |
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
|
193 |
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
|
194 |
inc(numFrames); |
7180 | 195 |
end; |
196 |
||
14482
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
14220
diff
changeset
|
197 |
function LoadNextCameraPosition(var newRealTicks, newGameTicks: LongInt): Boolean; |
8370 | 198 |
var frame: TFrame = (realTicks: 0; gameTicks: 0; CamX: 0; CamY: 0; zoom: 0); |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
199 |
res: LongInt; |
7180 | 200 |
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
|
201 |
// 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
|
202 |
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
|
203 |
begin |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
204 |
res:= 0; |
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
|
205 |
{$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
|
206 |
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
|
207 |
exit(false); |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
208 |
BlockRead(cameraFile, frame, 1, res); |
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
|
209 |
{$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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
inc(progress); |
7392
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
216 |
newRealTicks:= frame.realTicks; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
217 |
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
|
218 |
end; |
7392
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
219 |
LoadNextCameraPosition:= true; |
7180 | 220 |
end; |
221 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
222 |
// 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
|
223 |
// This procedure may be called from different thread. |
7180 | 224 |
procedure RecordPostMix(udata: pointer; stream: PByte; len: LongInt); cdecl; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
225 |
var result: LongInt; |
7180 | 226 |
begin |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
227 |
result:= 0; // avoid warning |
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 | 229 |
{$IOCHECKS OFF} |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
230 |
BlockWrite(audioFile, stream^, len, result); |
7180 | 231 |
{$IOCHECKS ON} |
232 |
end; |
|
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 |
14908
a414d37278df
Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents:
14900
diff
changeset
|
238 |
thumbpath:= '/VideoThumbnails/' + RecPrefix; |
7306
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 |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10309
diff
changeset
|
241 |
MakeScreenshot(thumbpath, k, 0); |
7306
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; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
249 |
result, result2: LongInt; |
8370 | 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 | 253 |
result:= 0; // avoid compiler hint and warning |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
254 |
result2:= 0; // avoid compiler hint and warning |
8370 | 255 |
for i:= 0 to 1023 do |
256 |
buffer[i]:= 0; |
|
7392
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
257 |
|
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
258 |
Assign(inF, src); |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
259 |
Reset(inF, 1); |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
260 |
if IOResult <> 0 then |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
261 |
begin |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
262 |
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
|
263 |
exit; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
264 |
end; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
265 |
|
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
266 |
Assign(outF, dest); |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
267 |
Rewrite(outF, 1); |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
268 |
if IOResult <> 0 then |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
269 |
begin |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
270 |
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
|
271 |
exit; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
272 |
end; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
273 |
|
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
274 |
repeat |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
275 |
BlockRead(inF, buffer, 1024, result); |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
276 |
BlockWrite(outF, buffer, result, result2); |
7392
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
277 |
until result < 1024; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
278 |
{$IOCHECKS ON} |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
279 |
end; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
280 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
281 |
procedure BeginPreRecording; |
7180 | 282 |
var format: word; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
283 |
filename: shortstring; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
284 |
frequency, channels: LongInt; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
285 |
result: LongInt; |
7180 | 286 |
begin |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
287 |
result:= 0; |
7180 | 288 |
AddFileLog('BeginPreRecording'); |
15288
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
289 |
// Videos don't work if /lua command was used, so we forbid them |
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
290 |
if luaCmdUsed then |
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
291 |
begin |
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
292 |
// TODO: Show message to player |
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
293 |
PlaySound(sndDenied); |
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
294 |
AddFileLog('Pre-recording prevented; /lua command was used before'); |
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
295 |
exit; |
22f2fd8a3d2c
VideoRec: Stop prerecording when /lua activates
Wuzzy <Wuzzy2@mail.ru>
parents:
14973
diff
changeset
|
296 |
end; |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
297 |
|
7369
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
298 |
thumbnailSaved:= false; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
299 |
RecPrefix:= 'hw-' + FormatDateTime('YYYY-MM-DD_HH-mm-ss-z', TDateTime(Now())); |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
300 |
|
7392
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
301 |
// 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
|
302 |
// 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
|
303 |
if recordFileName <> '' then |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
304 |
begin |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
305 |
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
|
306 |
exit; |
14914
66b510a8b81c
Pas2C: Fix path concatenation in uVideoRec
Wuzzy <Wuzzy2@mail.ru>
parents:
14908
diff
changeset
|
307 |
CopyFile(recordFileName, shortstring(UserPathPrefix) + '/VideoTemp/' + shortstring(RecPrefix) + '.hwd'); |
7392
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
308 |
end; |
bc3306c59a08
Correctly distinguish between game and real ticks while recording video,
Stepan777 <stepik-777@mail.ru>
parents:
7386
diff
changeset
|
309 |
|
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
310 |
if cIsSoundEnabled then |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
311 |
begin |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
if format <> $8010 then |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
315 |
begin |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
316 |
// 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
|
317 |
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
|
318 |
exit; |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
319 |
end; |
7180 | 320 |
|
321 |
{$IOCHECKS OFF} |
|
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
322 |
// create sound file |
14914
66b510a8b81c
Pas2C: Fix path concatenation in uVideoRec
Wuzzy <Wuzzy2@mail.ru>
parents:
14908
diff
changeset
|
323 |
filename:= shortstring(UserPathPrefix) + '/VideoTemp/' + shortstring(RecPrefix) + '.sw'; |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
324 |
Assign(audioFile, filename); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
325 |
Rewrite(audioFile, 1); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
326 |
if IOResult <> 0 then |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
327 |
begin |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
328 |
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
|
329 |
exit; |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
330 |
end; |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
331 |
end; |
7180 | 332 |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
333 |
// create file with camera positions |
14914
66b510a8b81c
Pas2C: Fix path concatenation in uVideoRec
Wuzzy <Wuzzy2@mail.ru>
parents:
14908
diff
changeset
|
334 |
filename:= shortstring(UserPathPrefix) + '/VideoTemp/' + shortstring(RecPrefix) + '.txtout'; |
7180 | 335 |
Assign(cameraFile, filename); |
14900
002f7d41f5ce
VideoRec: Replace "File of" syntax to make Pas2C happy
Wuzzy <Wuzzy2@mail.ru>
parents:
14482
diff
changeset
|
336 |
Rewrite(cameraFile, SizeOf(TFrame)); |
7180 | 337 |
if IOResult <> 0 then |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
338 |
begin |
7180 | 339 |
AddFileLog('Error: Could not write to ' + filename); |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
340 |
exit; |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
341 |
end; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
342 |
|
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
343 |
if cIsSoundEnabled then |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
344 |
begin |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
345 |
// save audio parameters in sound file |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
346 |
BlockWrite(audioFile, frequency, 4, result); |
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
347 |
BlockWrite(audioFile, channels, 4, result); |
7180 | 348 |
{$IOCHECKS ON} |
349 |
||
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
350 |
// 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
|
351 |
Mix_SetPostMix(@RecordPostMix, nil); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
352 |
end; |
7180 | 353 |
|
7369
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
354 |
startTime:= SDL_GetTicks(); |
7180 | 355 |
flagPrerecording:= true; |
356 |
end; |
|
357 |
||
358 |
procedure StopPreRecording; |
|
359 |
begin |
|
360 |
AddFileLog('StopPreRecording'); |
|
361 |
flagPrerecording:= false; |
|
362 |
||
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
363 |
if cIsSoundEnabled then |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
364 |
begin |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
365 |
// 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
|
366 |
SDL_LockAudio(); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
367 |
Close(audioFile); |
13497 | 368 |
end; |
7180 | 369 |
Close(cameraFile); |
13496
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
370 |
if cIsSoundEnabled then |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
371 |
begin |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
372 |
Mix_SetPostMix(nil, nil); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
373 |
SDL_UnlockAudio(); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
374 |
end; |
7369
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
375 |
|
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
376 |
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
|
377 |
SaveThumbnail(); |
7180 | 378 |
end; |
379 |
||
380 |
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
|
381 |
var frame: TFrame; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
382 |
result: LongInt; |
7180 | 383 |
begin |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
384 |
result:= 0; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
385 |
if (not thumbnailSaved) and (ScreenFade = sfNone) then |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
386 |
SaveThumbnail(); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
387 |
|
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
|
388 |
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
|
389 |
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
|
390 |
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
|
391 |
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
|
392 |
frame.zoom:= zoom/cScreenWidth; |
14935
9ab78e08a34c
Fix Pas2C unable to compile with VIDEOREC
Wuzzy <Wuzzy2@mail.ru>
parents:
14914
diff
changeset
|
393 |
BlockWrite(cameraFile, frame, 1, result); |
7180 | 394 |
end; |
395 |
||
7850 | 396 |
procedure initModule; |
397 |
begin |
|
9543 | 398 |
// we need to make sure these variables are initialized before the main loop |
399 |
// or the wrapper will keep the default values of preinit |
|
9545 | 400 |
cScreenWidth:= max(cWindowedWidth, 640); |
401 |
cScreenHeight:= max(cWindowedHeight, 480); |
|
7850 | 402 |
end; |
403 |
||
7180 | 404 |
procedure freeModule; |
405 |
begin |
|
406 |
if flagPrerecording then |
|
407 |
StopPreRecording(); |
|
408 |
end; |
|
409 |
||
410 |
end. |
|
7286 | 411 |
|
412 |
{$ENDIF} // USE_VIDEO_RECORDING |