Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written C# code of live streaming of IP camera (JPEG) in windows form application using AForge library. It is working but it's lagging too much.

Here is the code:

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


What I have tried:

Tried adding:

stream.FrameInterval = 0;


and

stream.FrameInterval = 1000;


But it's not making any difference. I think I'm placing it in the wrong place in the code. I'm writing it below stream1.NewFrame line, like this:

stream1.NewFrame += stream1_NewFrame1;
     stream.FrameInterval = 1000;
     stream.Start();
     stream1.Start();
 }
Posted
Comments
[no name] 15-Sep-20 11:13am    
That what "Buffering x%" is all about.
Member 14666358 15-Sep-20 11:57am    
What is Buffering x%?
[no name] 15-Sep-20 12:29pm    
It's what NetFlix, Sony, etc. do: trade one longer lag for many little ones.

If the download is slower than the need, you need to buffer, or risk starving. Then you have to call a medic.
Member 14666358 15-Sep-20 12:32pm    
How can I do that? Do you have any source code for it?
ZurdoDev 15-Sep-20 11:27am    
Get a faster computer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900