Go Down

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


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.


I did it using this library:


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
    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);

            ChannelExec channel = (ChannelExec)session.openChannel("exec");

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

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

    protected void onPostExecute(Boolean success){
            Toast.makeText(this.context, "Video stream successfully started.", Toast.LENGTH_SHORT).show();
            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){



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


The init.d way is nice :)

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


And what about the audio?

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



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


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.


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,



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.


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

What do you mean?


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?


Use top and free to monitor memory and cpu usage.

if high then change

Code: [Select]
option fps "30"


Code: [Select]
option fps "15"


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.



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.



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