2023-02-13 11:25:45 +01:00
|
|
|
|
using SkiaSharp;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
|
2022-03-24 20:19:37 +01:00
|
|
|
|
namespace FFMpegCore.Extensions.System.Drawing.Common
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
|
|
|
|
public static class BitmapExtensions
|
|
|
|
|
{
|
2023-02-13 11:25:45 +01:00
|
|
|
|
public static bool AddAudio(this SKBitmap poster, string audio, string output)
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
|
|
|
|
var destination = $"{Environment.TickCount}.png";
|
2023-02-13 11:25:45 +01:00
|
|
|
|
using (var fileStream = File.OpenWrite(destination))
|
|
|
|
|
{
|
|
|
|
|
poster.Encode(fileStream, SKEncodedImageFormat.Png, default); // PNG does not respect the quality parameter
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-02-02 21:19:45 +01:00
|
|
|
|
return FFMpeg.PosterWithAudio(destination, audio, output);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2023-02-02 21:19:45 +01:00
|
|
|
|
if (File.Exists(destination))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(destination);
|
|
|
|
|
}
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-02 21:19:45 +01:00
|
|
|
|
}
|