summaryrefslogtreecommitdiff
path: root/src/lib/ffmpeg_file_encoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-09-06 17:15:46 +0200
committerCarl Hetherington <cth@carlh.net>2025-09-06 17:15:46 +0200
commit24052ed1b36e0ce81fb863830a93f8282285f30d (patch)
treea3544b1b8efeac24ef37776b9b09eb479ee27625 /src/lib/ffmpeg_file_encoder.cc
parent307264b52c70ca0a79831240874fcb2278ebac89 (diff)
Fix incorrectly-clipped audio on export (possibly #2865).
Diffstat (limited to 'src/lib/ffmpeg_file_encoder.cc')
-rw-r--r--src/lib/ffmpeg_file_encoder.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc
index e63d92d5b..9f391df5d 100644
--- a/src/lib/ffmpeg_file_encoder.cc
+++ b/src/lib/ffmpeg_file_encoder.cc
@@ -26,6 +26,7 @@
#include "image.h"
#include "job.h"
#include "log.h"
+#include "maths_util.h"
#include "player.h"
#include "player_video.h"
extern "C" {
@@ -151,7 +152,7 @@ public:
int16_t* q = reinterpret_cast<int16_t*>(samples);
for (int i = 0; i < size; ++i) {
for (int j = 0; j < channels; ++j) {
- *q++ = data[j + channel_offset][i] * 32767;
+ *q++ = clamp(std::lround(data[j + channel_offset][i] * 32767), -32768L, 32767L);
}
}
break;
@@ -161,7 +162,7 @@ public:
int32_t* q = reinterpret_cast<int32_t*>(samples);
for (int i = 0; i < size; ++i) {
for (int j = 0; j < channels; ++j) {
- *q++ = data[j + channel_offset][i] * 2147483647;
+ *q++ = clamp(std::llround(data[j + channel_offset][i] * 2147483647.0), -2147483648LL, 2147483647LL);
}
}
break;