@@ -132,6 +132,44 @@ begin |
| 132 |
CancelButton.Enabled := Rendering and not CancelRequested; |
132 |
CancelButton.Enabled := Rendering and not CancelRequested; |
| 133 |
end; |
133 |
end; |
| 134 |
|
134 |
|
|
|
135 |
procedure DrainAndWaitForProcesses(const Procs: array of TProcess); |
|
|
136 |
var |
|
|
137 |
AllDone: Boolean; |
|
|
138 |
I, Avail: Integer; |
|
|
139 |
Discard: array[0..4095] of Byte; |
|
|
140 |
begin |
|
|
141 |
repeat |
|
|
142 |
AllDone := True; |
|
|
143 |
for I := Low(Procs) to High(Procs) do begin |
|
|
144 |
if Procs[I] = nil then Continue; |
|
|
145 |
|
|
|
146 |
if Procs[I].Output <> nil then begin |
|
|
147 |
Avail := Procs[I].Output.NumBytesAvailable; |
|
|
148 |
while Avail > 0 do begin |
|
|
149 |
if Avail > SizeOf(Discard) then Avail := SizeOf(Discard); |
|
|
150 |
Procs[I].Output.Read(Discard, Avail); |
|
|
151 |
Avail := Procs[I].Output.NumBytesAvailable; |
|
|
152 |
end; |
|
|
153 |
end; |
|
|
154 |
|
|
|
155 |
if Procs[I].Stderr <> nil then begin |
|
|
156 |
Avail := Procs[I].Stderr.NumBytesAvailable; |
|
|
157 |
while Avail > 0 do begin |
|
|
158 |
if Avail > SizeOf(Discard) then Avail := SizeOf(Discard); |
|
|
159 |
Procs[I].Stderr.Read(Discard, Avail); |
|
|
160 |
Avail := Procs[I].Stderr.NumBytesAvailable; |
|
|
161 |
end; |
|
|
162 |
end; |
|
|
163 |
|
|
|
164 |
if Procs[I].Running then AllDone := False; |
|
|
165 |
end; |
|
|
166 |
if not AllDone then begin |
|
|
167 |
Application.ProcessMessages; |
|
|
168 |
Sleep(100); |
|
|
169 |
end; |
|
|
170 |
until AllDone; |
|
|
171 |
end; |
|
|
172 |
|
| 135 |
function TfrmRenderToWave.CreateFFMPEGProcess(const DestFilename: String): TProcess; |
173 |
function TfrmRenderToWave.CreateFFMPEGProcess(const DestFilename: String): TProcess; |
| 136 |
begin |
174 |
begin |
| 137 |
Result := TProcess.Create(nil); |
175 |
Result := TProcess.Create(nil); |
@@ -212,16 +250,16 @@ begin |
| 212 |
|
250 |
|
| 213 |
finally |
251 |
finally |
| 214 |
EndWritingSoundToStream; |
252 |
EndWritingSoundToStream; |
|
|
253 |
|
| 215 |
MixProc.CloseInput; |
254 |
MixProc.CloseInput; |
| 216 |
MixProc.WaitOnExit; |
255 |
for I := 1 to 4 do |
| 217 |
MixProc.Free; |
256 |
if ChanProcs[I] <> nil then ChanProcs[I].CloseInput; |
|
|
257 |
|
|
|
258 |
DrainAndWaitForProcesses([MixProc, ChanProcs[1], ChanProcs[2], ChanProcs[3], ChanProcs[4]]); |
| 218 |
|
259 |
|
|
|
260 |
MixProc.Free; |
| 219 |
for I := 1 to 4 do |
261 |
for I := 1 to 4 do |
| 220 |
if ChanProcs[I] <> nil then begin |
262 |
if ChanProcs[I] <> nil then ChanProcs[I].Free; |
| 221 |
ChanProcs[I].CloseInput; |
|
|
| 222 |
ChanProcs[I].WaitOnExit; |
|
|
| 223 |
ChanProcs[I].Free; |
|
|
| 224 |
end; |
|
|
| 225 |
|
263 |
|
| 226 |
Panel1.Caption := 'Ready'; |
264 |
Panel1.Caption := 'Ready'; |
| 227 |
end; |
265 |
end; |