author | Stepan777 <stepik-777@mail.ru> |
Tue, 26 Jun 2012 02:15:50 +0400 | |
changeset 7294 | 135e4fb3b095 |
parent 7286 | 068adc6948e3 |
child 7306 | 3cff5c769509 |
permissions | -rw-r--r-- |
7180 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
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 |
||
7180 | 30 |
{$IFDEF UNIX} |
31 |
{$LINKLIB avwrapper} |
|
32 |
{$LINKLIB avutil} |
|
33 |
{$LINKLIB avcodec} |
|
34 |
{$LINKLIB avformat} |
|
35 |
{$ENDIF} |
|
36 |
||
37 |
interface |
|
38 |
||
39 |
var flagPrerecording: boolean = false; |
|
40 |
||
41 |
function BeginVideoRecording: Boolean; |
|
42 |
function LoadNextCameraPosition: LongInt; |
|
43 |
procedure EncodeFrame; |
|
44 |
procedure StopVideoRecording; |
|
45 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
46 |
procedure BeginPreRecording; |
7180 | 47 |
procedure StopPreRecording; |
48 |
procedure SaveCameraPosition; |
|
49 |
||
50 |
procedure freeModule; |
|
51 |
||
52 |
implementation |
|
53 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
54 |
uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO; |
7180 | 55 |
|
56 |
{$IFDEF WIN32} |
|
57 |
const AVWrapperLibName = 'libavwrapper.dll'; |
|
58 |
{$ENDIF} |
|
59 |
||
60 |
type TAddFileLogRaw = procedure (s: pchar); cdecl; |
|
61 |
||
62 |
{$IFDEF WIN32} |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
63 |
procedure AVWrapper_Init( |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
64 |
AddLog: TAddFileLogRaw; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
65 |
filename, desc, soundFile, format, vcodec, acodec, preset: PChar; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
66 |
width, height, framerateNum, framerateDen, vquality, aquality: LongInt); cdecl; external AVWrapperLibName; |
7180 | 67 |
procedure AVWrapper_Close; cdecl; external AVWrapperLibName; |
68 |
procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external AVWrapperLibName; |
|
69 |
{$ELSE} |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
70 |
procedure AVWrapper_Init( |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
71 |
AddLog: TAddFileLogRaw; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
72 |
filename, desc, soundFile, format, vcodec, acodec, preset: PChar; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
73 |
width, height, framerateNum, framerateDen, vquality, aquality: LongInt); cdecl; external; |
7180 | 74 |
procedure AVWrapper_Close; cdecl; external; |
75 |
procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external; |
|
76 |
{$ENDIF} |
|
77 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
78 |
type TFrame = record |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
79 |
ticks: LongWord; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
80 |
CamX, CamY: LongInt; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
81 |
zoom: single; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
82 |
end; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
83 |
|
7180 | 84 |
var YCbCr_Planes: array[0..2] of PByte; |
85 |
RGB_Buffer: PByte; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
86 |
cameraFile: File of TFrame; |
7180 | 87 |
audioFile: File; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
88 |
numPixels: LongWord; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
89 |
startTime, numFrames: LongWord; |
7180 | 90 |
cameraFilePath, soundFilePath: shortstring; |
91 |
||
92 |
function BeginVideoRecording: Boolean; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
93 |
var filename, desc: shortstring; |
7180 | 94 |
begin |
95 |
AddFileLog('BeginVideoRecording'); |
|
96 |
||
97 |
numPixels:= cScreenWidth*cScreenHeight; |
|
98 |
||
99 |
{$IOCHECKS OFF} |
|
100 |
// open file with prerecorded camera positions |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
101 |
cameraFilePath:= UserPathPrefix + '/VideoTemp/' + cRecPrefix + '.txtin'; |
7180 | 102 |
Assign(cameraFile, cameraFilePath); |
103 |
Reset(cameraFile); |
|
104 |
if IOResult <> 0 then |
|
105 |
begin |
|
106 |
AddFileLog('Error: Could not read from ' + cameraFilePath); |
|
107 |
exit(false); |
|
108 |
end; |
|
109 |
{$IOCHECKS ON} |
|
110 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
111 |
desc:= ''; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
112 |
if UserNick <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
113 |
desc+= 'Player: ' + UserNick + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
114 |
if recordFileName <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
115 |
desc+= 'Record: ' + recordFileName + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
116 |
if cMapName <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
117 |
desc+= 'Map: ' + cMapName + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
118 |
if Theme <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
119 |
desc+= 'Theme: ' + Theme + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
120 |
desc+= #0; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
121 |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
122 |
filename:= UserPathPrefix + '/VideoTemp/' + cRecPrefix + #0; |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
123 |
soundFilePath:= UserPathPrefix + '/VideoTemp/' + cRecPrefix + '.sw' + #0; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
124 |
cAVFormat+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
125 |
cAudioCodec+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
126 |
cVideoCodec+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
127 |
cVideoPreset+= #0; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
128 |
AVWrapper_Init(@AddFileLogRaw, @filename[1], @desc[1], @soundFilePath[1], @cAVFormat[1], @cVideoCodec[1], @cAudioCodec[1], @cVideoPreset[1], |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
129 |
cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cAudioQuality, cVideoQuality); |
7180 | 130 |
|
131 |
YCbCr_Planes[0]:= GetMem(numPixels); |
|
132 |
YCbCr_Planes[1]:= GetMem(numPixels div 4); |
|
133 |
YCbCr_Planes[2]:= GetMem(numPixels div 4); |
|
134 |
||
135 |
if (YCbCr_Planes[0] = nil) or (YCbCr_Planes[1] = nil) or (YCbCr_Planes[2] = nil) then |
|
136 |
begin |
|
137 |
AddFileLog('Error: Could not allocate memory for video recording (YCbCr buffer).'); |
|
138 |
exit(false); |
|
139 |
end; |
|
140 |
||
141 |
RGB_Buffer:= GetMem(4*numPixels); |
|
142 |
if RGB_Buffer = nil then |
|
143 |
begin |
|
144 |
AddFileLog('Error: Could not allocate memory for video recording (RGB buffer).'); |
|
145 |
exit(false); |
|
146 |
end; |
|
147 |
||
148 |
BeginVideoRecording:= true; |
|
149 |
end; |
|
150 |
||
151 |
procedure StopVideoRecording; |
|
152 |
begin |
|
153 |
AddFileLog('StopVideoRecording'); |
|
154 |
FreeMem(YCbCr_Planes[0], numPixels); |
|
155 |
FreeMem(YCbCr_Planes[1], numPixels div 4); |
|
156 |
FreeMem(YCbCr_Planes[2], numPixels div 4); |
|
157 |
FreeMem(RGB_Buffer, 4*numPixels); |
|
158 |
Close(cameraFile); |
|
159 |
AVWrapper_Close(); |
|
160 |
DeleteFile(cameraFilePath); |
|
161 |
DeleteFile(soundFilePath); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
162 |
SendIPC(_S'v'); |
7180 | 163 |
end; |
164 |
||
165 |
function pixel(x, y, color: LongInt): LongInt; |
|
166 |
begin |
|
167 |
pixel:= RGB_Buffer[(cScreenHeight-y-1)*cScreenWidth*4 + x*4 + color]; |
|
168 |
end; |
|
169 |
||
170 |
procedure EncodeFrame; |
|
171 |
var x, y, r, g, b: LongInt; |
|
172 |
begin |
|
173 |
// read pixels from OpenGL |
|
174 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, RGB_Buffer); |
|
175 |
||
176 |
// convert to YCbCr 4:2:0 format |
|
177 |
// Y |
|
178 |
for y := 0 to cScreenHeight-1 do |
|
179 |
for x := 0 to cScreenWidth-1 do |
|
180 |
YCbCr_Planes[0][y*cScreenWidth + x]:= Byte(16 + ((16828*pixel(x,y,0) + 33038*pixel(x,y,1) + 6416*pixel(x,y,2)) shr 16)); |
|
181 |
||
182 |
// Cb and Cr |
|
183 |
for y := 0 to cScreenHeight div 2 - 1 do |
|
184 |
for x := 0 to cScreenWidth div 2 - 1 do |
|
185 |
begin |
|
186 |
r:= pixel(2*x,2*y,0) + pixel(2*x+1,2*y,0) + pixel(2*x,2*y+1,0) + pixel(2*x+1,2*y+1,0); |
|
187 |
g:= pixel(2*x,2*y,1) + pixel(2*x+1,2*y,1) + pixel(2*x,2*y+1,1) + pixel(2*x+1,2*y+1,1); |
|
188 |
b:= pixel(2*x,2*y,2) + pixel(2*x+1,2*y,2) + pixel(2*x,2*y+1,2) + pixel(2*x+1,2*y+1,2); |
|
189 |
YCbCr_Planes[1][y*(cScreenWidth div 2) + x]:= Byte(128 + ((-2428*r - 4768*g + 7196*b) shr 16)); |
|
190 |
YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16)); |
|
191 |
end; |
|
192 |
||
193 |
AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
194 |
|
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
195 |
// inform frontend that we have encoded new frame (p for progress) |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
196 |
SendIPC(_S'p'); |
7180 | 197 |
end; |
198 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
199 |
// returns new game ticks |
7180 | 200 |
function LoadNextCameraPosition: LongInt; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
201 |
var frame: TFrame; |
7180 | 202 |
begin |
203 |
{$IOCHECKS OFF} |
|
204 |
if eof(cameraFile) then |
|
205 |
exit(-1); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
206 |
BlockRead(cameraFile, frame, 1); |
7180 | 207 |
{$IOCHECKS ON} |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
208 |
WorldDx:= frame.CamX; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
209 |
WorldDy:= frame.CamY + cScreenHeight div 2; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
210 |
zoom:= frame.zoom*cScreenWidth; |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
211 |
ZoomValue:= zoom; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
212 |
LoadNextCameraPosition:= frame.ticks; |
7180 | 213 |
end; |
214 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
215 |
// 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
|
216 |
// This procedure may be called from different thread. |
7180 | 217 |
procedure RecordPostMix(udata: pointer; stream: PByte; len: LongInt); cdecl; |
218 |
begin |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
219 |
udata:= udata; // avoid warning |
7180 | 220 |
{$IOCHECKS OFF} |
221 |
BlockWrite(audioFile, stream^, len); |
|
222 |
{$IOCHECKS ON} |
|
223 |
end; |
|
224 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
225 |
procedure BeginPreRecording; |
7180 | 226 |
var format: word; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
227 |
filePrefix, filename: shortstring; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
228 |
frequency, channels: LongInt; |
7180 | 229 |
begin |
230 |
AddFileLog('BeginPreRecording'); |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
231 |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
232 |
numFrames:= 0; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
233 |
startTime:= SDL_GetTicks(); |
7180 | 234 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
235 |
filePrefix:= FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
236 |
|
7180 | 237 |
Mix_QuerySpec(@frequency, @format, @channels); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
238 |
AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels)); |
7180 | 239 |
if format <> $8010 then |
240 |
begin |
|
241 |
// TODO: support any audio format |
|
242 |
AddFileLog('Error: Unexpected audio format ' + IntToStr(format)); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
243 |
exit; |
7180 | 244 |
end; |
245 |
||
246 |
{$IOCHECKS OFF} |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
247 |
// create sound file |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
248 |
filename:= UserPathPrefix + '/VideoTemp/' + filePrefix + '.sw'; |
7180 | 249 |
Assign(audioFile, filename); |
250 |
Rewrite(audioFile, 1); |
|
251 |
if IOResult <> 0 then |
|
252 |
begin |
|
253 |
AddFileLog('Error: Could not write to ' + filename); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
254 |
exit; |
7180 | 255 |
end; |
256 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
257 |
// create file with camera positions |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
258 |
filename:= UserPathPrefix + '/VideoTemp/' + filePrefix + '.txtout'; |
7180 | 259 |
Assign(cameraFile, filename); |
260 |
Rewrite(cameraFile); |
|
261 |
if IOResult <> 0 then |
|
262 |
begin |
|
263 |
AddFileLog('Error: Could not write to ' + filename); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
264 |
exit; |
7180 | 265 |
end; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
266 |
|
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
267 |
BlockWrite(audioFile, frequency, 4); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
268 |
BlockWrite(audioFile, channels, 4); |
7180 | 269 |
{$IOCHECKS ON} |
270 |
||
271 |
// register callback for actual audio recording |
|
272 |
Mix_SetPostMix(@RecordPostMix, nil); |
|
273 |
||
274 |
flagPrerecording:= true; |
|
275 |
end; |
|
276 |
||
277 |
procedure StopPreRecording; |
|
278 |
begin |
|
279 |
AddFileLog('StopPreRecording'); |
|
280 |
flagPrerecording:= false; |
|
281 |
||
282 |
// call SDL_LockAudio because RecordPostMix may be executing right now |
|
283 |
SDL_LockAudio(); |
|
284 |
Close(audioFile); |
|
285 |
Close(cameraFile); |
|
286 |
Mix_SetPostMix(nil, nil); |
|
287 |
SDL_UnlockAudio(); |
|
288 |
end; |
|
289 |
||
290 |
procedure SaveCameraPosition; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
291 |
var curTime: LongInt; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
292 |
frame: TFrame; |
7180 | 293 |
begin |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
294 |
curTime:= SDL_GetTicks(); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
295 |
while Int64(curTime - startTime)*cVideoFramerateNum > Int64(numFrames)*cVideoFramerateDen*1000 do |
7180 | 296 |
begin |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
297 |
frame.ticks:= GameTicks; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
298 |
frame.CamX:= WorldDx; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
299 |
frame.CamY:= WorldDy - cScreenHeight div 2; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
300 |
frame.zoom:= zoom/cScreenWidth; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
301 |
BlockWrite(cameraFile, frame, 1); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
302 |
inc(numFrames); |
7180 | 303 |
end; |
304 |
end; |
|
305 |
||
306 |
procedure freeModule; |
|
307 |
begin |
|
308 |
if flagPrerecording then |
|
309 |
StopPreRecording(); |
|
310 |
end; |
|
311 |
||
312 |
end. |
|
7286 | 313 |
|
314 |
{$ENDIF} // USE_VIDEO_RECORDING |