1
votes

I'm developing an application for real time streaming. capture frames from video devices and encoding with a ffmpeg wrapper called nreco.

the problerm is that if i try to stream encoded video to red5 via rtmp on red5 server, connection is immediatily closed.

this is the code i use to configure the output streaming:

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

adding frame this way:

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);
}  

any help?

1

1 Answers

2
votes

If you need to encode video from raw bitmap frames and provide result to red5 server another ConvertLiveMedia overload should be used (that accepts string-based identifier for output instead of 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();