LoginSignup
14
7

More than 5 years have passed since last update.

PythonのWebRTC実装を、Dockerで動かして見た

Last updated at Posted at 2018-05-03

はじめに

aiortc とは、Pythonで実装されたWebRTCのライブラリです。ネイティブライブラリである libwebrtc を使わずに作られています。このサンプルをDockerを使って動かして見ました。

環境

  • ホストOS: Mac OS X 10.12.6 (Sierra)
  • Docker: Docker for Mac Version 17.06.0-ce-mac18 (18433)
  • コンテナのベース: Ubuntu 18.04 LTS

Ubuntu 18.04 LTSがリリースされていたので、今回はそれをベースにしました。

Dockerfile

使ったDockerfileはこちらです。

  • python3
  • libopus-dev, libvpx-dev
  • libffi-dev, libssl-dev
  • libopencv-dev (2018.07.03 追加)

等をインストールしています。

# Ubuntu 18.04 and aiortc
#  aiortc: https://github.com/jlaine/aiortc

FROM ubuntu:18.04
MAINTAINER mganeko

#  
# -- if you are using docker behind proxy, please set ENV --
#
#ENV http_proxy "http://proxy.yourdomain.com:8080/"
#ENV https_proxy "http://proxy.yourdomain.com:8080/"

#
# -- set ENV for non-interactive
#
ENV DEBIAN_FRONTEND=noninteractive

# -- build step --
RUN apt update
RUN apt upgrade -y

RUN apt install python3 -y
RUN apt install python3-pip -y
RUN apt install python3-dev -y
RUN python3 -V
RUN pip3 -V
RUN pip3 install --upgrade pip
RUN pip -V


RUN apt install libopus-dev -y
RUN apt install libvpx-dev -y
RUN apt install libffi-dev -y
RUN apt install libssl-dev -y
RUN apt install libopencv-dev -y

RUN apt install git -y

RUN mkdir /root/work 
WORKDIR /root/work/
RUN git clone https://github.com/jlaine/aiortc.git

RUN pip install aiohttp
RUN pip install aiortc 
RUN pip install opencv-python

# --- for running --
EXPOSE 8080

WORKDIR /root/work/aiortc/examples/server/
CMD [ "python3", "server.py" ]

※ 最新版で動かないと指摘をいただいて、修正しました(2018.07.03)

ビルド手順

ターミナルから docker build を実行(イメージ名は適宜付けてください)

$ docker build -t mganeko/ubuntu18_aiortc -f Dockerfile .

実行手順

(1) ターミナルから docker run でコンテナを起動

$ docker run -d -p 8001:8080 mganeko/ubuntu18_aiortc
  • この例ではホストOSの8001ポートをコンテナの8080ポートに接続しています。
  • コンテナの内部では aiortc/examples/server/server.py を起動しています。

(2) Chromeで http://localhost:8001/ にアクセス

  • Firefox, Safariではサーバーからエラーが返ってきて動きませんでした

(3) [Use video]をチェック、[start]ボタンをクリック

うまく動けば次のようになるはずです。

  • Mediaの欄にカメラの映像と、選んだ画像効果の映像が交互に表示されます
    • 輪郭検出
    • 回転
    • 濃い緑のベタ塗り
    • 効果無し(カメラ映像のまま)
  • Data channel の欄に ping/pong とサーバーとのデータ交換の様子が表示されます

おわりに

aiortcはPythonを使ってWebRTCを独自に実装しているユニークなプロジェクトです。Dockerを使うことで、手軽に試すことができました。
ソースコードはまだ全然読めてませんが、少しずつ眺めて見たいと思います。

14
7
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
7