aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2026-03-30 18:39:37 +0200
committerGitHub <noreply@github.com>2026-03-30 18:39:37 +0200
commite4f01973b7034ae48617b1da1d1640545e005ded (patch)
treef76a95398bfa92a57ef070b543d109b58bfb1f3b
parent5f30a4538bb0dd06cabd9659eb8269a8038644fc (diff)
parent382db1da0dabf26d9fec1d809c76bbcec70418d5 (diff)
Merge pull request #16365 from Shadowghost/cleanup-trickplay-failure
Cleanup trickplay cache dir on failure
-rw-r--r--Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs102
1 files changed, 55 insertions, 47 deletions
diff --git a/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs b/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs
index 4505a377c..63319831e 100644
--- a/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs
+++ b/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs
@@ -399,64 +399,72 @@ public class TrickplayManager : ITrickplayManager
var workDir = Path.Combine(_appPaths.TempDirectory, "trickplay_" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(workDir);
- var trickplayInfo = new TrickplayInfo
+ try
{
- Width = width,
- Interval = options.Interval,
- TileWidth = options.TileWidth,
- TileHeight = options.TileHeight,
- ThumbnailCount = images.Count,
- // Set during image generation
- Height = 0,
- Bandwidth = 0
- };
-
- /*
- * Generate trickplay tiles from sets of thumbnails
- */
- var imageOptions = new ImageCollageOptions
- {
- Width = trickplayInfo.TileWidth,
- Height = trickplayInfo.TileHeight
- };
+ var trickplayInfo = new TrickplayInfo
+ {
+ Width = width,
+ Interval = options.Interval,
+ TileWidth = options.TileWidth,
+ TileHeight = options.TileHeight,
+ ThumbnailCount = images.Count,
+ // Set during image generation
+ Height = 0,
+ Bandwidth = 0
+ };
+
+ /*
+ * Generate trickplay tiles from sets of thumbnails
+ */
+ var imageOptions = new ImageCollageOptions
+ {
+ Width = trickplayInfo.TileWidth,
+ Height = trickplayInfo.TileHeight
+ };
- var thumbnailsPerTile = trickplayInfo.TileWidth * trickplayInfo.TileHeight;
- var requiredTiles = (int)Math.Ceiling((double)images.Count / thumbnailsPerTile);
+ var thumbnailsPerTile = trickplayInfo.TileWidth * trickplayInfo.TileHeight;
+ var requiredTiles = (int)Math.Ceiling((double)images.Count / thumbnailsPerTile);
- for (int i = 0; i < requiredTiles; i++)
- {
- // Set output/input paths
- var tilePath = Path.Combine(workDir, $"{i}.jpg");
+ for (int i = 0; i < requiredTiles; i++)
+ {
+ // Set output/input paths
+ var tilePath = Path.Combine(workDir, $"{i}.jpg");
- imageOptions.OutputPath = tilePath;
- imageOptions.InputPaths = images.Skip(i * thumbnailsPerTile).Take(Math.Min(thumbnailsPerTile, images.Count - (i * thumbnailsPerTile))).ToList();
+ imageOptions.OutputPath = tilePath;
+ imageOptions.InputPaths = images.Skip(i * thumbnailsPerTile).Take(Math.Min(thumbnailsPerTile, images.Count - (i * thumbnailsPerTile))).ToList();
- // Generate image and use returned height for tiles info
- var height = _imageEncoder.CreateTrickplayTile(imageOptions, options.JpegQuality, trickplayInfo.Width, trickplayInfo.Height != 0 ? trickplayInfo.Height : null);
- if (trickplayInfo.Height == 0)
- {
- trickplayInfo.Height = height;
+ // Generate image and use returned height for tiles info
+ var height = _imageEncoder.CreateTrickplayTile(imageOptions, options.JpegQuality, trickplayInfo.Width, trickplayInfo.Height != 0 ? trickplayInfo.Height : null);
+ if (trickplayInfo.Height == 0)
+ {
+ trickplayInfo.Height = height;
+ }
+
+ // Update bitrate
+ var bitrate = (int)Math.Ceiling(new FileInfo(tilePath).Length * 8m / trickplayInfo.TileWidth / trickplayInfo.TileHeight / (trickplayInfo.Interval / 1000m));
+ trickplayInfo.Bandwidth = Math.Max(trickplayInfo.Bandwidth, bitrate);
}
- // Update bitrate
- var bitrate = (int)Math.Ceiling(new FileInfo(tilePath).Length * 8m / trickplayInfo.TileWidth / trickplayInfo.TileHeight / (trickplayInfo.Interval / 1000m));
- trickplayInfo.Bandwidth = Math.Max(trickplayInfo.Bandwidth, bitrate);
- }
+ /*
+ * Move trickplay tiles to output directory
+ */
+ Directory.CreateDirectory(Directory.GetParent(outputDir)!.FullName);
+
+ // Replace existing tiles if they already exist
+ if (Directory.Exists(outputDir))
+ {
+ Directory.Delete(outputDir, true);
+ }
- /*
- * Move trickplay tiles to output directory
- */
- Directory.CreateDirectory(Directory.GetParent(outputDir)!.FullName);
+ _fileSystem.MoveDirectory(workDir, outputDir);
- // Replace existing tiles if they already exist
- if (Directory.Exists(outputDir))
+ return trickplayInfo;
+ }
+ catch
{
- Directory.Delete(outputDir, true);
+ Directory.Delete(workDir, true);
+ throw;
}
-
- _fileSystem.MoveDirectory(workDir, outputDir);
-
- return trickplayInfo;
}
private bool CanGenerateTrickplay(Video video, int interval)