2015-04-24 32 views
1

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

问题是,如果我尝试通过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); 
} 

任何帮助吗?

回答

2

如果需要编码来自原始位图的帧视频和提供结果到RED5服务器另一个ConvertLiveMedia过载,应使用(即接受输出,而不是C#流基于字符串的标识符):

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(); 
+0

确定。非常感谢你。有用! – pavel63

+0

在这种情况下,您可能会将我的答案标记为有用:-) –