nreco包装器位图通过rtmp流式传输

时间:2015-04-24 12:17:05

标签: bitmap ffmpeg

我正在开发一个实时流媒体应用程序。 从视频设备捕获帧并使用名为nreco的ffmpeg包装器进行编码。

问题在于,如果我尝试通过red5服务器上的rtmp将编码视频流式传输到red5,则连接将立即关闭。

这是我用来配置输出流的代码:

ffMpegTask = videoConv.ConvertLiveMedia(
     Format.raw_video,
     outstream,
     Format.flv,
     new ConvertSettings()
     {
         CustomInputArgs = " -re -pix_fmt bgr24 -video_size 800x600 ", 
         CustomOutputArgs = " -acodec copy -vcodec libx264 -pix_fmt yuv420p rtmp://127.0.0.1/live/stream ",   
     });

      ffMpegTask.Start();

以这种方式添加框架:

void camera_Frame(object sender, FrameEventArgs e)
{
   Bitmap item = e.Frame;

   BitmapData bd = item.LockBits(new Rectangle(0, 0, item.Width, item.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
   byte[] buf = new byte[bd.Stride * item.Height];
   Marshal.Copy(bd.Scan0, buf, 0, buf.Length);
   ffMpegTask.Write(buf, 0, buf.Length);
   item.UnlockBits(bd);
}  

任何帮助?

1 个答案:

答案 0 :(得分:2)

如果您需要对原始位图帧中的视频进行编码并将结果提供给red5服务器,则应使用另一个ConvertLiveMedia重载(它接受基于字符串的输出而不是C#Stream标识符):

ffMpegTask = videoConv.ConvertLiveMedia(
     null, // no input stream if data is provided with Write method
     Format.raw_video,
     "rtmp://127.0.0.1/live/stream",
     Format.flv,
     new ConvertSettings()
     {
         CustomInputArgs = " -re -pix_fmt bgr24 -video_size 800x600 ", 
         CustomOutputArgs = " -acodec copy -vcodec libx264 -pix_fmt yuv420p ",   
     });

      ffMpegTask.Start();