Skip to content

Commit

Permalink
chore(server)!: default max bitrate unit to kbps (immich-app#15264)
Browse files Browse the repository at this point in the history
default unit to kbps
  • Loading branch information
mertalev authored and vladd11 committed Jan 25, 2025
1 parent a5abfaf commit 02b76ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions server/src/services/media.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,22 @@ describe(MediaService.name, () => {
);
});

it('should default max bitrate to kbps if no unit is provided', async () => {
mediaMock.probe.mockResolvedValue(probeStub.matroskaContainer);
systemMock.get.mockResolvedValue({ ffmpeg: { maxBitrate: '4500' } });
assetMock.getByIds.mockResolvedValue([assetStub.video]);
await sut.handleVideoConversion({ id: assetStub.video.id });
expect(mediaMock.transcode).toHaveBeenCalledWith(
'/original/path.ext',
'upload/encoded-video/user-id/as/se/asset-id.mp4',
expect.objectContaining({
inputOptions: expect.any(Array),
outputOptions: expect.arrayContaining(['-c:v h264', '-maxrate 4500k', '-bufsize 9000k']),
twoPass: false,
}),
);
});

it('should transcode in two passes for h264/h265 when enabled and max bitrate is above 0', async () => {
mediaMock.probe.mockResolvedValue(probeStub.matroskaContainer);
systemMock.get.mockResolvedValue({ ffmpeg: { twoPass: true, maxBitrate: '4500k' } });
Expand Down
2 changes: 1 addition & 1 deletion server/src/utils/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class BaseConfig implements VideoCodecSWConfig {

getBitrateUnit() {
const maxBitrate = this.getMaxBitrateValue();
return this.config.maxBitrate.trim().slice(maxBitrate.toString().length); // use inputted unit if provided
return this.config.maxBitrate.trim().slice(maxBitrate.toString().length) || 'k'; // use inputted unit if provided, else default to kbps
}

getMaxBitrateValue() {
Expand Down

0 comments on commit 02b76ff

Please sign in to comment.