Fix video recorder not working if sound disabled (fixes
bug #200)
--- a/ChangeLog.txt Wed Aug 01 23:12:37 2018 +0200
+++ b/ChangeLog.txt Tue Jul 17 12:17:11 2018 +0200
@@ -3,6 +3,7 @@
====================== 0.9.24.2 ====================
* Restore joystick/controller functionality
* Fix crash when starting game with 2 controllers or more
+ * Fix video recorder not recording if sound was disabled
* Fix insane amount of droplets appearing when shooting minigun into ocean world edge
* Limit number of droplets to 50 (temporary bugfix)
* Prevent creation of schemes with same name as an existing scheme
--- a/QTfrontend/net/recorder.cpp Wed Aug 01 23:12:37 2018 +0200
+++ b/QTfrontend/net/recorder.cpp Tue Jul 17 12:17:11 2018 +0200
@@ -140,7 +140,10 @@
// Could use a field to use quality instead. maybe quality could override bitrate - or just pass (and set) both.
// The library does support using both at once after all.
arguments << QString::number(config->rec_Bitrate()*1024);
- arguments << (config->recordAudio() ? config->audioCodec() : "no");
+ if (config->recordAudio() && (config->isSoundEnabled() || config->isMusicEnabled()))
+ arguments << config->audioCodec();
+ else
+ arguments << "no";
return arguments;
}
--- a/hedgewars/uVideoRec.pas Wed Aug 01 23:12:37 2018 +0200
+++ b/hedgewars/uVideoRec.pas Tue Jul 17 12:17:11 2018 +0200
@@ -73,7 +73,8 @@
numPixels: LongWord;
startTime, numFrames, curTime, progress, maxProgress: LongWord;
soundFilePath: shortstring;
- thumbnailSaved : Boolean;
+ thumbnailSaved: boolean;
+ recordAudio: boolean;
function BeginVideoRecording: Boolean;
var filename, desc: shortstring;
@@ -113,7 +114,12 @@
desc:= desc + 'prefix[' + RecPrefix + ']prefix';
filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix;
- soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
+
+ recordAudio:= (cAudioCodec <> 'no');
+ if recordAudio then
+ soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw'
+ else
+ soundFilePath:= '';
if checkFails(AVWrapper_Init(@AddFileLogRaw
, PChar(ansistring(filename))
@@ -149,7 +155,8 @@
if AVWrapper_Close() < 0 then
halt(-1);
Erase(cameraFile);
- DeleteFile(soundFilePath);
+ if recordAudio then
+ DeleteFile(soundFilePath);
SendIPC(_S'v'); // inform frontend that we finished
end;
@@ -268,43 +275,49 @@
CopyFile(recordFileName, UserPathPrefix + '/VideoTemp/' + RecPrefix + '.hwd');
end;
- Mix_QuerySpec(@frequency, @format, @channels);
- AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels));
- if format <> $8010 then
- begin
- // TODO: support any audio format
- AddFileLog('Error: Unexpected audio format ' + IntToStr(format));
- exit;
- end;
+ if cIsSoundEnabled then
+ begin
+ Mix_QuerySpec(@frequency, @format, @channels);
+ AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels));
+ if format <> $8010 then
+ begin
+ // TODO: support any audio format
+ AddFileLog('Error: Unexpected audio format ' + IntToStr(format));
+ exit;
+ end;
{$IOCHECKS OFF}
- // create sound file
- filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
- Assign(audioFile, filename);
- Rewrite(audioFile, 1);
- if IOResult <> 0 then
- begin
- AddFileLog('Error: Could not write to ' + filename);
- exit;
- end;
+ // create sound file
+ filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw';
+ Assign(audioFile, filename);
+ Rewrite(audioFile, 1);
+ if IOResult <> 0 then
+ begin
+ AddFileLog('Error: Could not write to ' + filename);
+ exit;
+ end;
+ end;
// create file with camera positions
filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.txtout';
Assign(cameraFile, filename);
Rewrite(cameraFile);
if IOResult <> 0 then
- begin
+ begin
AddFileLog('Error: Could not write to ' + filename);
exit;
- end;
+ end;
- // save audio parameters in sound file
- BlockWrite(audioFile, frequency, 4);
- BlockWrite(audioFile, channels, 4);
+ if cIsSoundEnabled then
+ begin
+ // save audio parameters in sound file
+ BlockWrite(audioFile, frequency, 4);
+ BlockWrite(audioFile, channels, 4);
{$IOCHECKS ON}
- // register callback for actual audio recording
- Mix_SetPostMix(@RecordPostMix, nil);
+ // register callback for actual audio recording
+ Mix_SetPostMix(@RecordPostMix, nil);
+ end;
startTime:= SDL_GetTicks();
flagPrerecording:= true;
@@ -315,12 +328,18 @@
AddFileLog('StopPreRecording');
flagPrerecording:= false;
- // call SDL_LockAudio because RecordPostMix may be executing right now
- SDL_LockAudio();
- Close(audioFile);
+ if cIsSoundEnabled then
+ begin
+ // call SDL_LockAudio because RecordPostMix may be executing right now
+ SDL_LockAudio();
+ Close(audioFile);
+ end
Close(cameraFile);
- Mix_SetPostMix(nil, nil);
- SDL_UnlockAudio();
+ if cIsSoundEnabled then
+ begin
+ Mix_SetPostMix(nil, nil);
+ SDL_UnlockAudio();
+ end;
if not thumbnailSaved then
SaveThumbnail();