Jump to content

C# StandardOutput.BaseStream to NamedPipeServerStream

Hello everyone, I need your help, I was trying to Copy Stream from Process() to NamedPipeServer, my code as follow:

 

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.Out, 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 yuv4mpegpipe -pix_fmt yuv420p -y -",
                        UseShellExecute = false,
                        CreateNoWindow = true,
                        RedirectStandardOutput = true,
                    };

                    using (var process = new Process { StartInfo = psi })
                    {
                        process.Start();
                        process.StandardOutput.BaseStream.CopyTo(server);
                        process.WaitForExit();
                    }
                    
                }
            }
        }
    }
}

 

But I got an Error saying: Pipe is Broken, but It works a little:

 

D:\Users\Anime4000\Documents\GitHub\x265>x265 \\.\pipe\some_pipe --y4m --preset fast --tune psnr --crf 23.5 -o test.mp4
y4m  [info]: 1920x1080 fps 24/1 i420p8 sar 1:1 unknown frame count
raw  [info]: output file: test.mp4
x265 [error]: y4m: frame header missing
x265 [info]: HEVC encoder version 3.3_ifme-zen2+1-f94b0d32737d
x265 [info]: build info [Windows][GCC 9.3.0][64 bit] 8bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 32 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 5 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 2
x265 [info]: Keyframe min / max / scenecut / bias  : 24 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 15 / 4 / 0
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / on / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 0.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-23.5 / 0.60
x265 [info]: tools: rd=2 rskip signhide tmvp fast-intra strong-intra-smoothing
x265 [info]: tools: lslices=6 deblock sao

encoded 0 frames

How to properly copy or transfer StandardOutput.BaseStream to NamedPipeServerStream

My PC Specification: https://valid.x86.fr/qsznp0

Link to post
Share on other sites

Are you sure ffmpeg is doing anything? From that text block it looks like ffmpeg didn't encode anything. Or is the problem that it gets to that point then says the pipe is broken?

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 Fractal Design Meshify C Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to post
Share on other sites

8 hours ago, BobVonBob said:

Are you sure ffmpeg is doing anything? From that text block it looks like ffmpeg didn't encode anything. Or is the problem that it gets to that point then says the pipe is broken?

If I runs just this in Command Prompt, it do encode:

ffmpeg -hide_banner -v error -i "D:\Users\Anime4000\Videos\Unboxing.mp4" -strict -1 -map 0:0 -f yuv4mpegpipe -pix_fmt yuv420p -y -

 

My PC Specification: https://valid.x86.fr/qsznp0

Link to post
Share on other sites

I managed to fix this issue by telling ffmpeg use rawvideo instead of yuv4mpegpipe

 

and x265 need definde resolution, fps and bit-depth

 

ffmpeg -hide_banner -v error -i  -strict -1 -map 0:0 -f rawvideo -pix_fmt yuv420p -y -

x265-08 \\.\pipe\some_pipe --preset fast --tune psnr --crf 23.5 --input-res 1920x1080 --fps 24 --output-depth 8 -o test.mp4

 

My PC Specification: https://valid.x86.fr/qsznp0

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×