Problem with stream from IP camera

4,210 views
Skip to first unread message

dikatano

unread,
Jul 5, 2012, 10:43:48 AM7/5/12
to jav...@googlegroups.com
Hello! I want to load video from an IP camera and I am using this code:
import com.googlecode.javacv.*;
import static com.googlecode.javacv.cpp.opencv_core.*;

public class IpCam {

    public static void main(String[] args) throws Exception {

        
      FrameGrabber grabber = new FFmpegFrameGrabber("http://192.168.0.20");
      grabber.setFormat("mjpeg");
      grabber.start();
IplImage frame = grabber.grab(); CanvasFrame canvasFrame = new CanvasFrame("Camera"); canvasFrame.setCanvasSize(frame.width(), frame.height()); while (canvasFrame.isVisible() && (frame = grabber.grab()) != null) { canvasFrame.showImage(frame); } grabber.stop(); canvasFrame.dispose(); System.exit(0); } }

The error message I get is this:
Exception in thread "main" com.googlecode.javacv.FrameGrabber$Exception: Could not find stream information.
 at com.googlecode.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:224)
 at ipcam.IpCam.main(IpCam.java:16)
[mjpeg @ 000000000056B500] Could not find codec parameters (Video: mjpeg)
[mjpeg @ 000000000056B500] Estimating duration from bitrate, this may be inaccurate
Java Result: 1

When I change the format from mjpeg to mpeg I get this message:

Exception in thread "main" com.googlecode.javacv.FrameGrabber$Exception: Could not find stream information.
 at com.googlecode.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:224)
 at ipcam.IpCam.main(IpCam.java:16)
Java Result: 1

What is wrong? Any help would be appreciated
Thanks!

dikatano

unread,
Jul 5, 2012, 11:07:54 AM7/5/12
to jav...@googlegroups.com
I just change the format to h264 and the stream to rtp://192.168.0.20:554/play1.sdp/
I get no errors but nothing is done!

Samuel Audet

unread,
Jul 7, 2012, 10:57:40 AM7/7/12
to jav...@googlegroups.com
Are you sure your IP camera is MJPEG? What's the model of your camera?
What do you see if you copy/paste "http://192.168.0.20" in Firefox? If
it doesn't work with Firefox, it's not going to work with FFmpeg either...

On 2012-07-05 23:43, dikatano wrote:
> Hello! I want to load video from an IP camera and I am using this code:
>
> import com.googlecode.javacv.*;
> import static com.googlecode.javacv.cpp.opencv_core.*;
>
> public class IpCam {
>
> public static void main(String[] args) throws Exception {
>
>
>
> FrameGrabber grabber = new FFmpegFrameGrabber("http://192.168.0.20");
> grabber.setFormat("mjpeg");
> grabber.start();
>
>
>
> IplImage frame = grabber.grab();
> CanvasFrame canvasFrame = new CanvasFrame("Camera");
> canvasFrame.setCanvasSize(frame.width(), frame.height());
> while (canvasFrame.isVisible()&& (frame = grabber.grab()) != null) {

Samuel Audet

unread,
Jul 7, 2012, 10:59:01 AM7/7/12
to jav...@googlegroups.com
On 2012-07-06 00:07, dikatano wrote:
> I just change the format to h264 and the stream to rtp://192.168.0.20:554/play1.sdp/
> I get no errors but nothing is done!
>

If your IP camera supposed to be H.264 then? How did you verify that?

dikatano

unread,
Jul 8, 2012, 4:41:34 PM7/8/12
to jav...@googlegroups.com
The model of the camera is D-Link DCS5605. When I type the address http, opens in every browser a page that shows  the live video of the camera and also I can operate the camera and configure it. I have also tried the rtsp stream in vlc and it shows live video. When I open the browser, in the section of audio]video settings, I can choose the h.264.

Samuel Audet

unread,
Jul 8, 2012, 9:16:29 PM7/8/12
to jav...@googlegroups.com
And what happens if you use FFmpegFrameGrabber without setting anything?

On 07/09/2012 05:41 AM, dikatano wrote:
> The model of the camera is D-Link DCS5605. When I type the address http,
> opens in every browser a page that shows the live video of the camera
> and also I can operate the camera and configure it. I have also tried
> the rtsp stream in vlc and it shows live video. When I open the browser,
> in the section of audio]video settings, I can choose the h.264.
>
> On Saturday, July 7, 2012 3:59:01 PM UTC+1, Samuel Audet wrote:
>
> On 2012-07-06 00:07, dikatano wrote:
> > I just change the format to h264 and the stream to
> rtp://192.168.0.20:554/play1.sdp/ <http://192.168.0.20:554/play1.sdp/>

dikatano

unread,
Jul 9, 2012, 9:48:17 AM7/9/12
to jav...@googlegroups.com
Its ok, we fixed this!
This is the code:
final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("rtsp://192.168.0.20:554/play1.sdp");

dikatano

unread,
Sep 3, 2012, 10:40:08 AM9/3/12
to jav...@googlegroups.com


On Sunday, September 2, 2012 7:12:08 PM UTC+1, Tronic-X wrote:
Hey dikatano how did you find the video address ("rtsp://192.168.0.20:554/play1.sdp") of the camera?
The 192.168.0.20:554 was the IP address of the camera. Then in the configuration page of the camera in that IP address , in audio and video settings it is defined play1.sdp stream.
 

Todani Luvhengo

unread,
Sep 4, 2012, 10:45:47 AM9/4/12
to jav...@googlegroups.com
Thanks found another one that works. http://username:pass@<IP>/video.cgi?&.mjpg
--
***************
Luvhengo T
***************
Message has been deleted

Samuel Audet

unread,
Feb 9, 2013, 2:21:03 AM2/9/13
to jav...@googlegroups.com
Hello,

On 02/04/2013 04:41 AM, Tarun Dhillon wrote:
> Hi Dikantano/Samuel -
>
> I am trying to do something very similar, essentially fetch a MPEG4 feed from IPCamera ( tenvis) and store it as a video file on android phone.
>
> I am FFmpegFrameGrabber as shown in the code below and the last line throw up an exception
>
> FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("http://192.168.1.239:81/videostream.cgi?user=admin&pwd=");
> grabber.setFormat("mjpeg");
> grabber.start();
>
> >> com.googlecode.javacv.FrameGrabber$Exception: avformat_open_input() error -5: Could not open input "http://192.168.1.239:81/videostream.cgi?user=admin&pwd=". (Has setFormat() been called?)
>
> I have also tried to change the format to h264 but didn't succeed. Any suggestions will be really great.

What does FFmpeg prints on the console? (You might want to execute your
code outside of Android as that doesn't let us see those messages.)

Samuel

henriqu...@gmail.com

unread,
Nov 29, 2013, 10:05:33 AM11/29/13
to jav...@googlegroups.com
Hi Guys, anybody fixed the problem using IP CAm with format mjpeg ??
Could you help me please ?


Thks & regards

Samuel Audet

unread,
Dec 14, 2013, 11:04:42 PM12/14/13
to jav...@googlegroups.com
On 11/30/2013 12:05 AM, henriqu...@gmail.com wrote:
> Hi Guys, anybody fixed the problem using IP CAm with format mjpeg ??
> Could you help me please ?

The class provided here might work better for you:
http://code.google.com/p/javacv/issues/detail?id=384
I should be merging that in the repository soon enough :)

Samuel

Greg Perry

unread,
Dec 14, 2013, 11:16:52 PM12/14/13
to jav...@googlegroups.com
:)




--

--- You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Abhishek Majumdar

unread,
Feb 17, 2014, 7:41:51 PM2/17/14
to jav...@googlegroups.com
Hi Samuel,

I am totally new to JavaCv. I am trying to simply stream video from an ip camera in mjpeg format. I am using the basic program you had provided.

    FrameGrabber grabber = new FFmpegFrameGrabber("http://172.16.0.11:554/mjpeg.cgi?user=root&pwd=root");

        grabber.setFormat("mjpeg");
        grabber.start();
        IplImage grabbedImage = grabber.grab();
        int width  = grabbedImage.width();
        int height = grabbedImage.height();
        IplImage grayImage    = IplImage.create(width, height, IPL_DEPTH_8U, 1);
        IplImage rotatedImage = grabbedImage.clone();
        FrameRecorder recorder = FrameRecorder.createDefault("output.avi", width, height);
        recorder.start();
        CanvasFrame frame = new CanvasFrame("Some Title", CanvasFrame.getDefaultGamma()/grabber.getGamma());
    while (frame.isVisible() && (grabbedImage = grabber.grab()) != null) {

            frame.showImage(grabbedImage);
            recorder.record(grabbedImage);
        }
        frame.dispose();
        recorder.stop();
        grabber.stop();


 While it works well for webcams, when I try it on an IP camera I am really not sure what URL should I be using. I mean I tried "http://172.16.0.11:554/mjpeg.cgi?user=root&pwd=root" with FFmpegFrameGrabber(), but it gave me the following exception:

Exception in thread "main" com.googlecode.javacv.FrameGrabber$Exception: avformat_find_stream_info() error -541478725: Could not find stream information.
    at com.googlecode.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:360)
    at com.googlecode.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:308)
    at Demo.main(Demo.java:23)
[mjpeg @ 0000000000152660] decoding for stream 0 failed
[mjpeg @ 0000000000152660] Could not find codec parameters for stream 0 (Video: mjpeg): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options

When I simply put the ip in a browser, it works. But when I paste the whole string, it gives me this:
No session ID specified.

I followed this post and tried using IPCameraFrameGrabber. I guess I am having issue with the URL I mean to use. Could you help me out?

Thanks
Abhishek

Samuel Audet

unread,
Feb 17, 2014, 11:44:48 PM2/17/14
to jav...@googlegroups.com

BTW, does it work with ffplay on the command line?

2014/02/18 10:08 "Abhishek Majumdar" <abhishe...@gmail.com>:
--
 
---
You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+un...@googlegroups.com.

Abhishek Majumdar

unread,
Feb 19, 2014, 12:06:34 PM2/19/14
to jav...@googlegroups.com
Yes it does.

Abhishek Majumdar

unread,
Feb 19, 2014, 12:13:23 PM2/19/14
to jav...@googlegroups.com
Wait. What do you mean by "it"? The ffplay command works when I give a file to it.


On Monday, February 17, 2014 10:44:48 PM UTC-6, Samuel Audet wrote:

Abhishek Majumdar

unread,
Feb 19, 2014, 12:27:20 PM2/19/14
to jav...@googlegroups.com
No.


On Monday, February 17, 2014 10:44:48 PM UTC-6, Samuel Audet wrote:

Abhishek Majumdar

unread,
Feb 19, 2014, 1:04:56 PM2/19/14
to jav...@googlegroups.com
Why are my posts getting deleted?

Abhishek


On Monday, February 17, 2014 10:44:48 PM UTC-6, Samuel Audet wrote:

Samuel Audet

unread,
Feb 19, 2014, 8:38:38 PM2/19/14
to jav...@googlegroups.com
They are not getting deleted. Sometimes I get spam here, so I moderate
the messages, usually on first post only, but the system doesn't work
fully by e-mail, so not always.

Anyway, does calling "ffplay <your IP camera URL here>" work?

Samuel

Abhishek Majumdar

unread,
Feb 20, 2014, 1:55:25 PM2/20/14
to jav...@googlegroups.com
No it doesn't. It gives me "<URL>: No such file or directory"
BTW, I was looking and somebody suggested the following URLs
IPCameraFrameGrabber("http://<camera ip>/mjpg/video.mjpg") or IPCameraFrameGrabber("http://<camera ip>/axis-cgi/mjpg/video.cgi?"
This kind of works. I mean a frame opens up but has a white screen. However the video gets recorded just fine. But this only works when no login is required. Otherwise I get HTTP error 401.

Thanks
Abhishek

Abhishek Majumdar

unread,
Feb 20, 2014, 4:44:15 PM2/20/14
to jav...@googlegroups.com
Also I tried ffplay http://<camera ip>/mjpg/video.mjpg.
It gave me "Invalid data found when processing input"

Abhishek

Samuel Audet

unread,
Feb 21, 2014, 8:40:18 PM2/21/14
to jav...@googlegroups.com
On 02/21/2014 06:44 AM, Abhishek Majumdar wrote:
> Also I tried ffplay http://<camera ip>/mjpg/video.mjpg.
> It gave me "Invalid data found when processing input"

Ok, so let's try to figure out first if FFmpeg (ffplay) supports the
stream from that IP camera, and how. Here's a reply that might help:
http://ffmpeg.org/pipermail/libav-user/2013-May/004557.html
Because the thing is, if even FFmpeg doesn't support it, there isn't
much chance that anything else does, so...

Samuel

Abhishek Majumdar

unread,
Feb 22, 2014, 8:11:38 PM2/22/14
to jav...@googlegroups.com
Alright it works. And consequently FFmpegFrame("<URL>") also works. A window shows up, and records. Thanks a lot for that. Just two more issues:
1> I get this warning Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj420p(pc), 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 25 tbc
[swscaler @ 00000000138eb240] deprecated pixel format used, make sure you did set range correctly
Output #0, avi, to 'output.avi':
    Stream #0:0: Video: huffyuv, bgra, 320x240, q=2-31, 400 kb/s, 90k tbn, 30 tbc
[swscaler @ 00000000138eb240] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 00000000138eb240] deprecated pixel format used, make sure you did set range correctly

2> The video that is recorded, plays pretty fast. like when someone plays a video in several times its normal speed. Could you perhaps explain why?

Thanks
Abhishek

Samuel Audet

unread,
Feb 23, 2014, 7:56:39 AM2/23/14
to jav...@googlegroups.com
On 02/23/2014 10:11 AM, Abhishek Majumdar wrote:
> Alright it works. And consequently FFmpegFrame("<URL>") also works. A window shows up, and records. Thanks a lot for that.

Good to hear that!

> Just two more issues:
> 1> I get this warning Duration: N/A, bitrate: N/A
> Stream #0:0: Video: mjpeg, yuvj420p(pc), 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 25 tbc
> [swscaler @ 00000000138eb240] deprecated pixel format used, make sure you did set range correctly
> Output #0, avi, to 'output.avi':
> Stream #0:0: Video: huffyuv, bgra, 320x240, q=2-31, 400 kb/s, 90k tbn, 30 tbc
> [swscaler @ 00000000138eb240] deprecated pixel format used, make sure you did set range correctly
> [swscaler @ 00000000138eb240] deprecated pixel format used, make sure you did set range correctly

Might be worth looking into, but I wouldn't worry them for now if it works

> 2> The video that is recorded, plays pretty fast. like when someone
> plays a video in several times its normal speed. Could you perhaps
> explain why?

You've set the recording frame rate to 30 FPS (default is 30 FPS
anyway), while you are grabbing only at 25 FPS, so that's pretty normal.

Samuel
Reply all
Reply to author
Forward
0 new messages