我正在开发一个实时流媒体应用程序.两个部分包括流媒体.我使用捕获卡捕获一些实时源并需要实时流式传输.并且还需要流式传输本地视频文件.
为了实时流式传输本地视频文件,我使用emgu cv将视频帧捕获为位图.为此,我创建了位图列表,并使用一个线程将捕获的位图保存到此列表中.我还在图片框中显示这些帧.位图列表可以存储1秒的视频.如果帧速率为30,则将存储30个视频帧.填写此列表后,我启动另一个线程来编码1秒块视频.
出于编码目的,我使用名为nreco的ffmpeg包装器.我将视频帧写入ffmpeg并启动ffmpeg进行编码.停止该任务后,我可以将编码数据作为字节数组.
然后我通过LAN使用UDP协议发送数据.
这很好用.但我无法实现流畅的流媒体.当我通过VLC播放器接收到流时,数据包之间有一些毫秒的延迟,我也注意到帧丢失了.
private Capture _capture = null;
Image<Bgr, Byte> frame;
// Here I capture the frames and store them in a list
private void ProcessFrame(object sender, EventArgs arg)
{
frame = _capture.QueryFrame();
frameBmp = new Bitmap((int)frameWidth, (int)frameHeight, PixelFormat.Format24bppRgb);
frameBmp = frame.ToBitmap();
twoSecondVideoBitmapFramesForEncode.Add(frameBmp);
////}
if (twoSecondVideoBitmapFramesForEncode.Count == (int)FrameRate)
{
isInitiate = false;
thread = new Thread(new ThreadStart(encodeTwoSecondVideo));
thread.IsBackground = true;
thread.Start();
}
}
public void encodeTwoSecondVideo()
{
List<Bitmap> copyOfTwoSecondVideo = new List<Bitmap>();
copyOfTwoSecondVideo = twoSecondVideoBitmapFramesForEncode.ToList();
twoSecondVideoBitmapFramesForEncode.Clear();
int …Run Code Online (Sandbox Code Playgroud)