MJPEG on Android anyone?

All your problems with Audio, Video and Images.

Re: Mjpeg on Droid

Postby wally1944 » Tue Nov 17, 2009 9:20 pm

I tried one of the apps that says it supports avi and mjpeg (yxflash), but it just aborts immediately, so I can't tell much. Thanks for looking at this. I'll keep looking around. I can convert the files, but I don't see why the phone shouldn't just be able to play them. They aren't taxing to the hardware.
wally1944
Freshman
Freshman
 
Posts: 3
Joined: Mon Nov 16, 2009 6:03 pm

Top

Postby wirblix » Sat Nov 21, 2009 1:58 am

padde wrote:About the drop frame to stay in sync thingy... MJPEG isnt really
a video codec like others. Its a simple chain of JPEGs seperated
by a delimiter string. There is no information about sync or speed
at all in the stream itself.


I should probably have used a different word than "sync", since I actually meant it loses sync with reality. ;)

As a bandaid approach, is there any way to force the input stream to restart the stream every X seconds without actually disconnecting and reconnecting the http request? (ie every 30 seconds throw out any buffered frames and start fresh)
wirblix
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed Apr 29, 2009 12:10 am

Postby Ressor » Fri Jan 29, 2010 8:51 pm

This looks absolutely awesome! I've been dreaming of something just like it and I can;t wait to try it out!

Great contribution!!!
Ressor
Developer
Developer
 
Posts: 28
Joined: Wed Oct 14, 2009 11:43 pm
Location: Boston MA USA

Postby Ressor » Tue Feb 02, 2010 1:41 am

Ok... I thought this would be easy, but I'm reminded of how little I actually know again...

I tried creating the project with one package and adding the 3 classes, which compiles fine, but gets a FORCED CLOSE when it runs.

I also tried creating the project with 2 packages as described by another comment here and ended up with the same thing.

I have added the internet permissions so that isn't it. I don't have a layout file though because I didn't think I needed it here.

Maybe it's that I tried this with 2.0.1?

Any help would be appreciated.
Ressor
Developer
Developer
 
Posts: 28
Joined: Wed Oct 14, 2009 11:43 pm
Location: Boston MA USA

Postby Ressor » Tue Feb 02, 2010 1:56 am

Nevermind....stupid mistake!

Working on the delayed video issue now...
Ressor
Developer
Developer
 
Posts: 28
Joined: Wed Oct 14, 2009 11:43 pm
Location: Boston MA USA

Re: MJPEG on Android anyone?

Postby bl4d3 » Thu Jul 08, 2010 3:27 pm

I tried this code and it work really fine but I have some problem to integrate it with an intent, I made an activity(IntentTest) that call another activity(OtherActivity), last one show the stream from a remote cam.
Here the pain, I get this error:

Uncaught handler: thread main exiting due to uncaught exception

I'm really new on Android and I think I'm going to use too much memory and maybe I need a new Thread or somethink like this, anyone can give me an hint?

I past my code down here

IntentTest.java
Code: Select all
package com.test;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class IntentTest extends Activity {
    /** Called when the activity is first created. */
   ListView myListView = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        myListView = (ListView)findViewById(R.id.listView);
        final ArrayList<String> items = new ArrayList<String>();
        items.add("00408C944B9A");
        final ArrayAdapter<String> aa;
        aa = new ArrayAdapter<String>(this,
                             android.R.layout.simple_list_item_1,
                             items);
       
        myListView.setAdapter(aa);
        myListView.setOnItemClickListener(listClicked);
       
    }

   
    private OnItemClickListener listClicked = new OnItemClickListener() {
      public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
         // TODO Auto-generated method stub
         Intent i = new Intent(IntentTest.this, OtherActivity.class);
         i.putExtra("MAC", myListView.getItemAtPosition(position).toString());
         startActivity(i);         
      }
    };
}


OtherAvtivity.java
Code: Select all
package com.test;

import com.test.mjpeg.mjpegsample.MjpegView.*;
import com.test.parser.JSONParse;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class OtherActivity extends Activity {
    /** Called when the activity is first created. */
   private MjpegView mv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        Bundle extras = getIntent().getExtras();
        if (extras != null){
           String mac = (String)extras.get("MAC");
           Log.i("Other", "---->" + mac);
           TextView tv = (TextView)findViewById(R.id.textView);
           tv.setText(mac);
       
       
           String URL = "myurl";
          
           requestWindowFeature(Window.FEATURE_NO_TITLE);
           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);
          
           mv = new MjpegView(this);
           setContentView(mv);       
          
           mv.setSource(MjpegInputStream.read(URL));
           mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
           mv.showFps(true);     
          
        }
    }
   
   public void onPause() {
      super.onPause();
      mv.stopPlayback();
   }
   

}


I'm not going to paste the resto of the mjpeg code 'cause it is the same.
Hope someone can put me on the right way.
Thank you
bl4d3
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jul 08, 2010 3:01 pm

Top

Re: MJPEG on Android anyone?

Postby digitalmischief » Wed Jul 28, 2010 4:51 pm

Just wanted to say thanks for posting this code - just what I was looking for :)
digitalmischief
Freshman
Freshman
 
Posts: 9
Joined: Wed Jul 28, 2010 4:48 pm

Re:

Postby wirblix » Wed Jul 28, 2010 5:28 pm

Ressor wrote:Working on the delayed video issue now...


Have you had any luck with this by any chance?
wirblix
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed Apr 29, 2009 12:10 am

Re: MJPEG on Android anyone?

Postby Ressor » Wed Jul 28, 2010 6:24 pm

I have not... My guess is to try to restart the stream after a number of seconds to destroy the buffer... I've had no time to work on it though.
Ressor
Developer
Developer
 
Posts: 28
Joined: Wed Oct 14, 2009 11:43 pm
Location: Boston MA USA

Re: MJPEG on Android anyone?

Postby digitalmischief » Mon Aug 02, 2010 9:54 pm

Hi,

This code is working perfectly apart from one issue, if I have it playing the stream from one camera and then I want to change the source to be from another camera like below:

Code: Select all
mv.stopPlayback();
mv.setSource(MjpegInputStream.read(Studio));
mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
mv.showFps(true); 


It hangs on the setSource line with exception :

java.lang.IllegalThreadStateException: Thread already started.

I assume this because stopPlayback() has not finalised everything properly, do I need to do something other than just stopPlayback() ?

thanks!
digitalmischief
Freshman
Freshman
 
Posts: 9
Joined: Wed Jul 28, 2010 4:48 pm

Re: MJPEG on Android anyone?

Postby FilipeFreitas » Fri Aug 06, 2010 5:52 pm

digitalmischief wrote:Hi,

This code is working perfectly apart from one issue, if I have it playing the stream from one camera and then I want to change the source to be from another camera like below:

Code: Select all
mv.stopPlayback();
mv.setSource(MjpegInputStream.read(Studio));
mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
mv.showFps(true); 


It hangs on the setSource line with exception :

java.lang.IllegalThreadStateException: Thread already started.

I assume this because stopPlayback() has not finalised everything properly, do I need to do something other than just stopPlayback() ?

thanks!


If you're reusing the surface, do this:



mv.stopPlayback();

mv = new MjpegView(myContext, mSurfaceView);

mv.setSource(MjpegInputStream.read(Studio));
mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
mv.showFps(true);
mv.surfaceCreated(null);
FilipeFreitas
Junior Developer
Junior Developer
 
Posts: 14
Joined: Fri Aug 06, 2010 5:50 pm

Re: MJPEG on Android anyone?

Postby digitalmischief » Fri Aug 06, 2010 6:30 pm

thanks for the info, but Im a bit confused, I wasnt using a SurfaceView object as I did have the MjpegView view defined in the xml layout as in

Code: Select all
<view
  class="com.digitalmischief.housecontrol.MjpegView"
  android:id="@+id/mv"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  />


I have changeed it to use a SurfaceView but the constructor for the MjpegView view does not accept a SurfaceView as a parameter, it only has one which accepts an AttributeSet as the second parameter.

MjpegView(Context context, AttributeSet attrs)

any ideas?

thanks
digitalmischief
Freshman
Freshman
 
Posts: 9
Joined: Wed Jul 28, 2010 4:48 pm

Re: MJPEG on Android anyone?

Postby FilipeFreitas » Mon Aug 09, 2010 1:50 pm

You have this constructor too: MjpegView(Context context, SurfaceView mSurfaceView)

I don't understand how you can have MjpegView as a view, because i can't find where it extends a view. :?

On my layout xml i have this:
Code: Select all
   
<SurfaceView
      android:id="@+id/surface_camera"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_alignParentRight="true"
      >
</SurfaceView>


Then, on my code (onCreate) i have this:

Code: Select all
mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
mv = new MjpegView(this, mSurfaceView);
FilipeFreitas
Junior Developer
Junior Developer
 
Posts: 14
Joined: Fri Aug 06, 2010 5:50 pm

Re: MJPEG on Android anyone?

Postby digitalmischief » Mon Aug 09, 2010 3:15 pm

It works because MjpegView extends SurfaceView, which itself extends View - so we both effectively doing the same thing,

In the code on the original post of this thread (I assume thats where you got it from?!), in MjpegView the only constructor I have is,

Code: Select all
public MjpegView(Context context, AttributeSet attrs) {
super(context, attrs); init(context);
}


there does not seem to be any other constructor and the base class SurfaceView does not impliment any other constructors - I must be missing somthing?!

cheers
digitalmischief
Freshman
Freshman
 
Posts: 9
Joined: Wed Jul 28, 2010 4:48 pm

Re: MJPEG on Android anyone?

Postby FilipeFreitas » Mon Aug 09, 2010 3:51 pm

On the class MjpegView, i have this in the end:

Code: Select all
  public MjpegView(Context context, SurfaceView mSurfaceView) { super(); init(context, mSurfaceView); }   
    public void surfaceCreated(SurfaceHolder holder) { surfaceDone = true; }
    public void showFps(boolean b) { showFps = b; }
    public void setSource(MjpegInputStream source) { mIn = source; startPlayback();}
    public void setOverlayPaint(Paint p) { overlayPaint = p; }
    public void setOverlayTextColor(int c) { overlayTextColor = c; }
    public void setOverlayBackgroundColor(int c) { overlayBackgroundColor = c; }
    public void setOverlayPosition(int p) { ovlPos = p; }
    public void setDisplayMode(int s) { displayMode = s; }


I didn't write this code, it came with the sample i downloaded from here, so maybe we're using different versions. :?
FilipeFreitas
Junior Developer
Junior Developer
 
Posts: 14
Joined: Fri Aug 06, 2010 5:50 pm

Top
PreviousNext

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 13 guests