Displaying a mjpeg stream, is ofxIpVideoGrabber the right solution on Raspberry Pi?

Hi, I would like to create a small app that displays an http video stream coming from a remote Pi running mjpg-streamer

I’ve got a look at ofxIpVideoGrabber, but I’m not sure if this addon will be able to compile and run on a Pi.

Furthermore, I really wonder if I need a full blown addon, provided that few lines of Python seems to do the job :

import cv2
import urllib 
import numpy as np

stream=urllib.urlopen('http://192.168.1.90:8080/?action=stream')
bytes=''
while True:
    bytes+=stream.read(1024)
    a = bytes.find('\xff\xd8')
    b = bytes.find('\xff\xd9')
    if a!=-1 and b!=-1:
        jpg = bytes[a:b+2]
        bytes= bytes[b+2:]
        i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
        cv2.imshow('i',i)
        if cv2.waitKey(1) ==27:
            exit(0)    

While the above code works OK on a Pi it has two drawbacks :

  • it relies on openCV
  • it works only under XWindow and is very slow

I just would like a very simple piece of of code to decode the stream and get (for each frame) an image I could project on a texture… Any barebone addon anywhere ? I may have missed a message in the forums but I didn’t found anything…

Thanks !

ofxIpVideoGrabber is simple and should run fine on a Pi. If you want to broadcast a an mjpeg stream from a pi, check out https://github.com/bakercp/ofxHTTP/tree/master/example_basic_ip_video_server.

Thanks, I’ll try with ofxIpVideoGrabber !

BTW, the audio stream is captured from a webcam - Whilst mjpg-streamer does a good job (it’s very fast) I wonder how difficult it would be to create a live broadcaster with OF instead…

Christopher, I did a try with a very simple ofApp with OF0.8.4
Connecting to the mpeg stream seems ok, but I get this error

APP
[ error ] IPVideoGrabber: Exception : [CAM1]: Exception: Invalid HTTP Reponse : ???

STREAMER
./mjpg_streamer -i “./input_uvc.so -f 60 -r 320x240” -o “./output_http.so -w ./www”

ofApp:setup()

void ofApp::setup(){
	SharedIPVideoGrabber grabber = IPVideoGrabber::makeShared();
	grabber->setCameraName("CAM1");
    grabber->setURI("http://192.168.1.90:8080/?action=stream");
    grabber->connect(); // connect immediately
}

Did I missed something or is there any incompatibility between mjpg-streamer and ofxIpVideoGrabber ?

Just in case, curl first chunk is

Server: MJPG-Streamer/0.2
Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0
Pragma: no-cache
Expires: Mon, 3 Jan 2000 12:34:56 GMT
Content-Type: multipart/x-mixed-replace;boundary=boundarydonotcross

--boundarydonotcross
Content-Type: image/jpeg
Content-Length: 7988
X-Timestamp: 6997.869066

����!AVI1xx��C

Hey, sorry I haven’t had a chance to test this. Could you post it as a bug over at the repo? I’m hoping to get it all updated soon.

Done !!