+6
-1
src/components/composer/workers/gif-conversion.ts
+6
-1
src/components/composer/workers/gif-conversion.ts
···
18
18
19
19
{
20
20
const { image } = await decoder.decode({ frameIndex: 0 });
21
+
const { displayWidth, displayHeight } = image;
22
+
23
+
// Scale bitrate based on resolution (~5 Mbps at 1080p, sqrt curve for smaller sizes)
24
+
const pixels = displayWidth * displayHeight;
25
+
const bitrate = Math.max(500_000, Math.min(8_000_000, Math.round(Math.sqrt(pixels / (1920 * 1080)) * 5_000_000)));
21
26
22
27
output = new Output({
23
28
format: new WebMOutputFormat(),
24
29
target: new BufferTarget(),
25
30
});
26
31
27
-
videoSource = new VideoSampleSource({ codec: 'vp9', bitrate: 1e6 });
32
+
videoSource = new VideoSampleSource({ codec: 'vp9', bitrate });
28
33
output.addVideoTrack(videoSource);
29
34
30
35
await output.start();