Guide to Setup Streaming Web Cam on the Yun

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:

mjpg_streamer -i " -d /dev/video0 -r 640x480" -o " -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:

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

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 [u]audio[/u]?

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.

Vadorequest: 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.

demolishun: ... 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

option fps      "30"


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.


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.

if high resolution and high fps is needed by use high speed CPU board or router.

high resolution could be >= 4K high fps could be >=60 fps

Some time high speed CPU is not even enough. We need GPU ( Graphics processing unit) and Multi-core one.

I guess I'm not explaining it well. I am not concerned with the frame rate, that's fine.

When I start fswebcam it can take a first picture very quickly. However when I start mjpg_streamer it takes it up to 8 seconds to capture an initial image (using the module). I'd like to optimize the time to capture the first image in mjpg_streamer.

My video knowledge is rusty - almost 20 years old. I will try my best. The mjpg_streamer use M-JPEG under hook.

M-JPEG is an intraframe-only compression scheme (compared with the more computationally intensive technique of interframe prediction). Whereas modern interframe video formats, such as MPEG1, MPEG2 and H.264/MPEG-4 AVC, achieve real-world compression-ratios of 1:50 or better, M-JPEG's lack of interframe prediction limits its efficiency to 1:20 or lower. But since it is an intraframe-only compression scheme the capture frame become very easy.

Plan A. drop a line to mjpg_streamer team.

Plan B. test more robust ffmpeg-server which also provides M-JPEG streaming support.

Hi everyone

I have following this guide and have some problem with install the video4linux2

I try the command: opkg install v4l2 and this is what I get: """"" Unknown package 'v4l2'. Collected errors: * opkg_install_cmd: Cannot install package v4l2. root@arduino:~# """""

Please tell me where to get the package smiley-cry

My computer science class group is working on an Arduino project and hope that it can stream video

Thanks in advance smiley

Wow so many replies here since I started this thread some time back. Apologies I have not replied to anyone, literally flat out with work here so I haven't actually checked this threat much since then. Actually I am still building my robot slowly... It now also had a Wi-Fi operated claw to pick up/move objects remotely and a self charge mechanism. Will post some pics/movie when I get a chance to finish it one day.

A PM from someone prompted me to check this thread, I hope everyone was able to rectify their issues and have their questions answered.

If the instructions are followed correctly from the first page, you should have no issues. If not then please factory reset your unit and start again. Note I only tested this with a particular camera (HD-3000). Some cameras may use different drivers which may require additional or different steps to set it up.

Please note, there is a continuation of my original guide (1st post of this thread) on the 8th post of the first page for faster streaming using mjpg-streamer. Please take note of that as well.

Also there may be an easier way of setting this up now since the Yun has been out for some time. Not sure as I haven't tinkered with it for some time..

Also this may be of use to some:

Best of luck with it