Migrate from old git host

This commit is contained in:
2025-01-31 11:16:42 +01:00
commit 44497e6b8d
77 changed files with 4687 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
using BlazorApp1.Handler.Interfaces;
using Microsoft.AspNetCore.Components.Forms;
namespace BlazorApp1.Handler;
public class FileHandler : IFileHandler
{
private readonly string _tempPath;
public FileHandler()
{
_tempPath = Directory.GetCurrentDirectory() + "/wwwroot/Videos/Temp/";
}
public async Task SaveFile(IBrowserFile file)
{
if (!Directory.Exists(_tempPath))
{
Directory.CreateDirectory(_tempPath);
}
await using FileStream fs = new(_tempPath + file.Name, FileMode.Create);
await file.OpenReadStream(1048576000).CopyToAsync(fs);
}
public async Task<bool> DeleteTempFile(string filePath)
{
if (!File.Exists(filePath))
{
return false;
}
File.Delete(filePath);
return true;
}
public string GetFileReference(string filename)
{
if (!File.Exists(_tempPath + filename))
{
return "";
}
return _tempPath + filename;
}
}
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Components.Forms;
namespace BlazorApp1.Handler.Interfaces;
public interface IFileHandler
{
public Task SaveFile(IBrowserFile file);
public Task<bool> DeleteTempFile(string filePath);
public string GetFileReference(string filename);
}
@@ -0,0 +1,8 @@
using BlazorApp1.Models;
namespace BlazorApp1.Handler.Interfaces;
public interface IVideoHandler
{
public bool ConvertVideo(string filePath, FFOptionsCodecs codecs, FFOptionsFilters filters, out string newFilePath);
}
+63
View File
@@ -0,0 +1,63 @@
using System.Diagnostics;
using BlazorApp1.Handler.Interfaces;
using BlazorApp1.Helpers;
using BlazorApp1.Models;
namespace BlazorApp1.Handler;
public class VideoHandler : IVideoHandler
{
private readonly string _finalPath;
private const string FILTER = "minterpolate";
private const string CODECH265 = "libx265";
private const string CODECH264 = "libx264";
private const string CODECVP9 = "";
private const string CONTAINERMP4 = "mp4";
private const string CONTAINERWEBM = "webm";
public VideoHandler()
{
_finalPath = Directory.GetCurrentDirectory() + "/wwwroot/Videos/Final/";
}
public bool ConvertVideo(string filePath, FFOptionsCodecs codecs, FFOptionsFilters filters, out string newFilePath)
{
string codec = ChooseCodec(codecs);
string container = ChooseContainer(codecs);
newFilePath = _finalPath + filePath.GetFileNameFromPath().RemoveFileEnding() + "_Converted" + "." + container;
ProcessStartInfo startInfo = new()
{
FileName = "ffmpeg",
Arguments = "-i " + filePath + " -c:v " + codec + " " + newFilePath,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
using Process lol = Process.Start(startInfo)!;
lol.WaitForExit();
return lol.Responding;
}
private string ChooseCodec(FFOptionsCodecs codecs)
{
return codecs switch
{
FFOptionsCodecs.H264 => CODECH264,
FFOptionsCodecs.H265 => CODECH265,
FFOptionsCodecs.VP9 => CODECVP9,
_ => throw new ArgumentOutOfRangeException(nameof(codecs), codecs, null)
};
}
private string ChooseContainer(FFOptionsCodecs codecs)
{
return codecs switch
{
FFOptionsCodecs.VP9 => CODECVP9,
_ => CONTAINERMP4
};
}
}