1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-26 10:50:29 +02:00

feat(server): option to transcode to original resolution (#2709)

* option to transcode to original resolution

* changed value for target res setting

* updated test, clarified scaling condition
This commit is contained in:
Mert 2023-06-10 00:15:12 -04:00 committed by GitHub
parent e3694695ae
commit 9cdec62918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View File

@ -259,6 +259,23 @@ describe(MediaService.name, () => {
); );
}); });
it('should not scale resolution if no target resolution', async () => {
mediaMock.probe.mockResolvedValue(probeStub.videoStream2160p);
configMock.load.mockResolvedValue([
{ key: SystemConfigKey.FFMPEG_TRANSCODE, value: 'all' },
{ key: SystemConfigKey.FFMPEG_TARGET_RESOLUTION, value: 'original' },
]);
await sut.handleVideoConversion({ id: assetEntityStub.video.id });
expect(mediaMock.transcode).toHaveBeenCalledWith(
'/original/path.ext',
'upload/encoded-video/user-id/asset-id.mp4',
{
outputOptions: ['-vcodec h264', '-acodec aac', '-movflags faststart', '-preset ultrafast', '-crf 23'],
twoPass: false,
},
);
});
it('should transcode with alternate scaling video is vertical', async () => { it('should transcode with alternate scaling video is vertical', async () => {
mediaMock.probe.mockResolvedValue(probeStub.videoStreamVertical2160p); mediaMock.probe.mockResolvedValue(probeStub.videoStreamVertical2160p);
configMock.load.mockResolvedValue([{ key: SystemConfigKey.FFMPEG_TRANSCODE, value: 'optimal' }]); configMock.load.mockResolvedValue([{ key: SystemConfigKey.FFMPEG_TRANSCODE, value: 'optimal' }]);

View File

@ -179,9 +179,9 @@ export class MediaService {
); );
const allTargetsMatching = isTargetVideoCodec && isTargetAudioCodec && isTargetContainer; const allTargetsMatching = isTargetVideoCodec && isTargetAudioCodec && isTargetContainer;
const scalingEnabled = ffmpegConfig.targetResolution !== 'original';
const targetResolution = Number.parseInt(ffmpegConfig.targetResolution); const targetRes = Number.parseInt(ffmpegConfig.targetResolution);
const isLargerThanTargetResolution = Math.min(videoStream.height, videoStream.width) > targetResolution; const isLargerThanTargetRes = scalingEnabled && Math.min(videoStream.height, videoStream.width) > targetRes;
switch (ffmpegConfig.transcode) { switch (ffmpegConfig.transcode) {
case TranscodePreset.DISABLED: case TranscodePreset.DISABLED:
@ -194,7 +194,7 @@ export class MediaService {
return !allTargetsMatching; return !allTargetsMatching;
case TranscodePreset.OPTIMAL: case TranscodePreset.OPTIMAL:
return !allTargetsMatching || isLargerThanTargetResolution; return !allTargetsMatching || isLargerThanTargetRes;
default: default:
return false; return false;
@ -212,10 +212,11 @@ export class MediaService {
// video dimensions // video dimensions
const videoIsRotated = Math.abs(stream.rotation) === 90; const videoIsRotated = Math.abs(stream.rotation) === 90;
const scalingEnabled = ffmpeg.targetResolution !== 'original';
const targetResolution = Number.parseInt(ffmpeg.targetResolution); const targetResolution = Number.parseInt(ffmpeg.targetResolution);
const isVideoVertical = stream.height > stream.width || videoIsRotated; const isVideoVertical = stream.height > stream.width || videoIsRotated;
const scaling = isVideoVertical ? `${targetResolution}:-2` : `-2:${targetResolution}`; const scaling = isVideoVertical ? `${targetResolution}:-2` : `-2:${targetResolution}`;
const shouldScale = Math.min(stream.height, stream.width) > targetResolution; const shouldScale = scalingEnabled && Math.min(stream.height, stream.width) > targetResolution;
// video codec // video codec
const isVP9 = ffmpeg.targetVideoCodec === 'vp9'; const isVP9 = ffmpeg.targetVideoCodec === 'vp9';

View File

@ -143,7 +143,8 @@
{ value: '1440', text: '1440p' }, { value: '1440', text: '1440p' },
{ value: '1080', text: '1080p' }, { value: '1080', text: '1080p' },
{ value: '720', text: '720p' }, { value: '720', text: '720p' },
{ value: '480', text: '480p' } { value: '480', text: '480p' },
{ value: 'original', text: 'original' }
]} ]}
name="resolution" name="resolution"
isEdited={!(ffmpegConfig.targetResolution == savedConfig.targetResolution)} isEdited={!(ffmpegConfig.targetResolution == savedConfig.targetResolution)}