What are the application examples of WebCam snap

Source: Internet
Author: User
Tags bind manual locale git clone

We believe that many people have used webcam. The use of webcam is not unfamiliar. In today's example, we introduce the snap design of webcam. If you've seen my Ubuntu core IoT design before, it's probably no stranger to the project. You can refer to my article "Snapcraft hands-on---Web Camera". Unfortunately, the webcam in that article was not tested on the desktop in the context of KVM, unless we installed a snappy computer system. In today's snap combat, our main design is almost the same as in the past, with only a few minor changes (this is due to the continuous evolution of our snap design).

Webcam design of the source code we can find at the following address:

Https://github.com/snapcore/snapcraft/tree/master/demos/webcam-webui

We can put the source code down by using the following method:

$ git clone https://github.com/ubuntu-core/snapcraft
$ cd Snapcraft/demos

For an introduction to the webcam application, you can find it at the following address:

https://developer.ubuntu.com/en/snappy/build-apps/your-first-snap/

Let's first look at the Snapcraft.yaml of this application: Snapcraft.yaml

Name:webcam-webui
version:1
Summary:webcam Web UI
description:exposes your webcam over a Web UI
Confin Ement:strict

Apps:
  webcam-webui:
    command:bin/webcam-webui
    daemon:simple
    plugs: [ Network-bind]

parts:
  cam:
    plugin:go
    go-packages:
      -Github.com/mikix/golang-static-http
    stage-packages:
      -Fswebcam
    filesets:
      fswebcam:
        -Usr/bin/fswebcam
        -Lib
        -usr/ Lib
      go-server:
        -bin/golang-*
    stage:
      -$fswebcam
      -$go-server
    snap:
      -$fswebcam
      -$go-server
      --usr/share/doc
  glue:
    plugin:copy
    files:
      webcam-webui:bin/ Webcam-webui

Fswebcam's user manual can be found in the link.
Note: This is so far the Snapcraft.yaml file, which does not have a camera plug. We have reported a bug. If you package this application directly:
$ snapcraft

and install this application:
$ sudo snap install Webcam-webui_1_amd64.snap--force-dangerous

Because this application is a daemon type of application. We see it as a service, that is, we don't need to start the app manually. It is automatically run at the time of installation. I can open the following address in our browser:


Obviously, our webserver is already working, but we can't see any of the camera outputs. What is this for? We use the following command to view the logs of our service runs:
$ journalctl-u Snap.webcam-webui.webcam-webui

We have the following results:

We can see that some of the information (remember to turn to the last message). Obviously it shows:
July 10:33:13 liuxg ubuntu-core-launcher[13442]: Trying source module V4l2 ...
July 10:33:13 liuxg ubuntu-core-launcher[13442]: Error opening device:/dev/video0
July 10:33:13 liuxg ubuntu-core-l AUNCHER[13442]: Open:permission denied

What does that mean? It shows that we are having a security problem. Our app cannot open the device/dev/video0. So how are we going to correct our problem? Let's enter the following command in the terminal:
liuxg@liuxg:~$ Snap Interfaces
Slot                 Plug
: Camera              -
: Cups-control        -
: Firewall-control    -
: Gsettings           -
: Home                -
: Locale-control      -
: Log-observe         -
: Modem-manager       -
: Mount-observe       -
: Network             -
: Network-bind        Webcam-webui
: Network-control     -
: Network-manager     -
: Network-observe     -
: OpenGL              -
: optical-drive       -
:p pp                 -
:p ulseaudio          -
: Snapd-control       -
: System-observe      -
: Timeserver-control  -
: Timezone-control    -
: Unity7              -
: X11                 -

Note the first slot in our list: Camera. We are thinking that this application is not a camera application. If we want to access the camera we have to set up camera plug so that we can really access our device. With this in mind, we add a camera to our snapcraft.yaml. The later Snapcraft.yaml files are as follows:
Snapcraft.yaml
Name:webcam-webui
version:1
Summary:webcam Web UI
description:exposes your webcam over a Web UI
Confin Ement:strict

Apps:
  webcam-webui:
    command:bin/webcam-webui
    daemon:simple
    plugs: [Camera, Network-bind]

parts:
  cam:
    plugin:go
    go-packages:
      -Github.com/mikix/golang-static-http
    stage-packages:
      -Fswebcam
    filesets:
      fswebcam:
        -Usr/bin/fswebcam
        -Lib
        -usr/ Lib
      go-server:
        -bin/golang-*
    stage:
      -$fswebcam
      -$go-server
    snap:
      -$fswebcam
      -$go-server
      --usr/share/doc
  glue:
    plugin:copy
    files:
      webcam-webui:bin/ Webcam-webui

Please note that we have added a camera to the plug. Repackage and install our app. We run again:
liuxg@liuxg:~$ SNAP Interfaces Slot Plug:camera-: Cups-control-: Firewall-control -: gsettings-: Home-: Locale-control-: Log-observe-: Modem-manager-: Mo 
Unt-observe-: Network-: Network-bind Webcam-webui:network-control-: Network-manager- : Network-observe-: OpenGL-: optical-drive-:p pp-:p ulseaudio-: SNAPD                 -control-: System-observe-: Timeserver-control-: Timezone-control-: Unity7-: X11 -liuxg@liuxg:~$ Snap Interfaces Slot Plug:camera-: Cups-control-: Firewall       -control-: gsettings-: Home-: Locale-control-: Log-observe-: Modem-manager -: Mount-observe-: Network-: Network-bind Webcam-webui:network-control-: Network-man Ager-: Network-obseRve-: OpenGL-: optical-drive-:p pp-:p ulseaudio-: Snapd-control                    -: System-observe-: Timeserver-control-: Timezone-control-: Unity7-: X11--
 Webcam-webui:camera

Obviously, this time, we saw:
-                    Webcam-webui:camera

Although the camera's plug is shown here, it is not really connected. We look at document Interfaces. In this article:
Camera

Can access the first video camera. Suitable for programs wanting to use the webcams.

Usage:common Auto-connect:no

It shows: Auto-connect:no. We need to connect manually.
$ sudo snap connect Webcam-webui:camera Ubuntu-core:camera

With the above command, we can make a manual connection between a Plug and a slot. Rerun the following command:
liuxg@liuxg:~$ Snap Interfaces
Slot                 Plug
: Camera              webcam-webui
: Cups-control        -
: Firewall-control    -
: Gsettings           -
: Home                -
: Locale-control      -
: Log-observe         -
: Modem-manager       -
: Mount-observe       -
: Network             -
: Network-bind        Webcam-webui
: Network-control     -
: Network-manager     -
: Network-observe     -
: o Pengl              -
: optical-drive       -
:p pp                 -
:p ulseaudio          -
: Snapd-control       -
: System-observe      -
: Timeserver-control  -
: Timezone-control    -
: Unity7              -
: X11                 -

This time, we saw that our application Webcam-webui has been established and connected with Network-bin and camera. We open our browser again:





The source code of our whole project is: Https://github.com/liu-xiao-guo/webcam-snap
We can query the operation of our service in the following way:
$ systemctl status-l Snap.webcam-webui.webcam-webui

liuxg@liuxg:~$ systemctl status Snap.webcam-webui.webcam-webui snap.webcam-webui.webcam-webui.service-service for Snap Application Webcam-webui.webcam-webui loaded:loaded (/etc/systemd/system/ Snap.webcam-webui.webcam-webui.service; Enabled Vendor Prese Active:active (running) since two 2016-07-19 12:38:02 CST; 36min ago Main pid:16325 (Webcam-webui) CGroup:/system.slice/snap.webcam-webui.webcam-webui.service├─163  25/bin/sh/snap/webcam-webui/x1/bin/webcam-webui├─16327 golang-static-http└─17488 Sleep 10 July 19
13:14:31 LIUXG ubuntu-core-launcher[16325]: Adjusting resolution from 384x288 to 960x540.
July 13:14:31 liuxg ubuntu-core-launcher[16325]:---capturing frame ...
July 13:14:31 liuxg ubuntu-core-launcher[16325]: Captured frame in 0.00 seconds.
July 13:14:32 liuxg ubuntu-core-launcher[16325]:---processing captured image ... July 13:14:32 liuxg ubuntu-core-launcher[16325]: fontconfig error:cannot load Default Config file July 19 13:14:32 liuxg ubuntu-core-launcher[16325]: fontconfig error:cannot load Default Config file July 13:14:32 liuxg ubunt U-CORE-LAUNCHER[16325]: fontconfig error:cannot load Default Config file July 13:14:32 liuxg ubuntu-core-launcher[16325] : Unable to load font ' sans ': fontconfig:couldn ' t f July 13:14:32 LIUXG ubuntu-core-launcher[16325]: Disabling the B
Anner. July 13:14:32 liuxg ubuntu-core-launcher[16325]: Writing JPEG image to ' shot.jpeg '.
We can stop a service in the following way:
$ sudo systemctl stop Snap.webcam-webui.webcam-webui

We can start a service in the following way:
$ sudo systemctl start Snap.webcam-webui.webcam-webui





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.