Skip to content

Instantly share code, notes, and snippets.

@kgbu
Created July 2, 2015 21:02
Show Gist options
  • Select an option

  • Save kgbu/0238dd2282d144a42779 to your computer and use it in GitHub Desktop.

Select an option

Save kgbu/0238dd2282d144a42779 to your computer and use it in GitHub Desktop.
RaspberrypiでWebRTCによるVideoストリーミングをブラウザで表示してみた

RaspberrypiでWebRTCによるVideoストリーミングをブラウザで表示

参考サイトそのまんまです。Much Thanks to all.

参考サイト

HW構成

Raspi2にWiFi-USBとcameraモジュールを取り付けた(その他にBLEのドングルもあるが気にしない) 以下、USB機器の接続状態

$ lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 005: ID 0411:01a2 BUFFALO INC. (formerly MelCo., Inc.) WLI-UC-GNM Wireless LAN Adapter [Ralink RT8070]

cameraをenableする

sudo raspi-config
sudo restart

カメラテスト:JPG画像撮影

raspistill -o test.jpg

WebRTC Video Streaming

Janusのインストールとセットアップ

ライブラリのインストール

$ sudo aptitude update
$ sudo aptitude install libmicrohttpd-dev libjansson-dev libnice-dev libssl-dev libsrtp-dev libsofia-sip-ua-dev libglib2.0-dev libopus-dev libogg-dev libini-config-dev libcollection-dev pkg-config gengetopt libtool automake dh-autoreconf

Janusのビルド

$ git clone https://github.com/meetecho/janus-gateway.git
$ cd janus-gateway
$ sh autogen.sh
$ ./configure --disable-websockets --disable-data-channels --disable-rabbitmq --disable-docs --prefix=/opt/janus
$ make
$ sudo make install
$ sudo make configs

/opt/janus/etc/janus/janus.plugin.streaming.cfg の編集

$ sudo nano janus.plugin.streaming.cfg

以下の内容を追加して、他はコメントアウトする。

[gst-rpwc]
type = rtp
id = 1
description = RPWC H264 test streaming
audio = no
video = yes
videoport = 8004
videopt = 96
videortpmap = H264/90000
videofmtp = profile-level-id=42e028\;packetization-mode=1

gStreamerとNginxのインストール

$ sudo aptitude install gstreamer1.0-alsa gstreamer1.0-audiosink gstreamer1.0-audiosource gstreamer1.0-doc gstreamer1.0-libav gstreamer1.0-omx gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-videosink gstreamer1.0-videosource gstreamer1.0-visualization gstreamer1.0-x

$ sudo aptitude install nginx
$ sudo cp -r /opt/janus/share/janus/demos/ /usr/share/nginx/www/
$ sudo service nginx start

Videoキャプチャ開始

$ raspivid --verbose --nopreview -hf -vf --width 640 --height 480 --framerate 15 --bitrate 1000000 --profile baseline --timeout 0 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink host=127.0.0.1 port=8004

WebRTC start

$ cd /opt/janus/bin
$ ./janus -F /opt/janus/etc/janus/

デモcontentsの中身

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Janus WebRTC Gateway: Streaming Demo</title>
<script type="text/javascript" src="jquery.min.js" ></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/bootbox.min.js"></script>
<script type="text/javascript" src="js/spin.min.js"></script>
<script type="text/javascript" src="janus.js" ></script>
<script type="text/javascript" src="streamingtest.js"></script>
<link rel="stylesheet" href="css/cerulean/bootstrap.css" type="text/css"/>
<link rel="stylesheet" href="css/demo.css" type="text/css"/>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"/>
</head>
<body>

<a href="https://github.com/meetecho/janus-gateway"><img style="position: absolute; top: 0; left: 0; border: 0; z-index: 1001;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_darkblue_121621.png" alt="Fork me on GitHub"></a>

<nav class="navbar navbar-default navbar-static-top">
<div class="container">
	<div class="navbar-header">
		<a class="navbar-brand" href="index.html">Janus</a>
		<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
		</button>
	</div>
	<div class="navbar-collapse collapse">
		<ul class="nav navbar-nav">
			<li><a href="index.html">Home</a></li>
			<li class="dropdown active"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Demos <b class="caret"></b></a>
				<ul class="dropdown-menu">
					<li><a href="demos.html">Index</a></li>
					<li class="divider"></li>
					<li><a href="echotest.html">Echo Test</a></li>
					<li class="active"><a href="streamingtest.html">Streaming</a></li>
					<li><a href="videocalltest.html">Video Call</a></li>
					<li><a href="siptest.html">SIP Gateway</a></li>
					<li><a href="videomcutest.html">Video MCU</a></li>
					<li><a href="audiobridgetest.html">Audio Conference</a></li>
					<li><a href="voicemailtest.html">Voice Mail</a></li>
					<li><a href="recordplaytest.html">Recorder/Playout</a></li>
					<li><a href="screensharingtest.html">Screen Sharing</a></li>
					<li class="divider"></li>
					<li><a href="admin.html">Admin/Monitor</a></li>
				</ul>
			</li>
			<li><a href="docs">Documentation</a></li>
			<li><a href="citeus.html">Cite us!</a></li>
		</ul>
		<div class="navbar-header navbar-right">
			<ul class="nav navbar-nav">
				<li><a href="http://groups.google.com/d/forum/meetecho-janus" class="navbar-link"><b>Discuss Janus</b></a></li>
				<li><a href="http://www.meetecho.com" class="navbar-link"><img src="meetecho-logo-white.png"/> <b>Meetecho</b></a></li>
			</ul>
		</div>
	</div>
</div>
</nav>

<div class="container">
	<div class="row">
		<div class="col-md-12">
			<div class="page-header">
				<h1>Plugin Demo: Streaming
					<button class="btn btn-default" autocomplete="off" id="start">Start</button>
				</h1>
			</div>
			<div class="container" id="details">
				<div class="row">
					<div class="col-md-12">
						<h3>Demo details</h3>
						<p>This demo showcases the functionality provided by the Streaming plugin.
						In particular, it provides three different streaming approaches, namely:</p>
						<p><ol>
							<li>An on-demand stream originated by a file (a song, in this case):
							different users accessing this stream would receive a personal view
							of the stream itself.</li>
							<li>A pseudo-live stream, still originated by a file (an audio recording
							of a radio running commentary): different users accessing this stream
							would all receive the same, shared view of the stream.</li>
							<li>A live stream, originated by a gstreamer script: as for the pseudo-live
							stream, different users will get the same feed.</li>
						</ol></p>
						<p>You can try them all within the same session: just choose the stream
						you're interested in and press the <code>Watch</code> button to start
						the playout. Stopping it will allow you to switch to a different one.</p>
						<p>Press the <code>Start</code> button above to launch the demo.</p>
					</div>
				</div>
			</div>
			<div class="container hide" id="streams">
				<div class="row">
					<div class="col-md-6">
						<div class="panel panel-default">
							<div class="panel-heading">
								<h3 class="panel-title">Streams <i id="update-streams" class="fa fa-refresh" title="Update list of streams" style="cursor: pointer;"></i></h3>
							</div>
							<div class="panel-body" id="list">
								<div class="btn-group btn-group-sm">
									<button class="btn btn-primary" autocomplete="off" id="watch">Watch or Listen</button>
									<div class="btn-group btn-group-sm">
										<button autocomplete="off" id="streamset" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
										Streams list<span class="caret"></span>
										</button>
										<ul id="streamslist" class="dropdown-menu" role="menu">
										</ul>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="panel panel-default">
							<div class="panel-heading">
								<h3 class="panel-title">Stream <span class="label label-info hide" id="status"></h3>
							</div>
							<div class="panel-body" id="stream"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<hr>
	<div class="footer">
	<p>Janus WebRTC Gateway &copy; <a href="http://www.meetecho.com">Meetecho</a> 2014</p>
	</div>
</div>

</body>
</html>

Browserでみてみる

ラズパイのDHCPでのアドレスが192.168.1.145だったので、以下のURLでアクセス

http://192.168.1.145/demos/streamingtest.html

結果は https://twitter.com/ocaokgbu/status/616706872448413697

@kgbu

kgbu commented Jul 3, 2015

Copy link
Copy Markdown
Author

demoコンテンツの中身は要点だけに絞りたい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment