mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 01:55:45 +00:00
Merge pull request #563 from rosenbjerg/main
Some checks failed
NuGet release / release (push) Has been cancelled
Some checks failed
NuGet release / release (push) Has been cancelled
V.5.2.0
This commit is contained in:
commit
6f1a8d77d7
37 changed files with 574 additions and 96 deletions
35
.github/workflows/ci.yml
vendored
35
.github/workflows/ci.yml
vendored
|
|
@ -1,53 +1,52 @@
|
|||
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-latest]
|
||||
os: [windows-latest, ubuntu-latest, macos-13]
|
||||
timeout-minutes: 7
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '7.0.x'
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Lint with dotnet
|
||||
run: dotnet format FFMpegCore.sln --severity warn --verify-no-changes
|
||||
|
||||
- name: Prepare FFMpeg
|
||||
uses: FedericoCarboni/setup-ffmpeg@v2
|
||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
ffmpeg-version: 6.0.1
|
||||
github-token: ${{ secrets.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@v3
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
directory: FFMpegCore.Test/TestResults
|
||||
fail_ci_if_error: true
|
||||
directory: FFMpegCore.Test/TestResults
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
os: windows
|
||||
|
|
|
|||
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
|
|
@ -8,12 +8,12 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '7.0.x'
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Build solution
|
||||
run: dotnet pack FFMpegCore.sln -c Release
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +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.3" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.3" />
|
||||
<PackageReference Include="SkiaSharp" Version="3.116.1" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.116.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -3,16 +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>
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
@ -571,5 +572,126 @@ namespace FFMpegCore.Test
|
|||
-i "input.mp4" -filter_complex "[{streamIndex}:v] fps=10,split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer" "output.gif"
|
||||
""", str);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Builder_BuildString_MultiOutput()
|
||||
{
|
||||
var str = FFMpegArguments.FromFileInput("input.mp4")
|
||||
.MultiOutput(args => args
|
||||
.OutputToFile("output.mp4", overwrite: true, args => args.CopyChannel())
|
||||
.OutputToFile("output.ts", overwrite: false, args => args.CopyChannel().ForceFormat("mpegts"))
|
||||
.OutputToUrl("http://server/path", options => options.ForceFormat("webm")))
|
||||
.Arguments;
|
||||
Assert.AreEqual($"""
|
||||
-i "input.mp4" -c:a copy -c:v copy "output.mp4" -y -c:a copy -c:v copy -f mpegts "output.ts" -f webm http://server/path
|
||||
""", str);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Builder_BuildString_MBROutput()
|
||||
{
|
||||
var str = FFMpegArguments.FromFileInput("input.mp4")
|
||||
.MultiOutput(args => args
|
||||
.OutputToFile("sd.mp4", overwrite: true, args => args.Resize(1200, 720))
|
||||
.OutputToFile("hd.mp4", overwrite: false, args => args.Resize(1920, 1080)))
|
||||
.Arguments;
|
||||
Assert.AreEqual($"""
|
||||
-i "input.mp4" -s 1200x720 "sd.mp4" -y -s 1920x1080 "hd.mp4"
|
||||
""", str);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Builder_BuildString_TeeOutput()
|
||||
{
|
||||
var str = FFMpegArguments.FromFileInput("input.mp4")
|
||||
.OutputToTee(args => args
|
||||
.OutputToFile("output.mp4", overwrite: false, args => args.WithFastStart())
|
||||
.OutputToUrl("http://server/path", options => options.ForceFormat("mpegts").SelectStream(0, channel: Channel.Video)))
|
||||
.Arguments;
|
||||
Assert.AreEqual($"""
|
||||
-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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Nullable>disable</Nullable>
|
||||
<LangVersion>default</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" Version="6.10.0" />
|
||||
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1">
|
||||
<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.5.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
|
||||
<PackageReference Include="SkiaSharp" Version="2.88.3" />
|
||||
<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>
|
||||
|
|
@ -51,9 +51,15 @@
|
|||
<None Update="Resources\input_3sec_rotation_90deg.mp4">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Resources\input_3sec_rotation_negative_90deg.mp4">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Resources\input_audio_only_10sec.mp4">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Resources\input_hdr.mov">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Resources\input_video_only_3sec.mp4">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace FFMpegCore.Test
|
|||
var packets = packetAnalysis.Packets;
|
||||
Assert.AreEqual(96, packets.Count);
|
||||
Assert.IsTrue(packets.All(f => f.CodecType == "video"));
|
||||
Assert.AreEqual("K_", packets[0].Flags);
|
||||
Assert.IsTrue(packets[0].Flags.StartsWith("K_"));
|
||||
Assert.AreEqual(1362, packets.Last().Size);
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ namespace FFMpegCore.Test
|
|||
|
||||
Assert.AreEqual(96, packets.Count);
|
||||
Assert.IsTrue(packets.All(f => f.CodecType == "video"));
|
||||
Assert.AreEqual("K_", packets[0].Flags);
|
||||
Assert.IsTrue(packets[0].Flags.StartsWith("K_"));
|
||||
Assert.AreEqual(1362, packets.Last().Size);
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ namespace FFMpegCore.Test
|
|||
var actual = packets.Select(f => f.CodecType).Distinct().ToList();
|
||||
var expected = new List<string> { "audio", "video" };
|
||||
CollectionAssert.AreEquivalent(expected, actual);
|
||||
Assert.IsTrue(packets.Where(t => t.CodecType == "audio").All(f => f.Flags == "K_"));
|
||||
Assert.IsTrue(packets.Where(t => t.CodecType == "audio").All(f => f.Flags.StartsWith("K_")));
|
||||
Assert.AreEqual(75, packets.Count(t => t.CodecType == "video"));
|
||||
Assert.AreEqual(141, packets.Count(t => t.CodecType == "audio"));
|
||||
}
|
||||
|
|
@ -105,6 +105,7 @@ namespace FFMpegCore.Test
|
|||
{
|
||||
var info = FFProbe.Analyse(TestResources.Mp4Video);
|
||||
Assert.AreEqual(3, info.Duration.Seconds);
|
||||
Assert.AreEqual(0, info.Chapters.Count);
|
||||
|
||||
Assert.AreEqual("5.1", info.PrimaryAudioStream!.ChannelLayout);
|
||||
Assert.AreEqual(6, info.PrimaryAudioStream.Channels);
|
||||
|
|
@ -122,6 +123,7 @@ namespace FFMpegCore.Test
|
|||
Assert.AreEqual(1, info.PrimaryVideoStream.SampleAspectRatio.Width);
|
||||
Assert.AreEqual(1, info.PrimaryVideoStream.SampleAspectRatio.Height);
|
||||
Assert.AreEqual("yuv420p", info.PrimaryVideoStream.PixelFormat);
|
||||
Assert.AreEqual(31, info.PrimaryVideoStream.Level);
|
||||
Assert.AreEqual(1280, info.PrimaryVideoStream.Width);
|
||||
Assert.AreEqual(720, info.PrimaryVideoStream.Height);
|
||||
Assert.AreEqual(25, info.PrimaryVideoStream.AvgFrameRate);
|
||||
|
|
@ -144,6 +146,13 @@ namespace FFMpegCore.Test
|
|||
Assert.AreEqual(90, info.PrimaryVideoStream.Rotation);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Probe_Rotation_Negative_Value()
|
||||
{
|
||||
var info = FFProbe.Analyse(TestResources.Mp4VideoRotationNegative);
|
||||
Assert.AreEqual(-90, info.PrimaryVideoStream.Rotation);
|
||||
}
|
||||
|
||||
[TestMethod, Timeout(10000)]
|
||||
public async Task Probe_Async_Success()
|
||||
{
|
||||
|
|
@ -172,6 +181,18 @@ namespace FFMpegCore.Test
|
|||
Assert.AreEqual(3, info.Duration.Seconds);
|
||||
}
|
||||
|
||||
[TestMethod, Timeout(10000)]
|
||||
public void Probe_HDR()
|
||||
{
|
||||
var info = FFProbe.Analyse(TestResources.HdrVideo);
|
||||
|
||||
Assert.IsNotNull(info.PrimaryVideoStream);
|
||||
Assert.AreEqual("tv", info.PrimaryVideoStream.ColorRange);
|
||||
Assert.AreEqual("bt2020nc", info.PrimaryVideoStream.ColorSpace);
|
||||
Assert.AreEqual("arib-std-b67", info.PrimaryVideoStream.ColorTransfer);
|
||||
Assert.AreEqual("bt2020", info.PrimaryVideoStream.ColorPrimaries);
|
||||
}
|
||||
|
||||
[TestMethod, Timeout(10000)]
|
||||
public async Task Probe_Success_Subtitle_Async()
|
||||
{
|
||||
|
|
@ -235,5 +256,12 @@ namespace FFMpegCore.Test
|
|||
Assert.IsNotNull(info.PrimaryAudioStream);
|
||||
Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Probe_Success_Custom_Arguments()
|
||||
{
|
||||
var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\"");
|
||||
Assert.AreEqual(3, info.Duration.Seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
{
|
||||
public static readonly string Mp4Video = "./Resources/input_3sec.mp4";
|
||||
public static readonly string Mp4VideoRotation = "./Resources/input_3sec_rotation_90deg.mp4";
|
||||
public static readonly string Mp4VideoRotationNegative = "./Resources/input_3sec_rotation_negative_90deg.mp4";
|
||||
public static readonly string WebmVideo = "./Resources/input_3sec.webm";
|
||||
public static readonly string HdrVideo = "./Resources/input_hdr.mov";
|
||||
public static readonly string Mp4WithoutVideo = "./Resources/input_audio_only_10sec.mp4";
|
||||
public static readonly string Mp4WithoutAudio = "./Resources/input_video_only_3sec.mp4";
|
||||
public static readonly string RawAudio = "./Resources/audio.raw";
|
||||
|
|
|
|||
BIN
FFMpegCore.Test/Resources/input_3sec_rotation_negative_90deg.mp4
Normal file
BIN
FFMpegCore.Test/Resources/input_3sec_rotation_negative_90deg.mp4
Normal file
Binary file not shown.
BIN
FFMpegCore.Test/Resources/input_hdr.mov
Normal file
BIN
FFMpegCore.Test/Resources/input_hdr.mov
Normal file
Binary file not shown.
|
|
@ -480,6 +480,21 @@ namespace FFMpegCore.Test
|
|||
Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName);
|
||||
}
|
||||
|
||||
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
||||
public void Video_Snapshot_Rotated_PersistSnapshot()
|
||||
{
|
||||
using var outputPath = new TemporaryFile("out.png");
|
||||
|
||||
var size = new Size(360, 0); // half the size of original video, keeping height 0 for keeping aspect ratio
|
||||
FFMpeg.Snapshot(TestResources.Mp4VideoRotationNegative, outputPath, size);
|
||||
|
||||
var analysis = FFProbe.Analyse(outputPath);
|
||||
Assert.AreEqual(size.Width, analysis.PrimaryVideoStream!.Width);
|
||||
Assert.AreEqual(1280 / 2, analysis.PrimaryVideoStream!.Height);
|
||||
Assert.AreEqual(0, analysis.PrimaryVideoStream!.Rotation);
|
||||
Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName);
|
||||
}
|
||||
|
||||
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
||||
public void Video_GifSnapshot_PersistSnapshot()
|
||||
{
|
||||
|
|
|
|||
10
FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs
Normal file
10
FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
namespace FFMpegCore.Arguments
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a copy codec parameter
|
||||
/// </summary>
|
||||
public class CopyCodecArgument : IArgument
|
||||
{
|
||||
public string Text => $"-codec copy";
|
||||
}
|
||||
}
|
||||
22
FFMpegCore/FFMpeg/Arguments/CropArgument.cs
Normal file
22
FFMpegCore/FFMpeg/Arguments/CropArgument.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System.Drawing;
|
||||
|
||||
namespace FFMpegCore.Arguments
|
||||
{
|
||||
public class CropArgument : IArgument
|
||||
{
|
||||
public readonly Size? Size;
|
||||
public readonly int Top;
|
||||
public readonly int Left;
|
||||
|
||||
public CropArgument(Size? size, int top, int left)
|
||||
{
|
||||
Size = size;
|
||||
Top = top;
|
||||
Left = left;
|
||||
}
|
||||
|
||||
public CropArgument(int width, int height, int top, int left) : this(new Size(width, height), top, left) { }
|
||||
|
||||
public string Text => Size == null ? string.Empty : $"-vf crop={Size.Value.Width}:{Size.Value.Height}:{Left}:{Top}";
|
||||
}
|
||||
}
|
||||
47
FFMpegCore/FFMpeg/Arguments/MultiInputArgument.cs
Normal file
47
FFMpegCore/FFMpeg/Arguments/MultiInputArgument.cs
Normal 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}\""));
|
||||
}
|
||||
}
|
||||
57
FFMpegCore/FFMpeg/Arguments/OutputTeeArgument.cs
Normal file
57
FFMpegCore/FFMpeg/Arguments/OutputTeeArgument.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
namespace FFMpegCore.Arguments
|
||||
{
|
||||
internal class OutputTeeArgument : IOutputArgument
|
||||
{
|
||||
private readonly FFMpegMultiOutputOptions _options;
|
||||
|
||||
public OutputTeeArgument(FFMpegMultiOutputOptions options)
|
||||
{
|
||||
if (options.Outputs.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("Atleast one output must be specified.", nameof(options));
|
||||
}
|
||||
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public string Text => $"-f tee \"{string.Join("|", _options.Outputs.Select(MapOptions))}\"";
|
||||
|
||||
public Task During(CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
|
||||
public void Post()
|
||||
{
|
||||
}
|
||||
|
||||
public void Pre()
|
||||
{
|
||||
}
|
||||
|
||||
private static string MapOptions(FFMpegArgumentOptions option)
|
||||
{
|
||||
var optionPrefix = string.Empty;
|
||||
if (option.Arguments.Count > 1)
|
||||
{
|
||||
var options = option.Arguments.Take(option.Arguments.Count - 1);
|
||||
optionPrefix = $"[{string.Join(":", options.Select(MapArgument))}]";
|
||||
}
|
||||
|
||||
var output = option.Arguments.OfType<IOutputArgument>().Single();
|
||||
return $"{optionPrefix}{output.Text.Trim('"')}";
|
||||
}
|
||||
|
||||
private static string MapArgument(IArgument argument)
|
||||
{
|
||||
if (argument is MapStreamArgument map)
|
||||
{
|
||||
return map.Text.Replace("-map ", "select=\\'") + "\\'";
|
||||
}
|
||||
else if (argument is BitStreamFilterArgument bitstreamFilter)
|
||||
{
|
||||
return bitstreamFilter.Text.Replace("-bsf:", "bsfs/").Replace(' ', '=');
|
||||
}
|
||||
|
||||
return argument.Text.TrimStart('-').Replace(' ', '=');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
public TimeSpan Start { get; private set; }
|
||||
public TimeSpan End { get; private set; }
|
||||
|
||||
public TimeSpan Duration => End - Start;
|
||||
|
||||
public ChapterData(string title, TimeSpan start, TimeSpan end)
|
||||
{
|
||||
Title = title;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
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 AudioCodec
|
||||
|
|
@ -27,6 +28,8 @@
|
|||
public static Codec Ac3 => FFMpeg.GetCodec("ac3");
|
||||
public static Codec Eac3 => FFMpeg.GetCodec("eac3");
|
||||
public static Codec LibMp3Lame => FFMpeg.GetCodec("libmp3lame");
|
||||
public static Codec Copy => new Codec("copy", CodecType.Audio);
|
||||
|
||||
}
|
||||
|
||||
public static class VideoType
|
||||
|
|
|
|||
|
|
@ -333,7 +333,10 @@ namespace FFMpegCore
|
|||
}
|
||||
|
||||
return FFMpegArguments
|
||||
.FromUrlInput(uri)
|
||||
.FromUrlInput(uri, options =>
|
||||
{
|
||||
options.WithCopyCodec();
|
||||
})
|
||||
.OutputToFile(output)
|
||||
.ProcessSynchronously();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ namespace FFMpegCore
|
|||
public FFMpegArgumentOptions WithVariableBitrate(int vbr) => WithArgument(new VariableBitRateArgument(vbr));
|
||||
public FFMpegArgumentOptions Resize(int width, int height) => WithArgument(new SizeArgument(width, height));
|
||||
public FFMpegArgumentOptions Resize(Size? size) => WithArgument(new SizeArgument(size));
|
||||
|
||||
public FFMpegArgumentOptions Crop(Size? size, int left, int top) => WithArgument(new CropArgument(size, top, left));
|
||||
public FFMpegArgumentOptions Crop(int width, int height, int left, int top) => WithArgument(new CropArgument(new Size(width, height), top, left));
|
||||
public FFMpegArgumentOptions Crop(Size? size) => WithArgument(new CropArgument(size, 0, 0));
|
||||
public FFMpegArgumentOptions Crop(int width, int height) => WithArgument(new CropArgument(new Size(width, height), 0, 0));
|
||||
public FFMpegArgumentOptions WithBitStreamFilter(Channel channel, Filter filter) => WithArgument(new BitStreamFilterArgument(channel, filter));
|
||||
public FFMpegArgumentOptions WithConstantRateFactor(int crf) => WithArgument(new ConstantRateFactorArgument(crf));
|
||||
public FFMpegArgumentOptions CopyChannel(Channel channel = Channel.Both) => WithArgument(new CopyArgument(channel));
|
||||
|
|
@ -77,6 +80,7 @@ namespace FFMpegCore
|
|||
public FFMpegArgumentOptions WithAudibleActivationBytes(string activationBytes) => WithArgument(new AudibleEncryptionKeyArgument(activationBytes));
|
||||
public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version));
|
||||
public FFMpegArgumentOptions WithGifPaletteArgument(int streamIndex, Size? size, int fps = 12) => WithArgument(new GifPaletteArgument(streamIndex, fps, size));
|
||||
public FFMpegArgumentOptions WithCopyCodec() => WithArgument(new CopyCodecArgument());
|
||||
|
||||
public FFMpegArgumentOptions WithArgument(IArgument argument)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using FFMpegCore.Enums;
|
||||
using FFMpegCore.Exceptions;
|
||||
|
|
@ -263,7 +262,7 @@ namespace FFMpegCore
|
|||
return;
|
||||
}
|
||||
|
||||
var processed = TimeSpan.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
|
||||
var processed = MediaAnalysisUtils.ParseDuration(match.Groups[1].Value);
|
||||
_onTimeProgress?.Invoke(processed);
|
||||
|
||||
if (_onPercentageProgress == null || _totalTimespan == null)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -71,6 +73,21 @@ namespace FFMpegCore
|
|||
return new FFMpegArgumentProcessor(this);
|
||||
}
|
||||
|
||||
public FFMpegArgumentProcessor OutputToTee(Action<FFMpegMultiOutputOptions> addOutputs, Action<FFMpegArgumentOptions>? addArguments = null)
|
||||
{
|
||||
var outputs = new FFMpegMultiOutputOptions();
|
||||
addOutputs(outputs);
|
||||
return ToProcessor(new OutputTeeArgument(outputs), addArguments);
|
||||
}
|
||||
|
||||
public FFMpegArgumentProcessor MultiOutput(Action<FFMpegMultiOutputOptions> addOutputs)
|
||||
{
|
||||
var args = new FFMpegMultiOutputOptions();
|
||||
addOutputs(args);
|
||||
Arguments.AddRange(args.Arguments);
|
||||
return new FFMpegArgumentProcessor(this);
|
||||
}
|
||||
|
||||
internal void Pre()
|
||||
{
|
||||
foreach (var argument in Arguments.OfType<IInputOutputArgument>())
|
||||
|
|
|
|||
29
FFMpegCore/FFMpeg/FFMpegMultiOutputOptions.cs
Normal file
29
FFMpegCore/FFMpeg/FFMpegMultiOutputOptions.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using FFMpegCore.Arguments;
|
||||
using FFMpegCore.Pipes;
|
||||
|
||||
namespace FFMpegCore
|
||||
{
|
||||
public class FFMpegMultiOutputOptions
|
||||
{
|
||||
internal readonly List<FFMpegArgumentOptions> Outputs = new();
|
||||
|
||||
public IEnumerable<IArgument> Arguments => Outputs.SelectMany(o => o.Arguments);
|
||||
|
||||
public FFMpegMultiOutputOptions OutputToFile(string file, bool overwrite = true, Action<FFMpegArgumentOptions>? addArguments = null) => AddOutput(new OutputArgument(file, overwrite), addArguments);
|
||||
|
||||
public FFMpegMultiOutputOptions OutputToUrl(string uri, Action<FFMpegArgumentOptions>? addArguments = null) => AddOutput(new OutputUrlArgument(uri), addArguments);
|
||||
|
||||
public FFMpegMultiOutputOptions OutputToUrl(Uri uri, Action<FFMpegArgumentOptions>? addArguments = null) => AddOutput(new OutputUrlArgument(uri.ToString()), addArguments);
|
||||
|
||||
public FFMpegMultiOutputOptions OutputToPipe(IPipeSink reader, Action<FFMpegArgumentOptions>? addArguments = null) => AddOutput(new OutputPipeArgument(reader), addArguments);
|
||||
|
||||
public FFMpegMultiOutputOptions AddOutput(IOutputArgument argument, Action<FFMpegArgumentOptions>? addArguments)
|
||||
{
|
||||
var args = new FFMpegArgumentOptions();
|
||||
addArguments?.Invoke(args);
|
||||
args.Arguments.Add(argument);
|
||||
Outputs.Add(args);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
public async Task WriteAsync(Stream outputStream, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_sampleEnumerator.Current != null)
|
||||
if (_sampleEnumerator.MoveNext() && _sampleEnumerator.Current != null)
|
||||
{
|
||||
await _sampleEnumerator.Current.SerializeAsync(outputStream, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public static class SnapshotArgumentBuilder
|
|||
}
|
||||
|
||||
var currentSize = new Size(source.PrimaryVideoStream.Width, source.PrimaryVideoStream.Height);
|
||||
if (source.PrimaryVideoStream.Rotation == 90 || source.PrimaryVideoStream.Rotation == 180)
|
||||
if (IsRotated(source.PrimaryVideoStream.Rotation))
|
||||
{
|
||||
currentSize = new Size(source.PrimaryVideoStream.Height, source.PrimaryVideoStream.Width);
|
||||
}
|
||||
|
|
@ -88,4 +88,10 @@ public static class SnapshotArgumentBuilder
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsRotated(int rotation)
|
||||
{
|
||||
var absRotation = Math.Abs(rotation);
|
||||
return absRotation == 90 || absRotation == 180;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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="7.0.2" />
|
||||
<PackageReference Include="Instances" Version="3.0.1" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using FFMpegCore.Enums;
|
||||
|
||||
namespace FFMpegCore
|
||||
|
|
@ -20,10 +21,20 @@ namespace FFMpegCore
|
|||
/// </summary>
|
||||
public string TemporaryFilesFolder { get; set; } = Path.GetTempPath();
|
||||
|
||||
/// <summary>
|
||||
/// Encoding web name used to persist encoding <see cref="Encoding"/>
|
||||
/// </summary>
|
||||
public string EncodingWebName { get; set; } = Encoding.Default.WebName;
|
||||
|
||||
/// <summary>
|
||||
/// Encoding used for parsing stdout/stderr on ffmpeg and ffprobe processes
|
||||
/// </summary>
|
||||
public Encoding Encoding { get; set; } = Encoding.Default;
|
||||
[JsonIgnore]
|
||||
public Encoding Encoding
|
||||
{
|
||||
get => Encoding.GetEncoding(EncodingWebName);
|
||||
set => EncodingWebName = value?.WebName ?? Encoding.Default.WebName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log level to use when calling of the ffmpeg executable.
|
||||
|
|
|
|||
|
|
@ -10,52 +10,52 @@ namespace FFMpegCore
|
|||
{
|
||||
public static class FFProbe
|
||||
{
|
||||
public static IMediaAnalysis Analyse(string filePath, FFOptions? ffOptions = null)
|
||||
public static IMediaAnalysis Analyse(string filePath, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
var processArguments = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var processArguments = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = processArguments.StartAndWaitForExit();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
}
|
||||
|
||||
public static FFProbeFrames GetFrames(string filePath, FFOptions? ffOptions = null)
|
||||
public static FFProbeFrames GetFrames(string filePath, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = instance.StartAndWaitForExit();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseFramesOutput(result);
|
||||
}
|
||||
|
||||
public static FFProbePackets GetPackets(string filePath, FFOptions? ffOptions = null)
|
||||
public static FFProbePackets GetPackets(string filePath, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = instance.StartAndWaitForExit();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParsePacketsOutput(result);
|
||||
}
|
||||
|
||||
public static IMediaAnalysis Analyse(Uri uri, FFOptions? ffOptions = null)
|
||||
public static IMediaAnalysis Analyse(Uri uri, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = instance.StartAndWaitForExit();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
}
|
||||
public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null)
|
||||
public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
var streamPipeSource = new StreamPipeSource(stream);
|
||||
var pipeArgument = new InputPipeArgument(streamPipeSource);
|
||||
var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
pipeArgument.Pre();
|
||||
|
||||
var task = instance.StartAndWaitForExitAsync();
|
||||
|
|
@ -75,57 +75,57 @@ namespace FFMpegCore
|
|||
return ParseOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default)
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
}
|
||||
|
||||
public static FFProbeFrames GetFrames(Uri uri, FFOptions? ffOptions = null)
|
||||
public static FFProbeFrames GetFrames(Uri uri, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = instance.StartAndWaitForExit();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseFramesOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<FFProbeFrames> GetFramesAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default)
|
||||
public static async Task<FFProbeFrames> GetFramesAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||
return ParseFramesOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<FFProbePackets> GetPacketsAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default)
|
||||
public static async Task<FFProbePackets> GetPacketsAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||
return ParsePacketsOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default)
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null)
|
||||
{
|
||||
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
}
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default)
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null)
|
||||
{
|
||||
var streamPipeSource = new StreamPipeSource(stream);
|
||||
var pipeArgument = new InputPipeArgument(streamPipeSource);
|
||||
var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
pipeArgument.Pre();
|
||||
|
||||
var task = instance.StartAndWaitForExitAsync(cancellationToken);
|
||||
|
|
@ -148,9 +148,9 @@ namespace FFMpegCore
|
|||
return ParseOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<FFProbeFrames> GetFramesAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default)
|
||||
public static async Task<FFProbeFrames> GetFramesAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null)
|
||||
{
|
||||
var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current);
|
||||
var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||
return ParseFramesOutput(result);
|
||||
}
|
||||
|
|
@ -212,18 +212,18 @@ namespace FFMpegCore
|
|||
}
|
||||
}
|
||||
|
||||
private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions)
|
||||
=> PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams \"{filePath}\"", ffOptions);
|
||||
private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions)
|
||||
=> PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions);
|
||||
private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions)
|
||||
=> PrepareInstance($"-loglevel error -print_format json -show_packets -v quiet -sexagesimal \"{filePath}\"", ffOptions);
|
||||
private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments)
|
||||
=> PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams -show_chapters \"{filePath}\"", ffOptions, customArguments);
|
||||
private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments)
|
||||
=> PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions, customArguments);
|
||||
private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments)
|
||||
=> PrepareInstance($"-loglevel error -print_format json -show_packets -v quiet -sexagesimal \"{filePath}\"", ffOptions, customArguments);
|
||||
|
||||
private static ProcessArguments PrepareInstance(string arguments, FFOptions ffOptions)
|
||||
private static ProcessArguments PrepareInstance(string arguments, FFOptions ffOptions, string? customArguments)
|
||||
{
|
||||
FFProbeHelper.RootExceptionCheck();
|
||||
FFProbeHelper.VerifyFFProbeExists(ffOptions);
|
||||
var startInfo = new ProcessStartInfo(GlobalFFOptions.GetFFProbeBinaryPath(ffOptions), arguments)
|
||||
var startInfo = new ProcessStartInfo(GlobalFFOptions.GetFFProbeBinaryPath(ffOptions), $"{arguments} {customArguments}")
|
||||
{
|
||||
StandardOutputEncoding = ffOptions.Encoding,
|
||||
StandardErrorEncoding = ffOptions.Encoding,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ namespace FFMpegCore
|
|||
[JsonPropertyName("format")]
|
||||
public Format Format { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("chapters")]
|
||||
public List<Chapter> Chapters { get; set; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
public IReadOnlyList<string> ErrorData { get; set; } = new List<string>();
|
||||
}
|
||||
|
|
@ -80,6 +83,9 @@ namespace FFMpegCore
|
|||
[JsonPropertyName("pix_fmt")]
|
||||
public string PixelFormat { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("level")]
|
||||
public int Level { get; set; }
|
||||
|
||||
[JsonPropertyName("sample_rate")]
|
||||
public string SampleRate { get; set; } = null!;
|
||||
|
||||
|
|
@ -87,10 +93,22 @@ namespace FFMpegCore
|
|||
public Dictionary<string, int> Disposition { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("tags")]
|
||||
public Dictionary<string, string> Tags { get; set; } = null!;
|
||||
public Dictionary<string, string>? Tags { get; set; }
|
||||
|
||||
[JsonPropertyName("side_data_list")]
|
||||
public List<Dictionary<string, JsonValue>> SideData { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("color_range")]
|
||||
public string ColorRange { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("color_space")]
|
||||
public string ColorSpace { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("color_transfer")]
|
||||
public string ColorTransfer { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("color_primaries")]
|
||||
public string ColorPrimaries { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class Format : ITagsContainer
|
||||
|
|
@ -126,7 +144,31 @@ namespace FFMpegCore
|
|||
public int ProbeScore { get; set; }
|
||||
|
||||
[JsonPropertyName("tags")]
|
||||
public Dictionary<string, string> Tags { get; set; } = null!;
|
||||
public Dictionary<string, string>? Tags { get; set; }
|
||||
}
|
||||
|
||||
public class Chapter : ITagsContainer
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public long Id { get; set; }
|
||||
|
||||
[JsonPropertyName("time_base")]
|
||||
public string TimeBase { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("start")]
|
||||
public long Start { get; set; }
|
||||
|
||||
[JsonPropertyName("start_time")]
|
||||
public string StartTime { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("end")]
|
||||
public long End { get; set; }
|
||||
|
||||
[JsonPropertyName("end_time")]
|
||||
public string EndTime { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("tags")]
|
||||
public Dictionary<string, string>? Tags { get; set; }
|
||||
}
|
||||
|
||||
public interface IDispositionContainer
|
||||
|
|
@ -136,7 +178,7 @@ namespace FFMpegCore
|
|||
|
||||
public interface ITagsContainer
|
||||
{
|
||||
Dictionary<string, string> Tags { get; set; }
|
||||
Dictionary<string, string>? Tags { get; set; }
|
||||
}
|
||||
|
||||
public static class TagExtensions
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
namespace FFMpegCore
|
||||
using FFMpegCore.Builders.MetaData;
|
||||
|
||||
namespace FFMpegCore
|
||||
{
|
||||
public interface IMediaAnalysis
|
||||
{
|
||||
TimeSpan Duration { get; }
|
||||
MediaFormat Format { get; }
|
||||
List<ChapterData> Chapters { get; }
|
||||
AudioStream? PrimaryAudioStream { get; }
|
||||
VideoStream? PrimaryVideoStream { get; }
|
||||
SubtitleStream? PrimarySubtitleStream { get; }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using FFMpegCore.Builders.MetaData;
|
||||
|
||||
namespace FFMpegCore
|
||||
{
|
||||
|
|
@ -7,6 +8,7 @@ namespace FFMpegCore
|
|||
internal MediaAnalysis(FFProbeAnalysis analysis)
|
||||
{
|
||||
Format = ParseFormat(analysis.Format);
|
||||
Chapters = analysis.Chapters.Select(c => ParseChapter(c)).ToList();
|
||||
VideoStreams = analysis.Streams.Where(stream => stream.CodecType == "video").Select(ParseVideoStream).ToList();
|
||||
AudioStreams = analysis.Streams.Where(stream => stream.CodecType == "audio").Select(ParseAudioStream).ToList();
|
||||
SubtitleStreams = analysis.Streams.Where(stream => stream.CodecType == "subtitle").Select(ParseSubtitleStream).ToList();
|
||||
|
|
@ -28,6 +30,18 @@ namespace FFMpegCore
|
|||
};
|
||||
}
|
||||
|
||||
private string GetValue(string tagName, Dictionary<string, string>? tags, string defaultValue) =>
|
||||
tags == null ? defaultValue : tags.TryGetValue(tagName, out var value) ? value : defaultValue;
|
||||
|
||||
private ChapterData ParseChapter(Chapter analysisChapter)
|
||||
{
|
||||
var title = GetValue("title", analysisChapter.Tags, "TitleValueNotSet");
|
||||
var start = MediaAnalysisUtils.ParseDuration(analysisChapter.StartTime);
|
||||
var end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime);
|
||||
|
||||
return new ChapterData(title, start, end);
|
||||
}
|
||||
|
||||
public TimeSpan Duration => new[]
|
||||
{
|
||||
Format.Duration,
|
||||
|
|
@ -37,6 +51,8 @@ namespace FFMpegCore
|
|||
|
||||
public MediaFormat Format { get; }
|
||||
|
||||
public List<ChapterData> Chapters { get; }
|
||||
|
||||
public AudioStream? PrimaryAudioStream => AudioStreams.OrderBy(stream => stream.Index).FirstOrDefault();
|
||||
public VideoStream? PrimaryVideoStream => VideoStreams.OrderBy(stream => stream.Index).FirstOrDefault();
|
||||
public SubtitleStream? PrimarySubtitleStream => SubtitleStreams.OrderBy(stream => stream.Index).FirstOrDefault();
|
||||
|
|
@ -74,6 +90,11 @@ namespace FFMpegCore
|
|||
Width = stream.Width ?? 0,
|
||||
Profile = stream.Profile,
|
||||
PixelFormat = stream.PixelFormat,
|
||||
Level = stream.Level,
|
||||
ColorRange = stream.ColorRange,
|
||||
ColorSpace = stream.ColorSpace,
|
||||
ColorTransfer = stream.ColorTransfer,
|
||||
ColorPrimaries = stream.ColorPrimaries,
|
||||
Rotation = MediaAnalysisUtils.ParseRotation(stream),
|
||||
Language = stream.GetLanguage(),
|
||||
Disposition = MediaAnalysisUtils.FormatDisposition(stream.Disposition),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
namespace FFMpegCore
|
||||
{
|
||||
public class MediaFormat
|
||||
public class MediaFormat : ITagsContainer
|
||||
{
|
||||
public TimeSpan Duration { get; set; }
|
||||
public TimeSpan StartTime { get; set; }
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FFMpegCore
|
||||
{
|
||||
public abstract class MediaStream
|
||||
public abstract class MediaStream : ITagsContainer
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public string CodecName { get; set; } = null!;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,13 @@ namespace FFMpegCore
|
|||
public int Height { get; set; }
|
||||
public double FrameRate { get; set; }
|
||||
public string PixelFormat { get; set; } = null!;
|
||||
public int Level { get; set; }
|
||||
public int Rotation { get; set; }
|
||||
public double AverageFrameRate { get; set; }
|
||||
public string ColorRange { get; set; } = null!;
|
||||
public string ColorSpace { get; set; } = null!;
|
||||
public string ColorTransfer { get; set; } = null!;
|
||||
public string ColorPrimaries { get; set; } = null!;
|
||||
|
||||
public PixelFormat GetPixelFormatInfo() => FFMpeg.GetPixelFormat(PixelFormat);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,23 @@ namespace FFMpegCore
|
|||
}
|
||||
|
||||
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
||||
if (Directory.Exists(Path.Combine(ffOptions.BinaryFolder, target)))
|
||||
var possiblePaths = new List<string>()
|
||||
{
|
||||
ffName = Path.Combine(target, ffName);
|
||||
Path.Combine(ffOptions.BinaryFolder, target),
|
||||
ffOptions.BinaryFolder
|
||||
};
|
||||
|
||||
foreach (var possiblePath in possiblePaths)
|
||||
{
|
||||
var possibleFFMpegPath = Path.Combine(possiblePath, ffName);
|
||||
if (File.Exists(possibleFFMpegPath))
|
||||
{
|
||||
return possibleFFMpegPath;
|
||||
}
|
||||
}
|
||||
|
||||
return Path.Combine(ffOptions.BinaryFolder, ffName);
|
||||
//Fall back to the assumption this tool exists in the PATH
|
||||
return ffName;
|
||||
}
|
||||
|
||||
private static FFOptions LoadFFOptions()
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ FFMpeg.Join(@"..\joined_video.mp4",
|
|||
``` csharp
|
||||
FFMpeg.SubVideo(inputPath,
|
||||
outputPath,
|
||||
TimeSpan.FromSeconds(0)
|
||||
TimeSpan.FromSeconds(0),
|
||||
TimeSpan.FromSeconds(30)
|
||||
);
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue