使用ffmpeg推送多路海康摄像头(摄像头单独存在)的服务程序,经测试可用

新建类:PullVideoStreamService.cs 内容如下:

public class PullVideoStreamService
{
public static void Start(string ffmpegFilePath
, string cameraIP
, string cameraId
, string cameraUser
, string cameraPassword)
{
  Task.Run(() =>
  {
    Process cmd = new Process();
    cmd.StartInfo.FileName = ffmpegFilePath;
    cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    cmd.StartInfo.Arguments = $"-i \"rtsp://{cameraUser}:{cameraPassword}@{cameraIP}:554/h264/ch34/main/av_stream\" -f flv -r 25 -s 640*480 -an \"rtmp://localhost:1935/hls/{cameraId}\"";

      cmd.Start();
      cmd.WaitForExit();
    });
  }
}

在你摄像头加载循环中调用此方法,将在程序运行的后台推送视频流,然后就可以通过:rtmp://localhost:1935/hls/{cameraId}访问了

注:rtmp://localhost:1935/hls/{cameraId}是基于nginx的一个播放服务,在网上到处都可以下载,改一下配置运行就行了

猜你喜欢

转载自www.cnblogs.com/my85016629/p/11935612.html