mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Ensure all images have same file extension and handle that
This commit is contained in:
parent
e32dd3a7f7
commit
ad5dca3cd6
2 changed files with 24 additions and 16 deletions
|
@ -66,25 +66,34 @@ public static async Task<bool> SnapshotAsync(string input, string output, Size?
|
||||||
/// <returns>Output video information.</returns>
|
/// <returns>Output video information.</returns>
|
||||||
public static bool JoinImageSequence(string output, double frameRate = 30, params string[] images)
|
public static bool JoinImageSequence(string output, double frameRate = 30, params string[] images)
|
||||||
{
|
{
|
||||||
|
var fileExtensions = images.Select(Path.GetExtension).Distinct().ToArray();
|
||||||
|
if (fileExtensions.Length != 1)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("All images must have the same extension", nameof(images));
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileExtension = fileExtensions[0].ToLowerInvariant();
|
||||||
int? width = null, height = null;
|
int? width = null, height = null;
|
||||||
|
|
||||||
var tempFolderName = Path.Combine(GlobalFFOptions.Current.TemporaryFilesFolder, Guid.NewGuid().ToString());
|
var tempFolderName = Path.Combine(GlobalFFOptions.Current.TemporaryFilesFolder, Guid.NewGuid().ToString());
|
||||||
var temporaryImageFiles = images.Select((imagePath, index) =>
|
Directory.CreateDirectory(tempFolderName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var index = 0;
|
||||||
|
foreach (var imagePath in images)
|
||||||
{
|
{
|
||||||
var analysis = FFProbe.Analyse(imagePath);
|
var analysis = FFProbe.Analyse(imagePath);
|
||||||
FFMpegHelper.ConversionSizeExceptionCheck(analysis.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Height);
|
FFMpegHelper.ConversionSizeExceptionCheck(analysis.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Height);
|
||||||
width ??= analysis.PrimaryVideoStream.Width;
|
width ??= analysis.PrimaryVideoStream.Width;
|
||||||
height ??= analysis.PrimaryVideoStream.Height;
|
height ??= analysis.PrimaryVideoStream.Height;
|
||||||
|
|
||||||
var destinationPath = Path.Combine(tempFolderName, $"{index.ToString().PadLeft(9, '0')}{Path.GetExtension(imagePath)}");
|
var destinationPath = Path.Combine(tempFolderName, $"{index++.ToString().PadLeft(9, '0')}{fileExtension}");
|
||||||
Directory.CreateDirectory(tempFolderName);
|
|
||||||
File.Copy(imagePath, destinationPath);
|
File.Copy(imagePath, destinationPath);
|
||||||
return destinationPath;
|
}
|
||||||
}).ToArray();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return FFMpegArguments
|
return FFMpegArguments
|
||||||
.FromFileInput(Path.Combine(tempFolderName, "%09d.png"), false)
|
.FromFileInput(Path.Combine(tempFolderName, $"%09d{fileExtension}"), false)
|
||||||
.OutputToFile(output, true, options => options
|
.OutputToFile(output, true, options => options
|
||||||
.ForcePixelFormat("yuv420p")
|
.ForcePixelFormat("yuv420p")
|
||||||
.Resize(width!.Value, height!.Value)
|
.Resize(width!.Value, height!.Value)
|
||||||
|
@ -93,8 +102,7 @@ public static bool JoinImageSequence(string output, double frameRate = 30, param
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Cleanup(temporaryImageFiles);
|
Directory.Delete(tempFolderName, true);
|
||||||
Directory.Delete(tempFolderName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<IsPackable>true</IsPackable>
|
<IsPackable>true</IsPackable>
|
||||||
<Description>A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications</Description>
|
<Description>A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications</Description>
|
||||||
<PackageVersion>5.0.0</PackageVersion>
|
<PackageVersion>5.0.1</PackageVersion>
|
||||||
<PackageReleaseNotes>
|
<PackageReleaseNotes>
|
||||||
</PackageReleaseNotes>
|
</PackageReleaseNotes>
|
||||||
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
||||||
|
|
Loading…
Reference in a new issue