Skip to content

Commit

Permalink
Introduce OutputFormat.Guess/All.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Sep 22, 2022
1 parent 825f06c commit 0dce0d2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build/deploy-test-nuget.linq
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ string IncrementBuildVersion(string projFile)

string versionPrefix = (versionPrefixNode.FirstNode as XText).Value;
string versionSuffix = (versionSuffixNode.FirstNode as XText).Value;
int buildNumber = int.Parse(versionSuffix.Split('-')[1]);
int buildNumber = int.Parse(versionSuffix.Split('.')[1]);
int newBuildNumber = buildNumber + 1;
string newVersionSuffix = "preview-" + newBuildNumber;
string newVersionSuffix = "preview." + newBuildNumber;

versionSuffixNode.ReplaceNodes(newVersionSuffix);

Expand Down
45 changes: 45 additions & 0 deletions src/Sdcb.FFmpeg.Tests/Formats/FormatTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Sdcb.FFmpeg.Common;
using Sdcb.FFmpeg.Formats;
using Sdcb.FFmpeg.Raw;
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace Sdcb.FFmpeg.Tests.Formats;

public class FormatTest
{
private readonly ITestOutputHelper _console;

public FormatTest(ITestOutputHelper console)
{
_console = console;
}

[Fact]
public void InputFormatTest()
{
foreach (InputFormat fmt in InputFormat.All)
{
_console.WriteLine(fmt.Name);
}
}

[Fact]
public void OutputFormatTest()
{
foreach (OutputFormat fmt in OutputFormat.All)
{
_console.WriteLine(fmt.Name);
}
}
}
29 changes: 29 additions & 0 deletions src/Sdcb.FFmpeg/Formats/OutputFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Sdcb.FFmpeg.Common;
using Sdcb.FFmpeg.Raw;
using System;
using System.Collections.Generic;
using static Sdcb.FFmpeg.Raw.ffmpeg;
using System.Linq;

namespace Sdcb.FFmpeg.Formats;

public unsafe partial struct OutputFormat
{
/// <summary>
/// Return the output format in the list of registered output formats which best matches the provided parameters, or return NULL if there is no match.
/// <param name="shortName">if non-NULL checks if short_name matches with the names of the registered formats</param>
/// <param name="fileName">if non-NULL checks if filename terminates with the extensions of the registered formats</param>
/// <param name="mimeType">if non-NULL checks if mime_type matches with the MIME type of the registered formats</param>
/// <see cref="av_guess_format(string, string, string)"/>
/// </summary>
public static OutputFormat? Guess(string? shortName = null, string? fileName = null, string? mimeType = null)
=> FromNativeOrNull(av_guess_format(shortName, fileName, mimeType));

/// <summary>
/// Iterate over all registered muxers.
/// <see cref="av_muxer_iterate(void**)"/>
/// </summary>
public static IEnumerable<OutputFormat> All => NativeUtils
.EnumeratePtrIterator(ptr => (IntPtr)av_muxer_iterate((void**)ptr))
.Select(x => FromNative((AVOutputFormat*)x));
}
2 changes: 1 addition & 1 deletion src/Sdcb.FFmpeg/Sdcb.FFmpeg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<PackageId>Sdcb.FFmpeg</PackageId>
<VersionPrefix>5.1.1</VersionPrefix>
<VersionSuffix>preview.1</VersionSuffix>
<VersionSuffix>preview.4</VersionSuffix>
<LangVersion>latest</LangVersion>
<!-- Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
<IncludeSymbols>true</IncludeSymbols>
Expand Down

0 comments on commit 0dce0d2

Please sign in to comment.