Created
August 22, 2020 07:07
-
-
Save Anime4000/9dffab62e31b9d8dd815f0803eb5cbd3 to your computer and use it in GitHub Desktop.
C# Named Pipe FFmpeg x265
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -hide_banner -v error -i -strict -1 -map 0:0 -f rawvideo -pix_fmt yuv420p -y \\.\pipe\some_pipe_in | |
x265-08 \\.\pipe\some_pipe --preset fast --tune psnr --crf 23.5 --input-res 1920x1080 --fps 24 --output-depth 8 -o test.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.IO.Pipes; | |
using System.Diagnostics; | |
namespace NamedPipeTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
while (true) | |
{ | |
using (var server_tx = new NamedPipeServerStream("some_pipe", PipeDirection.Out, 1, PipeTransmissionMode.Byte)) | |
{ | |
Console.Error.WriteLine("TX Pipe is Waiting..."); | |
server_tx.WaitForConnection(); | |
Console.Error.WriteLine("TX Pipe Started!"); | |
using (var server_rx = new NamedPipeServerStream("some_pipe_in", PipeDirection.In, 1, PipeTransmissionMode.Byte)) | |
{ | |
Console.Error.WriteLine("RX Pipe is Waiting..."); | |
server_rx.WaitForConnection(); | |
Console.Error.WriteLine("RX Pipe Started!"); | |
CopyStream(server_rx, server_tx); | |
} | |
} | |
} | |
} | |
public static void CopyStream(Stream input, Stream output) | |
{ | |
int read; | |
byte[] buffer = new byte[0x1000]; | |
while ((read = input.Read(buffer, 0, buffer.Length)) > 0) | |
{ | |
output.Write(buffer, 0, read); | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.IO.Pipes; | |
using System.Diagnostics; | |
namespace NamedPipeTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
while (true) | |
{ | |
using (var server = new NamedPipeServerStream("some_pipe", PipeDirection.InOut, 1, PipeTransmissionMode.Byte)) | |
{ | |
Console.Error.WriteLine("Waiting..."); | |
server.WaitForConnection(); | |
Console.Error.WriteLine("Started!"); | |
var psi = new ProcessStartInfo() | |
{ | |
FileName = "ffmpeg", | |
Arguments = "-hide_banner -v error -i \"D:\\Users\\Anime4000\\Videos\\Unboxing.mp4\" -strict -1 -map 0:0 -f rawvideo -pix_fmt yuv420p -y -", | |
UseShellExecute = false, | |
CreateNoWindow = true, | |
RedirectStandardOutput = true, | |
RedirectStandardError = true, | |
}; | |
using (var process = new Process { StartInfo = psi }) | |
{ | |
process.Start(); | |
process.StandardOutput.BaseStream.CopyTo(server); | |
//process.StandardError.BaseStream.CopyTo(server); | |
process.WaitForExit(); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment