Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C# Named Pipe FFmpeg x265
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
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);
}
}
}
}
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