15

I am currently doing an AndAR project in group of 3. I'm the person who's in charge of video streaming into the Android phone. I got ourselves a D-Link DCS-920 IP camera and I found out that it uses MJPEG codec for the live video stream and the webserver uses Jview to view the live stream. As far as I know MJPG is not a supported file type for Android OS so I've came out with an idea, instead of using ImageView, I use WebView to stream the video. I've implemented a very simple concept and it works! But the problem is, refresh rate is terrible. I get the video image (eg: http://192.168.1.10/image.jpg) to view on the WebView and implement a Timer to control the refresh rate (supposed to set it to 30fps, which is refresh every 33ms) but it can only go up to 500ms interval, any lower interval I notice it will not be any smoother,sometimes the image wont load and connection is unstable (eg: dropped). Could this be I'm refreshing at a rate faster than it can receive? But over on the webserver Jview it has no problem! was trying to find the source code for the jview but I have no hope. Anyway here's the code I've written

package org.example.test;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

public class Webview extends Activity {

public WebView webView;
public Timer autoUpdate;
public String url;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);    

        webView = (WebView) findViewById(R.id.webview);
        webView.getSettings();
        final EditText urlText = (EditText) findViewById(R.id.urlText);

        //Buttons//////////////////------------
        final Button connectB = (Button)findViewById(R.id.connectButton);
        connectB.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
            //Actions goes here
          url = urlText.getText().toString();
          webView.loadUrl(url);
          timerSetup();
         }
        });
        final Button exitB = (Button)findViewById(R.id.exitButton);
     exitB.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
       //Actions goes here
       finish();
      }
     });
   }

    //refresh timer//////////////-----------------
    public void timerSetup(){
     autoUpdate = new Timer();
     autoUpdate.schedule(new TimerTask() {
      @Override
      public void run() {
       runOnUiThread(new Runnable() {
        @Override
     public void run() {
         //Actions goes here
         webView.loadUrl(url);
        }
       });
      }
     }, 0, 500);//refresh rate time interval (ms)
    }
}

Is there anyway I can get the video stream in by at least 15fps/have a faster refresh rate? Are there any such thing as MJPEG viewer/source code that I can use to display these images?

here's the screenshot of the app http://s945.photobucket.com/albums/ad295/kevinybh/?action=view&current=video.jpg (not enough points to post pictures) :(

I just need to make the video stream around 15-30fps. any suggestions/help would be very deeply appreciated :) Thanks!

Divya Jain
  • 393
  • 1
  • 6
  • 22
Kevin
  • 151
  • 1
  • 1
  • 3
  • It's very likely it will take longer than 33ms to load the picture over the network. Can you just try and reload the picture every time the previous has finished loading? – Jess Dec 20 '10 at 15:14
  • how do i do that? i mean check if it's finish loading the picture and reloads it right after it finish loading – Kevin Dec 20 '10 at 16:29

5 Answers5

1

Instead of an Arduino you could use a Raspberry PI, it should have enough CPU power to control the vehicle and to convert the video stream at the same time. Sure, you'll need to port all of your Arduino software to Raspberry...

Marco
  • 349
  • 1
  • 6
  • @FlashThunder I've never used a Raspberry yet, but as far as I know it runs some kind of Linux, has a powerful GPU and there is who says it is even able to encode H.264 video 1080p at 30 fps. I am very very skeptical on 1080p video, but it probably can encode IPcam's VGA 640x480 video streams. http://harrybuttle.wordpress.com/2013/08/05/hardware-transcoding-on-the-raspberry-pi/ If more power is needed, there's also who builds Raspberry's clusters. Just google "Raspberry video encoding" and/or "Raspberry cluster". – Marco Mar 13 '14 at 09:17
  • It is only 700Mhz processor... I really doubt that it could encode in real time... – Flash Thunder Mar 13 '14 at 10:39
  • The power of the Raspeberrypi really depends on if you can make its highly proprietary GPU do the job, or if you have to do it with the relatively wimpy CPU. If you can get the GPU docs from broadcomm, or your need is supported by available code written by someone who already did, great. If not, the CPU may not be up to the task. – Chris Stratton Jul 29 '14 at 21:34
0

You can use MjpegView class to display mjpeg stream directly. https://code.google.com/p/android-camera-axis/source/browse/trunk/serealisation/src/de/mjpegsample/MjpegView/MjpegView.java?r=33

You'll have to implement some AsyncTasks on this class to works fine.

Good luck

robpf
  • 1
0

MJPEG is a terribly inefficient way to deliver motion video to a mobile device, because each frame is compressed as it's own independent picture. For an application which doesn't need video (someone was asking about a camera watching waiting lines last week) your solution of pushing a static frame every second or so sounds good.

If you need motion video, I would recommend you do transcoding on your webserver from MJPEG to a supported video format which utilizes frame-to-frame compression. This will result in far less data to push, both over the user's 3g connection and from your server to all of its clients. You should only need to run one transcoding engine to support all clients - and you'll be able to use the same one for android & iphone devices, though you may want to also have a higher resolution output for tablets and pc's if your camera output is good enough to justify it.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • the webserver comes together with the camera itself, and the only supported compression that i can choose is MJPEG. how do i transcode it to other format? – Kevin Dec 21 '10 at 04:07
  • You'd probably need other webserver software (running on a server between the camera and the clients). You might be able to experimentally do something with VLC, though that's a package with a lot of technology hiding behind a rather inconsistent configuration interface. – Chris Stratton Dec 21 '10 at 17:03
  • Which means i have to stream my IP cam using VLC? Actually my project is a RC Vehicle Augmented Reality Game. so i have a wireless IP cam attached to the vehicle and an Arduino board with WiFly shield attached to it. I'm supposed to stream the video from the IP to my android phone and be able to control the vehicle from the phone at the same time. My plan is to eliminate the router and the laptop so it's a direct P2P connection from the phone to the vehicle. Any idea how? Worse case scenario i'll just have to attach a router and a laptop later on if things doesn't work out :( – Kevin Dec 22 '10 at 05:24
  • It's possible you could get this to work with an android phone having a fast enough processor to do MJPEG decoding using mplayer or ffmpeg, but I think you'd be better off using a PC somewhere in the middle to transcode to mpeg4 and keep the android phone doing standard things. If it's just for private use VLC probably can be configured to do the transcoding for you (not sure that it's up to be a multi-client public-facing server for the web). I guess in the end it's where you are more comfortable hacking - weird android stuff or setting up a pc server. I hope this isn't a plane. – Chris Stratton Dec 22 '10 at 17:06
  • i wouldnt want a pc to be interfaced in between bcoz my plan is to have a direct p2p connection from the android phone to the vehicle/camera. any source that i can refer to in this case? :) like a source code to transcode mjpg to other format let say jpg? – Kevin Dec 29 '10 at 07:04
0

On android, if we decode a jpeg by CPU, it will cost 40-100ms. If we want to play mjpeg to 15-30fps, we need hardware jpeg decoder.

xufan
  • 392
  • 1
  • 5
  • 18
0

There was a useful previous SO discussion and this great one with code. Would you try and let us know if that works for you.

Community
  • 1
  • 1
Walter K
  • 1,474
  • 1
  • 14
  • 24