SHA256
forked from ADOFAIEditorForum/ADOFAIRenderer
Add Renderer Feature
This commit is contained in:
1 parent
c9314c264d
commit
2556bc7f62
13 files changed
+727
-21
No files matched your search
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Unity.Collections;
|
||||
|
||||
namespace ADOFAIRenderer.Util
|
||||
{
|
||||
public class FFmpegProcess
|
||||
{
|
||||
public static string FFmpegPath = "";
|
||||
|
||||
private Process? _ffmpegProcess;
|
||||
private Stream? _inputStream;
|
||||
|
||||
public bool IsEnd => _ffmpegProcess is { HasExited: true };
|
||||
|
||||
public void Execute(string command)
|
||||
{
|
||||
if (string.IsNullOrEmpty(command))
|
||||
{
|
||||
throw new ArgumentException("Command is empty");
|
||||
}
|
||||
if (string.IsNullOrEmpty(FFmpegPath) || !File.Exists(FFmpegPath))
|
||||
{
|
||||
throw new FileNotFoundException($"ffmpeg binary not found at '{FFmpegPath}'");
|
||||
}
|
||||
|
||||
_ffmpegProcess = new Process();
|
||||
_ffmpegProcess.StartInfo.FileName = FFmpegPath;
|
||||
_ffmpegProcess.StartInfo.Arguments = command;
|
||||
_ffmpegProcess.StartInfo.UseShellExecute = false;
|
||||
_ffmpegProcess.StartInfo.RedirectStandardInput = true;
|
||||
_ffmpegProcess.StartInfo.CreateNoWindow = true;
|
||||
_ffmpegProcess.Start();
|
||||
_inputStream = _ffmpegProcess.StandardInput.BaseStream;
|
||||
}
|
||||
|
||||
public void SendDataFromBuffer(byte[] buffer, int length = -1)
|
||||
{
|
||||
if (_inputStream == null) return;
|
||||
int writeLength = length < 0 ? buffer.Length : length;
|
||||
_inputStream.Write(buffer, 0, writeLength);
|
||||
_inputStream.Flush();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (_ffmpegProcess == null || _ffmpegProcess.HasExited || _inputStream == null) return;
|
||||
_inputStream.Flush();
|
||||
_inputStream.Close();
|
||||
_ffmpegProcess.WaitForExit();
|
||||
}
|
||||
|
||||
public static byte[] RentRawBytes<T>(NativeArray<T> arr) where T : struct
|
||||
{
|
||||
var val = new NativeSlice<T>(arr).SliceConvert<byte>();
|
||||
var array = ArrayPool<byte>.Shared.Rent(val.Length);
|
||||
val.CopyTo(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static byte[] ToRawBytes<T>(NativeArray<T> arr) where T : struct
|
||||
{
|
||||
var val = new NativeSlice<T>(arr).SliceConvert<byte>();
|
||||
var array = new byte[val.Length];
|
||||
val.CopyTo(array);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user