Hy Everyone!
I am having a problem in grabbing images from a Panasonic IP Camera in JPEG format infact the problem is with the fps because the fps is always remains 1 or 2 not more than it but infact camera supports upto 30 the cam model is Panasonic WV-SP302E i am using the following C# code to grab the image and display it in my winforms app
public partial class Form1 : Form
{
// indicates wether to prevent caching in case of a proxy server or not
private bool preventCaching = false;
public Form1()
{
InitializeComponent();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
this.pictureBox1.Image = this.GetSingleFrame(@"http://ipaddress/SnapshotJPEG?Resolution=320x240&Quality=Standard");
}
}
/// <summary>
/// Get a single JPEG frame from the camera
/// </summary>
/// <param name="source">JPEG Stream source</param>
/// <exception cref="WebException">If the IP camera is not receable or an error is occured</exception>
/// <exception cref="Exception">If an unknown error occured</exception>
public Bitmap GetSingleFrame(string source)
{
byte[] buffer = new byte[512 * 1024]; // buffer to read stream
HttpWebRequest req = null;
WebResponse resp = null;
Stream stream = null;
Random rnd = new Random((int)DateTime.Now.Ticks);
try
{
int read, total = 0;
// create request
if (!preventCaching)
{
req = (HttpWebRequest)WebRequest.Create(source);
}
else
{
req = (HttpWebRequest)WebRequest.Create(source + ((source.IndexOf('?') == -1) ? '?' : '&') + "fake=" + rnd.Next().ToString());
}
// set login and password
req.Credentials = new NetworkCredential("root", "a");
req.Timeout = -1;
resp = req.GetResponse();
// get response stream
stream = resp.GetResponseStream();
// loop
do
{
read = stream.Read(buffer, total, 1024);
total += read;
}
while (read != 0);
Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, total));
return bmp;
}
catch (WebException ex)
{
string s = ex.ToString();
return null;
}
catch (Exception ex)
{
string s = ex.ToString();
return null;
}
finally
{
// abort request
if (req != null)
{
req.Abort();
req = null;
}
// close response stream
if (stream != null)
{
stream.Close();
stream = null;
}
// close response
if (resp != null)
{
resp.Close();
resp = null;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.backgroundWorker1.RunWorkerAsync();
}
}
I am even using the backgrounworker component to grab images in another thread but still 2 fps. Any idea how to increase the fps
It has been quite some time since the question, but it is still all the same since then.
The camera offers up to 30 frames per second in streaming mode, however this does not necessarily apply to JPEG snapshot frame rate. Depending on camera model effective JPEG rate might be more or less slower as compared to full speed streaming.
There is little you can actually do about this (it is typical for MPEG-4/H.264 camera to send JPEGs at lower rate), your options are: