我将mpg视频流传输到Windows管道时遇到问题。我用命令ffmpeg.exe将视频解码到Windows管道,并使用C#连接到该管道,并在Winform上显示视频。我已经尝试了许多命令,但是没有一个起作用。
FFmpeg命令:
ffmpeg -i Day Flight.mpg -f image2pipe pipe:1> //./ pipe / ffpipe
C#代码:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.IO.Pipes;
using System.Threading;
using System.Runtime.InteropServices;
using System.Text;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
String readLine_;
private void readThread()
{
while (true)
{
readLine_ = reader_.ReadLine();
if (readLine_ != null)
{
byte[] bytes = Encoding.Unicode.GetBytes(readLine_);
//Console.WriteLine(readLine_);
//Console.ReadLine();
var ms = new MemoryStream(bytes);
// Bitmap bm = new Bitmap(ms);
Image im = (Bitmap)((new ImageConverter()).ConvertFrom(bytes));
}
else
Console.WriteLine("empty string");
//
}
}
private NamedPipeServerStream server_;
StreamReader reader_;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
AllocConsole();
server_ = new NamedPipeServerStream("ffpipe", PipeDirection.In, 1, PipeTransmissionMode.Byte);
server_.WaitForConnection();
reader_ = new StreamReader(server_);
Thread t = new Thread(readThread);
t.Start();
}
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
}
}
我无法在C#中获取图像,我的程序在行中崩溃 图片im =(位图)(((新ImageConverter())。ConvertFrom(字节));
而且我不知道自己在哪里出错-在ffmpeg管道中还是在C#程序中 https://image.ibb.co/eGDymp/Przechwytywanie.png https://image.ibb.co/hWpM6p/Przechwytywanie.png
示例视频: http://samples.ffmpeg.org/MPEG2/mpegts-klv/Day%20Flight.mpg