Purpose:
利用C#架構一個RTSP 影像streaming的環境.包含WebCAM控制, FFMpeg使用 and Emgu.CV的應用
Fundamental:
RTSP
即時串流協定(Real Time Streaming Protocol,RTSP)是一種網路應用協定,專為娛樂和通訊系統的使用,以控制串流媒體伺服器。該協定用於建立和控制終端之間的媒體對談。媒體伺服器的客戶端發布VCR命令,例如播放,錄製和暫停,以便於即時控制從伺服器到客戶端(影片點播)或從客戶端到伺服器(語音錄音)的媒體流。FFmpeg
FFmpeg 是一個開放原始碼的自由軟體,它包含了音訊和視訊多種格式的錄影、轉檔、串流功能,同時也是一個音訊與視訊格式轉換函式庫(Library),許多開源的工具都是基於 FFmpeg 打造的。Reference:
感謝分享:包含 RTSP windows server 和一些相關軟體介紹與下載!!public void StartRTSP(string path)
{
if (_RTSPPara._process != null && !_RTSPPara._process.HasExited)
return;
_RTSPPara._process = new Process();
_RTSPPara._process.StartInfo.UseShellExecute = false;
_RTSPPara._process.StartInfo.FileName = @path;
_RTSPPara._process.StartInfo.Arguments = "";
_RTSPPara._process.StartInfo.RedirectStandardInput = true;
_RTSPPara._process.StartInfo.RedirectStandardOutput = true;
_RTSPPara._process.StartInfo.RedirectStandardError = true;
_RTSPPara._process.EnableRaisingEvents = true;
_RTSPPara._process.StartInfo.CreateNoWindow = true;
try
{
var started = _RTSPPara._process.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
_RTSPPara._process.BeginErrorReadLine();
_RTSPPara._process.BeginOutputReadLine();
}
public void StartFFmpeg(string path, string webname)
{
string rtspServer = "rtsp://localhost:8554/test";
string ffmpegCommand =
$"-f dshow -i video=\"{webname}\" -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -rtsp_transport tcp -f rtsp {rtspServer}";
if (_FFmpegPara._process != null && !_FFmpegPara._process.HasExited)
return;
_FFmpegPara._process = new Process();
_FFmpegPara._process.StartInfo.UseShellExecute = false;
_FFmpegPara._process.StartInfo.FileName = @path;
_FFmpegPara._process.StartInfo.Arguments = ffmpegCommand;
_FFmpegPara._process.StartInfo.RedirectStandardInput = true;
_FFmpegPara._process.StartInfo.RedirectStandardOutput = true;
_FFmpegPara._process.StartInfo.RedirectStandardError = true;
_FFmpegPara._process.EnableRaisingEvents = true;
_FFmpegPara._process.StartInfo.CreateNoWindow = true;
_FFmpegPara._process.StartInfo.Verb = "RunAs";
try
{
var started = _FFmpegPara._process.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
_FFmpegPara._process.BeginErrorReadLine();
_FFmpegPara._process.BeginOutputReadLine();
}
private void button7_Click(object sender, EventArgs e)
{
if (FFmpeg._FFmpegPara.RunisFinish == true)
{
//button5.BackColor = Color.AliceBlue;
button7.BackColor = Color.Green;
WebCAM[0].show_screen = true;
myVideoCapture = new VideoCapture("rtsp://127.0.0.1:8554/test");
myVideoCapture.ImageGrabbed += imageGrabbedEvent;
myVideoCapture.Start();
}
else if (WebCAM[0].run == true)
{
//button5.BackColor = Color.Green;
button7.BackColor = Color.AliceBlue;
if (myVideoCapture != null)
{
myVideoCapture.ImageGrabbed -= imageGrabbedEvent;
Thread.Sleep(500);
myVideoCapture.Dispose();
}
}
}
public void imageGrabbedEvent(object sender, EventArgs arg)
{
try
{
TEmgu._EmguPara.ImageSource = myVideoCapture.QueryFrame().ToImage<Bgr, byte>();
}
catch (Exception Ex)
{
}
if (TEmgu._EmguPara.ImageSource != null)
{
imageBox1.Image = TEmgu._EmguPara.ImageSource.Resize(imageBox1.Width, imageBox1.Height, Emgu.CV.CvEnum.Inter.Linear);
} //----if (TEmgu._EmguPara.ImageSource != null)
}
沒有留言:
張貼留言