Compare commits

...

57 commits

Author SHA1 Message Date
Malte Rosenbjerg
1f164472c7
Merge branch 'main' into bugfix/ensure-ffmpeg-not-found-throws-ffmpegexception 2025-10-16 10:09:50 +02:00
Malte Rosenbjerg
53b3e0fbd0
Merge pull request #566 from GorobVictor/snapshot-formats
FEAT: added more extensions for snapshot(jpg, bmp, webp)
2025-10-16 10:08:25 +02:00
Malte Rosenbjerg
bfefa9560e
Merge branch 'main' into snapshot-formats 2025-10-16 10:00:56 +02:00
Malte Rosenbjerg
37b4119e13
Merge pull request #576 from rosenbjerg/migrate-to-macos-latest-test-runner-instead-of-macos-13
CI: Install ffmpeg using brew if running on arm64 macos
2025-10-16 09:59:48 +02:00
Malte Rosenbjerg
7e135a78d3 Use install step for installing ffmpeg 2025-10-16 09:55:50 +02:00
Malte Rosenbjerg
91c1629215 Add name labels to ffmpeg install steps 2025-10-16 09:53:09 +02:00
Malte Rosenbjerg
7036ad6df2 Switch on matrix.os instead of runner.os 2025-10-16 09:47:53 +02:00
Malte Rosenbjerg
5ba8122d00 Fix specified ffmpeg version 2025-10-16 09:41:34 +02:00
Malte Rosenbjerg
665c9f9213 Use full reference 2025-10-16 09:39:51 +02:00
Malte Rosenbjerg
fb10b78e35 Include github token to avoid rate limiting 2025-10-16 09:37:42 +02:00
Malte Rosenbjerg
99181e9f65 Include github token to avoid rate limiting 2025-10-16 09:37:27 +02:00
Malte Rosenbjerg
af6587d8fe Reference workflow action by reference 2025-10-16 09:37:04 +02:00
Malte Rosenbjerg
9c636d4059 Migrate to AnimMouse/setup-ffmpeg@v1 2025-10-16 09:32:23 +02:00
Malte Rosenbjerg
5d8d346598 Only lint on ubuntu-latest to not waste time 2025-10-16 09:32:11 +02:00
Malte Rosenbjerg
918ca9a9ab Remove accessibility modifiers on interface properties (IDE0040) 2025-10-16 09:22:09 +02:00
Malte Rosenbjerg
abb9f15eeb Use brew if running on arm64 macos 2025-10-16 09:19:05 +02:00
Malte Rosenbjerg
193ed43f1d
Merge branch 'main' into snapshot-formats 2025-09-09 08:23:41 +02:00
Malte Rosenbjerg
25d7ae8374
Merge pull request #572 from WeihanLi/patch-1
docs: update nuget badge
2025-09-09 08:21:05 +02:00
Weihan Li
bbfcfaefac
docs: update nuget badge 2025-07-21 17:08:22 +08:00
Victor Horobchuk
3d21599c5d FIX: for dotnet format 2025-04-17 13:17:52 +03:00
Victor Horobchuk
4025b82fbf FIX: small moments 2025-04-17 13:02:27 +03:00
Victor Horobchuk
aa1051b268 FEAT: added more extensions for snapshot(jpg, bmp, webp) 2025-04-17 12:29:06 +03:00
Malte Rosenbjerg
37973c3daf Use different ffmpeg version 2025-02-18 08:55:41 +01:00
Malte Rosenbjerg
0e9ceee8d9 Use different ffmpeg version 2025-02-18 08:50:36 +01:00
Malte Rosenbjerg
df08334765 Specify ffmpeg version used for CI 2025-02-18 08:45:58 +01:00
Malte Rosenbjerg
19c83b8661 Update property for Prepare FFMpeg CI step 2025-02-16 22:29:29 +01:00
Malte Rosenbjerg
cc1d9d4966 Only run CI for PRs 2025-02-16 22:29:15 +01:00
Malte Rosenbjerg
f5a8cf5de7 v 5.2.0 2025-02-16 22:17:13 +01:00
Malte Rosenbjerg
1c4333ee4c
Merge pull request #552 from rosenbjerg/bump-dependencies--instances
Some checks failed
CI / ci (macos-13) (push) Has been cancelled
CI / ci (ubuntu-latest) (push) Has been cancelled
CI / ci (windows-latest) (push) Has been cancelled
Bump Instances
2024-12-05 10:05:06 +01:00
Malte Rosenbjerg
855e6ece30 Bump Instances 2024-12-05 10:59:59 +02:00
Malte Rosenbjerg
6836b143c7
Merge pull request #551 from rosenbjerg/bump-dependencies
Some checks are pending
CI / ci (macos-13) (push) Waiting to run
CI / ci (ubuntu-latest) (push) Waiting to run
CI / ci (windows-latest) (push) Waiting to run
Bump packages
2024-12-04 23:07:53 +01:00
Malte Rosenbjerg
82387dfded
Merge branch 'main' into bump-dependencies 2024-12-04 21:54:58 +01:00
Malte Rosenbjerg
8656a86c47
Merge pull request #409 from rosenbjerg/chore/deterministic-dotnet-builds
Deterministic .NET builds
2024-12-04 21:54:39 +01:00
Malte Rosenbjerg
9d0f8893a5 Use codecov/codecov-action@v4 instead of 5 2024-12-04 22:25:36 +02:00
Malte Rosenbjerg
c7f8c19be7 Specify codecov os 2024-12-04 22:19:57 +02:00
Malte Rosenbjerg
217c1d99e2 Bump extension package nuget version 2024-12-04 22:16:22 +02:00
Malte Rosenbjerg
dedd913682 Bump packages 2024-12-04 22:15:02 +02:00
Malte Rosenbjerg
09faf340fb
Merge branch 'main' into chore/deterministic-dotnet-builds 2024-12-04 20:59:32 +01:00
Malte Rosenbjerg
71e36847a9
Merge pull request #505 from AddyMills/main
Add Multiple Input files
2024-12-04 20:59:10 +01:00
Malte Rosenbjerg
69535d6fdc dotnet format 2024-12-04 21:54:06 +02:00
Malte Rosenbjerg
40a3609d5d
Merge branch 'main' into main 2024-12-04 20:43:51 +01:00
AddyMills
8309951519 Reapply "Update JSON Reference"
This reverts commit aabd5cc3a8.
2024-11-16 20:09:24 -06:00
AddyMills
aabd5cc3a8 Revert "Update JSON Reference"
This reverts commit f3be9f2b77.
2024-11-16 20:07:57 -06:00
AddyMills
f3be9f2b77 Update JSON Reference 2024-11-16 19:50:29 -06:00
AddyMills
49c2941474 Remove JSON vulnerability Reference 2024-08-31 20:30:37 -06:00
Vlad Jerca
5e62d9ba36
Merge branch 'main' into chore/deterministic-dotnet-builds 2024-06-28 13:52:40 +02:00
AddyMills
94db493d19 Add IEnumerable tests for inputs 2024-03-03 18:56:06 -06:00
AddyMills
31b117d186 Remove whitespace 2024-03-03 13:09:52 -06:00
AddyMills
bb341e6dd7 Update one more instance of string[] to IEnumerable 2024-03-03 13:02:50 -06:00
AddyMills
622db9600c Add MultiInput Test 2024-03-03 12:49:34 -06:00
AddyMills
d836501681 Change string array to IEnumerable 2024-03-03 11:42:52 -06:00
AddyMills
8f6d1aa8e9 Update MultiInput to IEnumerable 2024-03-01 07:13:55 -06:00
AddyMills
8a764eccc7 Add MultiInputArgument 2024-03-01 07:08:16 -06:00
Malte Rosenbjerg
e9264a3c2a Update ci.yml 2023-02-22 17:52:56 +01:00
Malte Rosenbjerg
06f5bfa598 Update CI paths 2023-02-22 17:52:29 +01:00
Malte Rosenbjerg
cc2d9890f9 CI yaml fixes 2023-02-22 17:50:35 +01:00
Malte Rosenbjerg
86a500309d Set ContinuousIntegrationBuild to true 2023-02-22 17:49:09 +01:00
17 changed files with 334 additions and 73 deletions

View file

@ -1,28 +1,24 @@
name: CI
on:
push:
branches:
- master
paths:
- .github/workflows/ci.yml
- FFMpegCore/**
- FFMpegCore.Test/**
pull_request:
branches:
- main
- release
paths:
- .github/workflows/ci.yml
- FFMpegCore/**
- FFMpegCore.Test/**
- .github/workflows/ci.yml
- Directory.Build.props
- FFMpegCore/**
- FFMpegCore.Test/**
- FFMpegCore.Extensions.SkiaSharp/**
- FFMpegCore.Extensions.System.Drawing.Common/**
jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-13]
os: [windows-latest, ubuntu-latest, macos-latest]
timeout-minutes: 7
steps:
@ -34,21 +30,24 @@ jobs:
with:
dotnet-version: '8.0.x'
- name: Lint with dotnet
- if: matrix.os == 'ubuntu-latest'
name: Lint with dotnet
run: dotnet format FFMpegCore.sln --severity warn --verify-no-changes
- name: Prepare FFMpeg
uses: FedericoCarboni/setup-ffmpeg@v3
- name: Setup FFmpeg
uses: AnimMouse/setup-ffmpeg@ae28d57dabbb148eff63170b6bf7f2b60062cbae # 1.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ matrix.os != 'macos-latest' && '7.1' || '711' }}
token: ${{ github.token }}
- name: Test with dotnet
run: dotnet test FFMpegCore.sln --collect "XPlat Code Coverage" --logger GitHubActions
- if: matrix.os == 'windows-latest'
name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
directory: FFMpegCore.Test/TestResults
token: ${{ secrets.CODECOV_TOKEN }}
os: windows

View file

@ -13,5 +13,14 @@
<PackageProjectUrl>https://github.com/rosenbjerg/FFMpegCore</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<NeutralLanguage>en</NeutralLanguage>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
</Project>

View file

@ -3,18 +3,17 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<Description>Image extension for FFMpegCore using SkiaSharp</Description>
<PackageVersion>5.0.0</PackageVersion>
<PackageVersion>5.0.2</PackageVersion>
<PackageOutputPath>../nupkg</PackageOutputPath>
<PackageReleaseNotes>
</PackageReleaseNotes>
<PackageReleaseNotes>Bump dependencies</PackageReleaseNotes>
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing skiasharp</PackageTags>
<Authors>Malte Rosenbjerg, Vlad Jerca, Max Bagryantsev, Dimitri Vranken</Authors>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="SkiaSharp" Version="3.116.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.116.1" />
</ItemGroup>
<ItemGroup>

View file

@ -3,17 +3,16 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<Description>Image extension for FFMpegCore using System.Common.Drawing</Description>
<PackageVersion>5.0.0</PackageVersion>
<PackageVersion>5.0.2</PackageVersion>
<PackageOutputPath>../nupkg</PackageOutputPath>
<PackageReleaseNotes>
</PackageReleaseNotes>
<PackageReleaseNotes>Bump dependencies</PackageReleaseNotes>
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
<Authors>Malte Rosenbjerg, Vlad Jerca, Max Bagryantsev</Authors>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="7.0.0"/>
<PackageReference Include="System.Drawing.Common" Version="9.0.2" />
</ItemGroup>
<ItemGroup>

View file

@ -9,6 +9,7 @@ namespace FFMpegCore.Test
public class ArgumentBuilderTest
{
private readonly string[] _concatFiles = { "1.mp4", "2.mp4", "3.mp4", "4.mp4" };
private readonly string[] _multiFiles = { "1.mp3", "2.mp3", "3.mp3", "4.mp3" };
[TestMethod]
public void Builder_BuildString_IO_1()
@ -611,5 +612,86 @@ namespace FFMpegCore.Test
-i "input.mp4" -f tee "[movflags=faststart]output.mp4|[f=mpegts:select=\'0:v:0\']http://server/path"
""", str);
}
[TestMethod]
public void Builder_BuildString_MultiInput()
{
var audioStreams = string.Join("", _multiFiles.Select((item, index) => $"[{index}:0]"));
var mixFilter = $"{audioStreams}amix=inputs={_multiFiles.Length}:duration=longest:dropout_transition=1:normalize=0[final]";
var ffmpegArgs = $"-filter_complex \"{mixFilter}\" -map \"[final]\"";
var str = FFMpegArguments
.FromFileInput(_multiFiles)
.OutputToFile("output.mp3", overwrite: true, options => options
.WithCustomArgument(ffmpegArgs)
.WithAudioCodec(AudioCodec.LibMp3Lame) // Set the audio codec to MP3
.WithAudioBitrate(128) // Set the bitrate to 128kbps
.WithAudioSamplingRate(48000) // Set the sample rate to 48kHz
.WithoutMetadata() // Remove metadata
.WithCustomArgument("-ac 2 -write_xing 0 -id3v2_version 0")) // Force 2 Channels
.Arguments;
Assert.AreEqual($"-i \"1.mp3\" -i \"2.mp3\" -i \"3.mp3\" -i \"4.mp3\" -filter_complex \"[0:0][1:0][2:0][3:0]amix=inputs=4:duration=longest:dropout_transition=1:normalize=0[final]\" -map \"[final]\" -c:a libmp3lame -b:a 128k -ar 48000 -map_metadata -1 -ac 2 -write_xing 0 -id3v2_version 0 \"output.mp3\" -y", str);
}
[TestMethod]
public void Pre_VerifyExists_AllFilesExist()
{
// Arrange
var filePaths = new List<string>
{
Path.GetTempFileName(),
Path.GetTempFileName(),
Path.GetTempFileName()
};
var argument = new MultiInputArgument(true, filePaths);
try
{
// Act & Assert
argument.Pre(); // No exception should be thrown
}
finally
{
// Cleanup
foreach (var filePath in filePaths)
{
File.Delete(filePath);
}
}
}
[TestMethod]
public void Pre_VerifyExists_SomeFilesNotExist()
{
// Arrange
var filePaths = new List<string>
{
Path.GetTempFileName(),
"file2.mp4",
"file3.mp4"
};
var argument = new MultiInputArgument(true, filePaths);
try
{
// Act & Assert
Assert.ThrowsException<FileNotFoundException>(() => argument.Pre());
}
finally
{
// Cleanup
File.Delete(filePaths[0]);
}
}
[TestMethod]
public void Pre_VerifyExists_NoFilesExist()
{
// Arrange
var filePaths = new List<string>
{
"file1.mp4",
"file2.mp4",
"file3.mp4"
};
var argument = new MultiInputArgument(true, filePaths);
// Act & Assert
Assert.ThrowsException<FileNotFoundException>(() => argument.Pre());
}
}
}

View file

@ -8,19 +8,19 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="FluentAssertions" Version="8.0.1" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.8.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.8.0" />
<PackageReference Include="SkiaSharp" Version="3.116.1" />
</ItemGroup>
<ItemGroup>

View file

@ -467,7 +467,7 @@ namespace FFMpegCore.Test
}
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
public void Video_Snapshot_PersistSnapshot()
public void Video_Snapshot_Png_PersistSnapshot()
{
using var outputPath = new TemporaryFile("out.png");
var input = FFProbe.Analyse(TestResources.Mp4Video);
@ -480,6 +480,63 @@ namespace FFMpegCore.Test
Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName);
}
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
public void Video_Snapshot_Jpg_PersistSnapshot()
{
using var outputPath = new TemporaryFile("out.jpg");
var input = FFProbe.Analyse(TestResources.Mp4Video);
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
var analysis = FFProbe.Analyse(outputPath);
Assert.AreEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width);
Assert.AreEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height);
Assert.AreEqual("mjpeg", analysis.PrimaryVideoStream!.CodecName);
}
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
public void Video_Snapshot_Bmp_PersistSnapshot()
{
using var outputPath = new TemporaryFile("out.bmp");
var input = FFProbe.Analyse(TestResources.Mp4Video);
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
var analysis = FFProbe.Analyse(outputPath);
Assert.AreEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width);
Assert.AreEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height);
Assert.AreEqual("bmp", analysis.PrimaryVideoStream!.CodecName);
}
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
public void Video_Snapshot_Webp_PersistSnapshot()
{
using var outputPath = new TemporaryFile("out.webp");
var input = FFProbe.Analyse(TestResources.Mp4Video);
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
var analysis = FFProbe.Analyse(outputPath);
Assert.AreEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width);
Assert.AreEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height);
Assert.AreEqual("webp", analysis.PrimaryVideoStream!.CodecName);
}
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
public void Video_Snapshot_Exception_PersistSnapshot()
{
using var outputPath = new TemporaryFile("out.asd");
try
{
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
}
catch (Exception ex)
{
Assert.IsTrue(ex is ArgumentException);
}
}
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
public void Video_Snapshot_Rotated_PersistSnapshot()
{

View file

@ -8,6 +8,6 @@
/// <param name="context"></param>
/// <returns></returns>
//public string GetText(StringBuilder context);
public string GetText(IEnumerable<IArgument> context);
string GetText(IEnumerable<IArgument> context);
}
}

View file

@ -0,0 +1,47 @@
namespace FFMpegCore.Arguments
{
/// <summary>
/// Represents input parameters for multiple files
/// </summary>
public class MultiInputArgument : IInputArgument
{
public readonly bool VerifyExists;
public readonly IEnumerable<string> FilePaths;
public MultiInputArgument(bool verifyExists, IEnumerable<string> filePaths)
{
VerifyExists = verifyExists;
FilePaths = filePaths;
}
public MultiInputArgument(IEnumerable<string> filePaths, bool verifyExists) : this(verifyExists, filePaths) { }
public void Pre()
{
if (VerifyExists)
{
var missingFiles = new List<string>();
foreach (var filePath in FilePaths)
{
if (!File.Exists(filePath))
{
missingFiles.Add(filePath);
}
}
if (missingFiles.Any())
{
throw new FileNotFoundException($"The following input files were not found: {string.Join(", ", missingFiles)}");
}
}
}
public Task During(CancellationToken cancellationToken = default) => Task.CompletedTask;
public void Post() { }
/// <summary>
/// Generates a combined input argument text for all file paths
/// </summary>
public string Text => string.Join(" ", FilePaths.Select(filePath => $"-i \"{filePath}\""));
}
}

View file

@ -36,8 +36,8 @@ namespace FFMpegCore.Arguments
public interface IVideoFilterArgument
{
public string Key { get; }
public string Value { get; }
string Key { get; }
string Value { get; }
}
public class VideoFilterOptions

View file

@ -15,9 +15,33 @@
public static Codec LibX265 => FFMpeg.GetCodec("libx265");
public static Codec LibVpx => FFMpeg.GetCodec("libvpx");
public static Codec LibTheora => FFMpeg.GetCodec("libtheora");
public static Codec Png => FFMpeg.GetCodec("png");
public static Codec MpegTs => FFMpeg.GetCodec("mpegts");
public static Codec LibaomAv1 => FFMpeg.GetCodec("libaom-av1");
public static class Image
{
public static Codec Png => FFMpeg.GetCodec("png");
public static Codec Jpg => FFMpeg.GetCodec("mjpeg");
public static Codec Bmp => FFMpeg.GetCodec("bmp");
public static Codec Webp => FFMpeg.GetCodec("webp");
public static Codec GetByExtension(string path)
{
var ext = Path.GetExtension(path);
switch (ext)
{
case FileExtension.Image.Png:
return Png;
case FileExtension.Image.Jpg:
return Jpg;
case FileExtension.Image.Bmp:
return Bmp;
case FileExtension.Image.Webp:
return Webp;
default: throw new NotSupportedException($"Unsupported image extension: {ext}");
}
}
}
}
public static class AudioCodec

View file

@ -10,7 +10,10 @@
"libxvpx" => WebM,
"libxtheora" => Ogv,
"mpegts" => Ts,
"png" => Png,
"png" => Image.Png,
"jpg" => Image.Jpg,
"bmp" => Image.Bmp,
"webp" => Image.Webp,
_ => throw new Exception("The extension for this video type is not defined.")
};
}
@ -18,8 +21,16 @@
public static readonly string Ts = VideoType.MpegTs.Extension;
public static readonly string Ogv = VideoType.Ogv.Extension;
public static readonly string WebM = VideoType.WebM.Extension;
public static readonly string Png = ".png";
public static readonly string Mp3 = ".mp3";
public static readonly string Gif = ".gif";
public static class Image
{
public const string Png = ".png";
public const string Jpg = ".jpg";
public const string Bmp = ".bmp";
public const string Webp = ".webp";
public static readonly List<string> All = [Png, Jpg, Bmp, Webp];
}
}
}

View file

@ -20,16 +20,11 @@ namespace FFMpegCore
/// <returns>Bitmap with the requested snapshot.</returns>
public static bool Snapshot(string input, string output, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
{
if (Path.GetExtension(output) != FileExtension.Png)
{
output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Png);
}
CheckSnapshotOutputExtension(output, FileExtension.Image.All);
var source = FFProbe.Analyse(input);
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);
return arguments
.OutputToFile(output, true, outputOptions)
return SnapshotProcess(input, output, source, size, captureTime, streamIndex, inputFileIndex)
.ProcessSynchronously();
}
/// <summary>
@ -44,47 +39,55 @@ namespace FFMpegCore
/// <returns>Bitmap with the requested snapshot.</returns>
public static async Task<bool> SnapshotAsync(string input, string output, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
{
if (Path.GetExtension(output) != FileExtension.Png)
{
output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Png);
}
CheckSnapshotOutputExtension(output, FileExtension.Image.All);
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);
return await arguments
.OutputToFile(output, true, outputOptions)
return await SnapshotProcess(input, output, source, size, captureTime, streamIndex, inputFileIndex)
.ProcessAsynchronously();
}
public static bool GifSnapshot(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null)
{
if (Path.GetExtension(output)?.ToLower() != FileExtension.Gif)
{
output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Gif);
}
CheckSnapshotOutputExtension(output, [FileExtension.Gif]);
var source = FFProbe.Analyse(input);
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex);
return arguments
.OutputToFile(output, true, outputOptions)
return GifSnapshotProcess(input, output, source, size, captureTime, duration, streamIndex)
.ProcessSynchronously();
}
public static async Task<bool> GifSnapshotAsync(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null)
{
if (Path.GetExtension(output)?.ToLower() != FileExtension.Gif)
{
output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Gif);
}
CheckSnapshotOutputExtension(output, [FileExtension.Gif]);
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
return await GifSnapshotProcess(input, output, source, size, captureTime, duration, streamIndex)
.ProcessAsynchronously();
}
private static FFMpegArgumentProcessor SnapshotProcess(string input, string output, IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
{
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildSnapshotArguments(input, output, source, size, captureTime, streamIndex, inputFileIndex);
return arguments.OutputToFile(output, true, outputOptions);
}
private static FFMpegArgumentProcessor GifSnapshotProcess(string input, string output, IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null)
{
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex);
return await arguments
.OutputToFile(output, true, outputOptions)
.ProcessAsynchronously();
return arguments.OutputToFile(output, true, outputOptions);
}
private static void CheckSnapshotOutputExtension(string output, List<string> extensions)
{
if (!extensions.Contains(Path.GetExtension(output).ToLower()))
{
throw new ArgumentException(
$"Invalid snapshot output extension: {output}, needed: {string.Join(",", FileExtension.Image.All)}");
}
}
/// <summary>

View file

@ -21,6 +21,7 @@ namespace FFMpegCore
public static FFMpegArguments FromConcatInput(IEnumerable<string> filePaths, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new ConcatArgument(filePaths), addArguments);
public static FFMpegArguments FromDemuxConcatInput(IEnumerable<string> filePaths, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new DemuxConcatArgument(filePaths), addArguments);
public static FFMpegArguments FromFileInput(string filePath, bool verifyExists = true, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputArgument(verifyExists, filePath), addArguments);
public static FFMpegArguments FromFileInput(IEnumerable<string> filePath, bool verifyExists = true, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new MultiInputArgument(verifyExists, filePath), addArguments);
public static FFMpegArguments FromFileInput(FileInfo fileInfo, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputArgument(fileInfo.FullName, false), addArguments);
public static FFMpegArguments FromUrlInput(Uri uri, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputArgument(uri.AbsoluteUri, false), addArguments);
public static FFMpegArguments FromDeviceInput(string device, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputDeviceArgument(device), addArguments);
@ -35,6 +36,7 @@ namespace FFMpegCore
public FFMpegArguments AddConcatInput(IEnumerable<string> filePaths, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new ConcatArgument(filePaths), addArguments);
public FFMpegArguments AddDemuxConcatInput(IEnumerable<string> filePaths, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new DemuxConcatArgument(filePaths), addArguments);
public FFMpegArguments AddFileInput(string filePath, bool verifyExists = true, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputArgument(verifyExists, filePath), addArguments);
public FFMpegArguments AddFileInput(IEnumerable<string> filePath, bool verifyExists = true, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MultiInputArgument(verifyExists, filePath), addArguments);
public FFMpegArguments AddFileInput(FileInfo fileInfo, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputArgument(fileInfo.FullName, false), addArguments);
public FFMpegArguments AddUrlInput(Uri uri, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputArgument(uri.AbsoluteUri, false), addArguments);
public FFMpegArguments AddDeviceInput(string device, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputDeviceArgument(device), addArguments);

View file

@ -9,6 +9,30 @@ public static class SnapshotArgumentBuilder
{
public static (FFMpegArguments, Action<FFMpegArgumentOptions> outputOptions) BuildSnapshotArguments(
string input,
string output,
IMediaAnalysis source,
Size? size = null,
TimeSpan? captureTime = null,
int? streamIndex = null,
int inputFileIndex = 0)
{
return BuildSnapshotArguments(input, VideoCodec.Image.GetByExtension(output), source, size, captureTime, streamIndex, inputFileIndex);
}
public static (FFMpegArguments, Action<FFMpegArgumentOptions> outputOptions) BuildSnapshotArguments(
string input,
IMediaAnalysis source,
Size? size = null,
TimeSpan? captureTime = null,
int? streamIndex = null,
int inputFileIndex = 0)
{
return BuildSnapshotArguments(input, VideoCodec.Image.Png, source, size, captureTime, streamIndex, inputFileIndex);
}
private static (FFMpegArguments, Action<FFMpegArgumentOptions> outputOptions) BuildSnapshotArguments(
string input,
Codec codec,
IMediaAnalysis source,
Size? size = null,
TimeSpan? captureTime = null,
@ -26,7 +50,7 @@ public static class SnapshotArgumentBuilder
.Seek(captureTime)),
options => options
.SelectStream((int)streamIndex, inputFileIndex)
.WithVideoCodec(VideoCodec.Png)
.WithVideoCodec(codec)
.WithFrameOutputCount(1)
.Resize(size));
}

View file

@ -3,10 +3,15 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<Description>A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications</Description>
<PackageVersion>5.1.0</PackageVersion>
<PackageVersion>5.2.0</PackageVersion>
<PackageOutputPath>../nupkg</PackageOutputPath>
<PackageReleaseNotes>
</PackageReleaseNotes>
<PackageReleaseNotes>- **Instances and Packages Updates**: Updates to various instances and packages by rosenbjerg.
- **Audio and Video Enhancements**: Additions include a Copy option to Audio Codec and a Crop option to Arguments by brett-baker; video-stream level added to FFProbe analysis by Kaaybi; AV1 support for smaller snapshots and videos by BenediktBertsch; multiple input files support by AddyMills; HDR color properties support added to FFProbe analysis by Tomiscout.
- **System.Text.Json Bump**: Update by Kaaybi.
- **FFMpeg Processors and Utilities**: Modification for handling durations over 24 hours in `FFMpegArgumentProcessor` by alahane-techtel; fix for snapshots with correct width/height from rotated videos by Hagfjall.
- **Feature Additions and Fixes**: Support for multiple outputs and tee muxer by duggaraju; custom ffprob arguments by vfrz; fix for null reference exception with tags container by rosenbjerg; Chapter Modell change by vortex852456; codec copy added to the SaveM3U8Stream method by rpaschoal.
- **Closed and Non-merged Contributions**: Notable closed contributions include JSON source generators usage by onionware-github; Snapshot overload by 3UR; FromRawInput method by pedoc; runtime ffmpeg suite installation by yuqian5; and support for scale_npp by vicwilliam.
- **Miscellaneous Fixes**: Minor readme corrections by NaBian; fix for ffmpeg path issue by devedse.</PackageReleaseNotes>
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
<Authors>Malte Rosenbjerg, Vlad Jerca, Max Bagryantsev</Authors>
<PackageReadmeFile>README.md</PackageReadmeFile>
@ -17,8 +22,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Instances" Version="3.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="Instances" Version="3.0.1" />
<PackageReference Include="System.Text.Json" Version="9.0.2" />
</ItemGroup>
</Project>

View file

@ -1,5 +1,5 @@
# [FFMpegCore](https://www.nuget.org/packages/FFMpegCore/)
[![NuGet Badge](https://buildstats.info/nuget/FFMpegCore)](https://www.nuget.org/packages/FFMpegCore/)
[![NuGet Version](https://img.shields.io/nuget/v/FFMpegCore)](https://www.nuget.org/packages/FFMpegCore/)
[![GitHub issues](https://img.shields.io/github/issues/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/issues)
[![GitHub stars](https://img.shields.io/github/stars/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/stargazers)
[![GitHub](https://img.shields.io/github/license/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/blob/master/LICENSE)