Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize and cleanup pre 6.1 #285

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

7 changes: 1 addition & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
</PropertyGroup>

<PropertyGroup>
<!--<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>-->
<PublicSign>true</PublicSign>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
Expand All @@ -30,9 +29,5 @@
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)LICENSE.txt" Link="LICENSE.txt" Pack="true" PackagePath="LICENSE.txt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.*" PrivateAssets="all" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.*" PrivateAssets="all" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="CppSharp" Version="1.1.5.3168" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.7.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
<PackageVersion Include="SkiaSharp" Version="2.88.6" />
<PackageVersion Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FFmpeg.AutoGen.Abstractions\FFmpeg.AutoGen.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FFmpeg.AutoGen.Abstractions\FFmpeg.AutoGen.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FFmpeg.AutoGen.Abstractions\FFmpeg.AutoGen.Abstractions.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FFmpeg.AutoGen.ClangMacroParser\FFmpeg.AutoGen.ClangMacroParser.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<NoWarn>8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="CppSharp" Version="1.0.1" />
<PackageReference Include="CommandLineParser" />
<PackageReference Include="CppSharp" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FFmpeg.AutoGen.ClangMacroParser\FFmpeg.AutoGen.ClangMacroParser.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>

</Project>
15 changes: 9 additions & 6 deletions FFmpeg.AutoGen.Example/FFmpeg.AutoGen.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<NoWarn>1416</NoWarn>
</PropertyGroup>

<PropertyGroup>


</PropertyGroup>

<ItemGroup>
<None Remove="frame.*.jpg" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="SkiaSharp" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FFmpeg.AutoGen.Bindings.DynamicallyLoaded\FFmpeg.AutoGen.Bindings.DynamicallyLoaded.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>

</Project>
52 changes: 20 additions & 32 deletions FFmpeg.AutoGen.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using FFmpeg.AutoGen.Abstractions;
using FFmpeg.AutoGen.Bindings.DynamicallyLoaded;
using SkiaSharp;

namespace FFmpeg.AutoGen.Example;

Expand Down Expand Up @@ -111,21 +113,15 @@ private static unsafe void DecodeAllFramesToImages(AVHWDeviceType HWDevice)
? vsd.PixelFormat
: GetHWPixelFormat(HWDevice);
var destinationSize = sourceSize;
var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24;
var destinationPixelFormat = AVPixelFormat.@AV_PIX_FMT_BGRA;
using var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat);

var frameNumber = 0;

while (vsd.TryDecodeNextFrame(out var frame))
{
var convertedFrame = vfc.Convert(frame);

using (var bitmap = new Bitmap(convertedFrame.width,
convertedFrame.height,
convertedFrame.linesize[0],
PixelFormat.Format24bppRgb,
(IntPtr)convertedFrame.data[0]))
bitmap.Save($"frames/frame.{frameNumber:D8}.jpg", ImageFormat.Jpeg);
WriteFrame(convertedFrame, frameNumber);

Console.WriteLine($"frame: {frameNumber}");
frameNumber++;
Expand Down Expand Up @@ -154,12 +150,12 @@ private static AVPixelFormat GetHWPixelFormat(AVHWDeviceType hWDevice)
private static unsafe void EncodeImagesToH264()
{
var frameFiles = Directory.GetFiles("./frames", "frame.*.jpg").OrderBy(x => x).ToArray();
var fistFrameImage = Image.FromFile(frameFiles.First());
using var fistFrameImage = ReadFrame(frameFiles.First());

var outputFileName = "frames/out.h264";
var fps = 25;
var sourceSize = fistFrameImage.Size;
var sourcePixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24;
var sourceSize = new Size(fistFrameImage.Width, fistFrameImage.Height);
var sourcePixelFormat = AVPixelFormat.@AV_PIX_FMT_BGRA;
var destinationSize = sourceSize;
var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_YUV420P;
using var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat);
Expand All @@ -172,12 +168,8 @@ private static unsafe void EncodeImagesToH264()

foreach (var frameFile in frameFiles)
{
byte[] bitmapData;

using (var frameImage = Image.FromFile(frameFile))
using (var frameBitmap = frameImage is Bitmap bitmap ? bitmap : new Bitmap(frameImage))
bitmapData = GetBitmapData(frameBitmap);

using var bitmap = ReadFrame(frameFile);
var bitmapData = bitmap.Bytes;
fixed (byte* pBitmapData = bitmapData)
{
var data = new byte_ptr8 { [0] = pBitmapData };
Expand All @@ -200,22 +192,18 @@ private static unsafe void EncodeImagesToH264()
vse.Drain();
}

private static byte[] GetBitmapData(Bitmap frameBitmap)
private static unsafe void WriteFrame(AVFrame convertedFrame, int frameNumber)
{
var bitmapData = frameBitmap.LockBits(new Rectangle(Point.Empty, frameBitmap.Size),
ImageLockMode.ReadOnly,
PixelFormat.Format24bppRgb);
var imageInfo = new SKImageInfo(convertedFrame.width, convertedFrame.height, SKColorType.Bgra8888, SKAlphaType.Opaque);
using var bitmap = new SKBitmap();
bitmap.InstallPixels(imageInfo, (IntPtr)convertedFrame.data[0]);
using var stream = File.Create($"frames/frame.{frameNumber:D8}.jpg");
bitmap.Encode(stream, SKEncodedImageFormat.Jpeg, 90);
}

try
{
var length = bitmapData.Stride * bitmapData.Height;
var data = new byte[length];
Marshal.Copy(bitmapData.Scan0, data, 0, length);
return data;
}
finally
{
frameBitmap.UnlockBits(bitmapData);
}
private static unsafe SKBitmap ReadFrame(string frameFile)
{
using var codec = SKCodec.Create(frameFile);
return SKBitmap.Decode(codec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@
<ProjectReference Include="..\FFmpeg.AutoGen\FFmpeg.AutoGen.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@
<ProjectReference Include="..\FFmpeg.AutoGen\FFmpeg.AutoGen.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion FFmpeg.AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFmpeg.AutoGen.Example", "F
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "0. Solution Items", "0. Solution Items", "{CF48D45D-979F-4574-9E33-A3AC1CB542B5}"
ProjectSection(SolutionItems) = preProject
.travis.yml = .travis.yml
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
README.md = README.md
EndProjectSection
EndProject
Expand Down
8 changes: 2 additions & 6 deletions FFmpeg.AutoGen/FFmpeg.AutoGen.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
Expand All @@ -21,11 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.0.1" />
</ItemGroup>

</Project>
Loading