Как прочитать .mp4 видео, а затем поместить его в NamedPipeServerStream? - PullRequest
1 голос
/ 23 марта 2019

Как я могу положить .mp4 прочитанный с StreamReader и затем поместить его в трубу?Мне нужно прочитать данные и отправить их в трубу.Я прочитал файл .mpg4.Затем я обрабатываю его через ffmpeg.Я пытаюсь правильно отправить файл в канал?

public void getVideoFramesFromLocalPath(string fileName, string outputFileName, int period)
    {
        Thread th1 = new Thread(new ParameterizedThreadStart(PipeLine));
        th1.Start(fileName);            

        int bitrate = 5000;
        int fps = 10;

        string strTakeFrame = $"-f image2pipe -i pipe:videoPipe -qscale:v 4 -vf fps=1/{period} {outputFileName}_%04d.jpg";       

        ffProcessStart(strTakeFrame);
    }

    private async void PipeLine(object fileName)
    {
        StreamReader SR = new StreamReader((string)fileName);
        NamedPipeServerStream pipeServer = new NamedPipeServerStream("videoPipe", PipeDirection.Out);
        pipeServer.WaitForConnection();
        StreamWriter SW = new StreamWriter(pipeServer);
        SW.Write(SR.ReadToEnd());
        SW.Flush();
    }
    static void ffProcessStart(string commandLine)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();            

        startInfo.CreateNoWindow = false;                                

        startInfo.UseShellExecute = false;                              

        startInfo.FileName = @"ffmpeg.exe";                             

        startInfo.WindowStyle = ProcessWindowStyle.Hidden;              

        startInfo.Arguments = commandLine;                              

        try
        {
            using (Process exeProcess = Process.Start(startInfo))       
            {
                exeProcess.WaitForExit();                              
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
...