Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何解决JPEG直播滞后的问题?_C#_Jpeg_Http Live Streaming_Live Streaming_Aforge - Fatal编程技术网

C# 如何解决JPEG直播滞后的问题?

C# 如何解决JPEG直播滞后的问题?,c#,jpeg,http-live-streaming,live-streaming,aforge,C#,Jpeg,Http Live Streaming,Live Streaming,Aforge,我使用一个RGE库在windows窗体应用程序中编写了IP摄像头(JPEG)实时流媒体的C#代码。它正在工作,但滞后太多了 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Thread

我使用一个RGE库在windows窗体应用程序中编写了IP摄像头(JPEG)实时流媒体的C#代码。它正在工作,但滞后太多了

代码如下:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using AForge.Video; 
namespace CCTV_software 
{ 
    public partial class Form1 : Form 
    { 
        JPEGStream stream; 
        JPEGStream stream1; 
        public Form1() 
        { 
            InitializeComponent(); 
            stream = new JPEGStream("ip"); 
            stream1 = new JPEGStream("ip1"); 
stream.Login = "username"; 
stream.Password =  "password"; 
stream1.Login = "username1"; 
stream1.Password = "password1"; 
            stream.NewFrame += stream_NewFrame; 
            stream1.NewFrame += stream1_NewFrame1; 
            stream.Start(); 
            stream1.Start(); 
        } 
 
 
        void stream_NewFrame(object sender, NewFrameEventArgs eventArgs) 
        { 
            Bitmap bmp = (Bitmap)eventArgs.Frame.Clone(); 
            pictureBox1.Image = bmp;  
        } 
        void stream1_NewFrame1(object sender, NewFrameEventArgs eventArgs) 
        { 
            Bitmap bp = (Bitmap)eventArgs.Frame.Clone(); 
            pictureBox2.Image = bp; 
        } 
    } 
尝试添加:

stream.FrameInterval = 0;
但这没什么区别。 请帮我解决这个问题

编辑:

编辑2:


@mjwills和我的建议结合在一起:

void stream_NewFrame(object sender, NewFrameEventArgs eventArgs) 
{
    var oldImage = pictureBox1.Image 
    pictureBox1.Image = eventArgs.Frame; // set to new image without making a copy
    oldImage?.Dispose(); // = Dispose previous image, if not null
}
这为您节省了一个昂贵的克隆,并允许gc及时清理图像

这些措施结合起来应该可以提高吞吐量(即减少“滞后”)。进一步的对策可能是缩小图像尺寸或降低质量


注意:上述措施至少可以改善延迟,但不能保证使其完全消失,因为延迟也可能在其他地方引起。

您是否尝试过直接设置图像而不进行克隆?我想知道我是否正在放置
stream.FrameInterval=0在正确的位置。你知道它应该放在代码中的什么位置才能工作吗?“这是什么意思?”而不是
Bitmap bmp=(Bitmap)eventArgs.Frame.Clone();pictureBox1.Image=bmp=>
pictureBox1.Image=eventArgs.Frame如果你点击“查看详细信息”,应该会有一个堆栈跟踪。你能添加吗?@Fildor是的,你可以查看编辑。谢谢你。我会试试这个,然后告诉你它是否解决了问题。我试过了。它给出了一个错误**System.ArgumentException:“参数无效”。**在
Application.Run(new Form1())行上
在program.cst中这真的很奇怪,但我认为这与答案无关。你能确定没有括号丢失或类似的东西吗?也许是清理和重建。需要一个
System.Windows.Forms.Form的实例
。。。检查你是否有扭曲的红线。我清理并重建了它。仔细检查所有支架。它运行,相机启动,但不显示在屏幕上。2秒后出现错误。检查我的问题的编辑。我已经发布了错误的图片。