Return dimensions

This commit is contained in:
Kieran
2023-12-26 18:20:15 +00:00
parent b9f989986a
commit a92e7d46fc
5 changed files with 39 additions and 10 deletions

View File

@@ -40,6 +40,7 @@ public class CompressContent
}
}
var ffProbe = await TryProbe(input, cts);
var probe = isImage ? await ImageFile.FromFileAsync(input) : default;
var ffmpeg = FFMpegArguments
.FromFileInput(input)
@@ -73,7 +74,9 @@ public class CompressContent
var result = await ffmpeg.ProcessAsynchronously();
return new(result, output)
{
MimeType = outMime
MimeType = outMime,
Width = ffProbe?.PrimaryVideoStream?.Width,
Height = ffProbe?.PrimaryVideoStream?.Height,
};
}
catch (Exception ex)
@@ -84,8 +87,24 @@ public class CompressContent
return new(false, output);
}
private async Task<IMediaAnalysis?> TryProbe(string path, CancellationToken cts)
{
try
{
return await FFProbe.AnalyseAsync(path, cancellationToken: cts);
}
catch
{
// ignored
}
return default;
}
public record CompressResult(bool Success, string OutPath)
{
public string? MimeType { get; init; }
public int? Width { get; init; }
public int? Height { get; init; }
}
}

View File

@@ -73,7 +73,8 @@ public class LocalDiskFileStore : StreamFileStore, IFileStore
Size = (ulong)fInfo.Length,
Digest = hash.ToHex(),
MimeType = res.MimeType ?? vf.MimeType,
OriginalDigest = originalHash.ToHex()
OriginalDigest = originalHash.ToHex(),
MediaDimensions = res is {Width: not null, Height: not null} ? $"{res.Width.Value}x{res.Height.Value}" : null
};
}
else