Skip to content

Commit

Permalink
using LGPL compiled ffmpeg shared for FFmpeg n5.0 from [here](https:/…
Browse files Browse the repository at this point in the history
…/github.com/BtbN/FFmpeg-Builds/releases)

* specifically - ffmpeg-n5.0-latest-win64-lgpl-shared-5.0.zip

targets openH264  rather than the GPL x264 encoder

modifies FFmpeg.AutoGen.Example to output an MP4 rather than .h264 file by way of:
* adding AVFormatContext and AVStream
* using ffmpeg.avio_open to create / write the file instead of System.IO.xxx
* writing a header and trailer
* using ffmpeg.av_interleaved_write_frame()

includes a somewhat mangled but updated and somewhat working version of the Transcoding gist shared by Ruslan-B
  • Loading branch information
camerongibbs-eic committed Jun 10, 2022
1 parent 24da0e7 commit d6af667
Show file tree
Hide file tree
Showing 26 changed files with 999 additions and 469 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ UpgradeLog*.XML
*.stackdump

# Local
/FFmpeg.AutoGen.Example/frame.*.jpg
/FFmpeg.AutoGen.Example/frame.*.jpg
/video-test*
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

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

</Project>
36 changes: 36 additions & 0 deletions FFmpeg.AutoGen.Example.Transcoding/FFmpegBinariesHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace FFmpeg.AutoGen.Example
{
public class FFmpegBinariesHelper
{
internal static void RegisterFFmpegBinaries()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var current = Environment.CurrentDirectory;
var probe = Path.Combine("FFmpeg", "bin", Environment.Is64BitProcess ? "x64" : "x86");

while (current != null)
{
var ffmpegBinaryPath = Path.Combine(current, probe);

if (Directory.Exists(ffmpegBinaryPath))
{
Console.WriteLine($"FFmpeg binaries found in: {ffmpegBinaryPath}");
ffmpeg.RootPath = ffmpegBinaryPath;
return;
}

current = Directory.GetParent(current)?.FullName;
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
ffmpeg.RootPath = "/lib/x86_64-linux-gnu/";
else
throw new NotSupportedException(); // fell free add support for platform of your choose
}
}
}
23 changes: 23 additions & 0 deletions FFmpeg.AutoGen.Example.Transcoding/FFmpegHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Runtime.InteropServices;

namespace FFmpeg.AutoGen.Example
{
internal static class FFmpegHelper
{
public static unsafe string av_strerror(int error)
{
var bufferSize = 1024;
var buffer = stackalloc byte[bufferSize];
ffmpeg.av_strerror(error, buffer, (ulong) bufferSize);
var message = Marshal.PtrToStringAnsi((IntPtr) buffer);
return message;
}

public static int ThrowExceptionIfError(this int error)
{
if (error < 0) throw new ApplicationException(av_strerror(error));
return error;
}
}
}
12 changes: 12 additions & 0 deletions FFmpeg.AutoGen.Example.Transcoding/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace FFmpeg.AutoGen.Example
{
public class Program
{
private static void Main(string[] args)
{
FFmpegBinariesHelper.RegisterFFmpegBinaries();
var transcoding = new Transcoding();
transcoding.main(args.Length, args);
}
}
}
Loading

0 comments on commit d6af667

Please sign in to comment.