Go Down

Topic: Guide to Setup Streaming Web Cam on the Yun (Read 82811 times) previous topic - next topic

Vadorequest

Hi, I would like to know if there is a way to start the stream from the Arduino program, because by now I have to manually connect using SSH and enter the following command line:
Code: [Select]
mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480" -o "output_http.so -p 8080 -w /mnt/share"

I would like to execute this command line from the Arduino, or from my Android application, there is a way?
Thank you.

Vadorequest

I did it using this library:
jsch-0.1.50.jar

http://www.jcraft.com/jsch/
http://epaul.github.io/jsch-documentation/simple.javadoc/

Source code:
Code: [Select]

package com.iha.wcc.job.ssh;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import com.jcraft.jsch.*;
import java.util.Properties;

/**
* Run a SSH command using Jsch library.
*/
public class SshTask extends AsyncTask<String, Integer, Boolean> {
    private static Session session;
    private static Channel channel;

    private Context context;
    private String host;
    private String user;
    private String password;
    private String command;

    /**
     * Constructor that load the necessary information to connect using SSG protocol.
     * @param context   Activity context, useful to display message.
     * @param host      Host IP to reach.
     * @param user      SSH user name.
     * @param password  SSH user password.
     * @param command   SSH command to execute.
     */
    public SshTask(Context context, String host, String user, String password, String command){
        this.context = context;
        this.host = host;
        this.user = user;
        this.password = password;
        this.command = command;
    }

    /**
     *
     * @param arg0
     * @return
     */
    @Override
    protected Boolean doInBackground(String... arg0) {
        JSch jsch=new JSch();

        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");

        Session session;
        try {
            session = jsch.getSession(user, host, 22);
            session.setConfig(config);
            session.setPassword(password);
            session.connect();

            ChannelExec channel = (ChannelExec)session.openChannel("exec");
            channel.setCommand(command);
            channel.connect();

            SshTask.session = session;
            SshTask.channel = channel;

            return true;
        } catch (JSchException e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    protected void onPostExecute(Boolean success){
        if(success){
            Toast.makeText(this.context, "Video stream successfully started.", Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(this.context, "Unable to start the camera video stream.", Toast.LENGTH_LONG).show();;
        }
    }

    /**
     * Shutdown the camera video stream.
     */
    public static void disconnect(){
        if(SshTask.session != null){
            SshTask.channel.disconnect();
            SshTask.session.disconnect();
        }
    }

}

sonnyyu

opkg update
opkg install nano

nano /etc/config/mjpg-streamer

Code: [Select]

config mjpg-streamer core
option enabled "1"
option device "/dev/video0"
option resolution "640x480"
option fps "30"
option www "/www/webcam"
option port "8080"


/etc/init.d/mjpg-streamer enable
/etc/init.d/mjpg-streamer stop
/etc/init.d/mjpg-streamer start

access video from http://arduino.local:8080


federicofissore

The init.d way is nice :)

BTW Vadorequest, can't you do that with runShellCommand?

ProfePaco

And what about the audio?

Many cams have mic. So, can we streaming the audio at the same time?

Francisco

Vadorequest

Good question, I didn't try to do that. Should be possible.

ProfePaco


Good question, I didn't try to do that. Should be possible.


when you have a IP web Cam. It is possible. I had one.

However, I think that the audio only worked with one browser, MS explorer, I think... not sure.

ProfePaco

I have been using Microsoft HD-3000 webcam with success.

Now I want to use another UVC webcam. However, it does not work.

Must I do something different if I want to use another cam? Should I indicate to the driver that the new cam has to be used now?

BTW, no ideas on audio streaming?

Merry Christmas,

Francisco

demolishun

I have the streaming setup to my Yun and can view in browser. 

So how do I get this stream to a website streaming service?

I have searched around and cannot make heads or tails on how to do this.

sonnyyu


...
So how do I get this stream to a website streaming service?
...


What do you mean?

roadfun

I think he was asking how he could view the stream remotely, when not on the local network. Poking a hole through the firewall and mapping to the Yun would be one answer, I suppose. But I have not yet tried it myself.

Has anyone had problems with mjpg_streamer crashing after running for awhile? If so, do you know how to prevent this?

sonnyyu

Use top and free to monitor memory and cpu usage.

if high then change

Code: [Select]
option fps "30"

to

Code: [Select]
option fps "15"

roadfun

I have mjpg_streamer working ok with my Yun and camera but I'm interested in customizing it for my video monitoring project. I have searched and haven't found instructions for how to do something like this on the Yun (i.e. build the package after customizing the source). Any pointers would be appreciated. The hacks I have in mind would likely be useful to others.

Alternately or in addition I'm thinking of some hacks to fswebcam that should be useful for monitoring too.

Cheers.

sonnyyu

#43
May 06, 2014, 06:42 pm Last Edit: May 06, 2014, 06:51 pm by sonnyyu Reason: 1
Video application is very CPU-Intensive, Yun CPU might be suffer for speed . if high resolution and high fps is needed by use high speed CPU board or router.

http://forum.arduino.cc/index.php?topic=187766.msg1711221#msg1711221


roadfun

I understand the CPU limitations but that's not the issue I'm trying to address. E.g. mjpg_streamer takes forever to take a first photo when you have it writing to a file. fswebcam does it very quickly. So it is an issues with the mjpg_streamer could I believe.

Go Up