mirror of
https://github.com/immich-app/immich.git
synced 2025-12-07 21:30:59 -08:00
Compare commits
2 Commits
fix/docs-c
...
feat/serve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f48318168b | ||
|
|
dda736840b |
File diff suppressed because it is too large
Load Diff
@@ -188,6 +188,7 @@ export class MediaService {
|
|||||||
const { image, ffmpeg } = await this.configCore.getConfig();
|
const { image, ffmpeg } = await this.configCore.getConfig();
|
||||||
const size = type === AssetPathType.PREVIEW ? image.previewSize : image.thumbnailSize;
|
const size = type === AssetPathType.PREVIEW ? image.previewSize : image.thumbnailSize;
|
||||||
const path = StorageCore.getImagePath(asset, type, format);
|
const path = StorageCore.getImagePath(asset, type, format);
|
||||||
|
const tmpPath = `${StorageCore.getTempPathInDir(dirname(path))}.${format}`;
|
||||||
this.storageCore.ensureFolders(path);
|
this.storageCore.ensureFolders(path);
|
||||||
|
|
||||||
switch (asset.type) {
|
switch (asset.type) {
|
||||||
@@ -201,8 +202,11 @@ export class MediaService {
|
|||||||
const colorspace = this.isSRGB(asset) ? Colorspace.SRGB : image.colorspace;
|
const colorspace = this.isSRGB(asset) ? Colorspace.SRGB : image.colorspace;
|
||||||
const imageOptions = { format, size, colorspace, quality: image.quality };
|
const imageOptions = { format, size, colorspace, quality: image.quality };
|
||||||
|
|
||||||
const outputPath = useExtracted ? extractedPath : asset.originalPath;
|
const inputPath = useExtracted ? extractedPath : asset.originalPath;
|
||||||
await this.mediaRepository.generateThumbnail(outputPath, path, imageOptions);
|
await this.mediaRepository.generateThumbnail(inputPath, tmpPath, imageOptions);
|
||||||
|
} catch (error) {
|
||||||
|
await this.storageRepository.unlink(tmpPath);
|
||||||
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
if (didExtract) {
|
if (didExtract) {
|
||||||
await this.storageRepository.unlink(extractedPath);
|
await this.storageRepository.unlink(extractedPath);
|
||||||
@@ -221,7 +225,12 @@ export class MediaService {
|
|||||||
const mainAudioStream = this.getMainStream(audioStreams);
|
const mainAudioStream = this.getMainStream(audioStreams);
|
||||||
const config = ThumbnailConfig.create({ ...ffmpeg, targetResolution: size.toString() });
|
const config = ThumbnailConfig.create({ ...ffmpeg, targetResolution: size.toString() });
|
||||||
const options = config.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream);
|
const options = config.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream);
|
||||||
await this.mediaRepository.transcode(asset.originalPath, path, options);
|
try {
|
||||||
|
await this.mediaRepository.transcode(asset.originalPath, tmpPath, options);
|
||||||
|
} catch (error) {
|
||||||
|
await this.storageRepository.unlink(tmpPath);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,6 +238,9 @@ export class MediaService {
|
|||||||
throw new UnsupportedMediaTypeException(`Unsupported asset type for thumbnail generation: ${asset.type}`);
|
throw new UnsupportedMediaTypeException(`Unsupported asset type for thumbnail generation: ${asset.type}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.storageRepository.rename(tmpPath, path);
|
||||||
|
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
`Successfully generated ${format.toUpperCase()} ${asset.type.toLowerCase()} ${type} for asset ${asset.id}`,
|
`Successfully generated ${format.toUpperCase()} ${asset.type.toLowerCase()} ${type} for asset ${asset.id}`,
|
||||||
);
|
);
|
||||||
@@ -340,8 +352,9 @@ export class MediaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log(`Started encoding video ${asset.id} ${JSON.stringify(command)}`);
|
this.logger.log(`Started encoding video ${asset.id} ${JSON.stringify(command)}`);
|
||||||
|
const tmpPath = StorageCore.getTempPathInDir(dirname(output));
|
||||||
try {
|
try {
|
||||||
await this.mediaRepository.transcode(input, output, command);
|
await this.mediaRepository.transcode(input, tmpPath, command);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
if (ffmpeg.accel !== TranscodeHWAccel.DISABLED) {
|
if (ffmpeg.accel !== TranscodeHWAccel.DISABLED) {
|
||||||
@@ -349,11 +362,20 @@ export class MediaService {
|
|||||||
`Error occurred during transcoding. Retrying with ${ffmpeg.accel.toUpperCase()} acceleration disabled.`,
|
`Error occurred during transcoding. Retrying with ${ffmpeg.accel.toUpperCase()} acceleration disabled.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const config = BaseConfig.create({ ...ffmpeg, accel: TranscodeHWAccel.DISABLED });
|
|
||||||
command = config.getCommand(target, mainVideoStream, mainAudioStream);
|
try {
|
||||||
await this.mediaRepository.transcode(input, output, command);
|
const config = BaseConfig.create({ ...ffmpeg, accel: TranscodeHWAccel.DISABLED });
|
||||||
|
command = config.getCommand(target, mainVideoStream, mainAudioStream);
|
||||||
|
await this.mediaRepository.transcode(input, tmpPath, command);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
await this.storageRepository.unlink(tmpPath);
|
||||||
|
return JobStatus.FAILED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.storageRepository.rename(tmpPath, output);
|
||||||
|
|
||||||
this.logger.log(`Successfully encoded ${asset.id}`);
|
this.logger.log(`Successfully encoded ${asset.id}`);
|
||||||
|
|
||||||
await this.assetRepository.update({ id: asset.id, encodedVideoPath: output });
|
await this.assetRepository.update({ id: asset.id, encodedVideoPath: output });
|
||||||
|
|||||||
Reference in New Issue
Block a user