2015. október 13., kedd

Wowza Streaming Engine 4.3 is out

Just saw today that Wowza Streaming Engine 4.3 is out. Quick summary of the main changes are:
  • The REST API that has been around for a while is now opened up to everyone and got the version name 1.0 (which is v2 for some reason in the actual URLs..)
  • A new API has been added that allows extracting clips from live streams. See the corresponding API comments here 
  • A new stream target option appears on the Engine Manager interface to deliver output directly to their Wowza Streaming Cloud. (Version 4.2 previously made similarly easy for delivering to YouTube)
  • Specific and upgraded JVC camcorders can deliver RTMP stream now directly to Wowza (to be honest I am not sure about this, I thought that this should not be a change in Wowza itself, only the camcorder firmware)
  • MPEG-DASH Example Player updated and is based on Google Shaka Player
  • New Java API methods to control purging of Media Cache Elements (see MediaCache here)
  • HEVC (High Efficiency Video Coding)/H.265 Video over Apple HLS preview available in the Transcoder
The detailed list of changes can be found here, one point that was interesting to me is:
  • Updated genkey.bat to work with updated environment variables created with Wowza Streaming Engine 4.2 installers
This was an annoying bug that I reported when I tried installing 4.2 on a non-English Windows box. The script that was setting file permissions assumed English default group names and was unable to handle the lack of these groups, causing the installer to throw an error and delete everything. The support was quick and helpful and the fix came out in the next minor release.

2015. október 5., hétfő

Video.js Authentication with Wrench

This article shows how to set up authentication for you video streams using the probably most popular opensource video player Video.js and Wowza Streaming Engine.

The authentication will be provided by Wrench which is a quite powerful module for Wowza. The main idea behind Wrench is that you need to add a special parameter to your video URL which is transparently sent back to the streaming server. Wrench once configured properly in the Wowza Streaming Engine will grab this token from the connection request and validate it against a custom webservice that you need to implement or alternatively use any relational database to check the token with the SQL you can configure.

There are some good tutorials on how to set up Wrench with JW Player and MySQL with a simple PHP demo page. I strongly suggest reading that first to get a basic understanding of what we'll do here, because in this article I'll mainly focus on the differences that you need to add to the official example on GitHub that works with JW Player.

Now the trick is how to format our URL so that it Video.js will be able to properly pass the token to Wrench. Below is a set of examples for RTMP and HTTP streaming:
<video class="video-js vjs-default-skin" controls="" data-setup="{'techOrder': ['flash']}" height="264" id="example_video_1" preload="auto" width="640">
  <!-- source src="http://localhost:1935/vod/mp4:streetview.mp4/playlist.m3u8?t=5612e22aa1f54" type='video/mp4' /-->
  <!-- source src="rtmp://localhost:1935/vod/?t=5612e22aa1f54&mp4:streetview.mp4" type='rtmp/mp4' /-->
  <source src="http://localhost:1935/vod/mp4:sample.mp4/playlist.m3u8?t=5612e22aa1f54" type="video/mp4"></source>
</video></code>

The HTTP based streamer is quite straightforward with appending the token as normally to the end of the URL. The tricky part is the RTMP. As mentioned in this old GitHub issue there is something in the video.js code that prevents it from normally passing the query parameter to Wowza. However we can work this around and construct this ugly URL that perfectly works:

rtmp://localhost:1935/vod/?t=ce43d56daa13d&mp4:streetview.mp4
The trick is based on the way Video.js parses the src attribute into a "connection" and a "stream" part in flash-rtmp.js.

Here is the logs on the Wrench / Wowza side when we hit play:
INFO server - Client connecting with id 1394368604 and query string t=5612e22aa1f54 [caller: onHTTPSessionCreate]
INFO server - Attempting to resolve hashed token 8a4bbef80da3af21ddd99272d1cee34f
INFO server - Executing SQL select username from wtb_tokens where token=:hashedtoken with params: {hashedtoken=8a4bbef80da3af21ddd99272d1cee34f}
INFO server - Resolved hashed token 8a4bbef80da3af21ddd99272d1cee34f to User [username=john, hashedToken=8a4bbef80da3af21ddd99272d1cee34f]
INFO server - User john is connecting, performing checks.
INFO server - Accepting connection from user john, all checks passed

As you can see Wrench properly detected the token from the query string and was able to resolve it to a valid user.

2015. október 4., vasárnap

How to install Wowza Streaming Engine on CentOS

This is a short step-by-step tutorial on how to install Wowza Streaming Engine 4.2 on a CentOS server for live or video-on-demand (VOD) streaming.

Check Java installation

Wowza runs on Wowza and actually ships with a JRE, but I strongly suggest installing a JRE separately on OS level.
First let's check if Java is installed or not:
root@main [~]# java -version
-bash: java: command not found
root@main [~]#
As you can see it's not, so let's search for the yum package.
root@main [~]# yum search java
And then install the latest available OpenJDK
root@main [~]# yum install java-1.8.0-openjdk.x86_64
Installed:
  java-1.8.0-openjdk.x86_64 1:1.8.0.60-2.b27.el7_1

Dependency Installed:
  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.60-2.b27.el7_1  javapackages-tools.noarch 0:3.4.1-6.el7_0  python-javapackages.noarch 0:3.4.1-6.el7_0
  python-lxml.x86_64 0:3.2.1-4.el7                           ttmkfdir.x86_64 0:3.0.9-41.el7             tzdata-java.noarch 0:2015f-1.el7
  xorg-x11-fonts-Type1.noarch 0:7.5-9.el7

Complete!
root@main [~]#
Let's double check our new Java installation:
root@main [~]# java -version
openjdk version "1.8.0_60"
OpenJDK Runtime Environment (build 1.8.0_60-b27)
OpenJDK 64-Bit Server VM (build 25.60-b23, mixed mode)

Install Wowza Streaming Engine

Download the Wowza installer from their website. You can look up the download link by inspecting where the download button refers to.
root@main [~/wowza-4.2-installer]# wget http://www.wowza.com/downloads/WowzaStreamingEngine-4-2-0/WowzaStreamingEngine-4.2.0-linux-x64-installer.run
--2015-10-02 05:22:22--  http://www.wowza.com/downloads/WowzaStreamingEngine-4-2-0/WowzaStreamingEngine-4.2.0-linux-x64-installer.run
Resolving www.wowza.com (www.wowza.com)... 54.86.180.31, 107.23.121.144
Connecting to www.wowza.com (www.wowza.com)|54.86.180.31|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 206904581 (197M) [text/plain]
Saving to: ‘WowzaStreamingEngine-4.2.0-linux-x64-installer.run’

100%[==========================================================================================================>] 206,904,581 39.3MB/s   in 6.9s

2015-10-02 05:22:30 (28.8 MB/s) - ‘WowzaStreamingEngine-4.2.0-linux-x64-installer.run’ saved [206904581/206904581]

root@main [~/wowza-4.2-installer]#
Make the downloaded file executable
root@main [~/wowza-4.2-installer]# chmod +x WowzaStreamingEngine-4.2.0-linux-x64-installer.run
Start the installer
root@main [~/wowza-4.2-installer]# ./WowzaStreamingEngine-4.2.0-linux-x64-installer.run

----------------------------------------------------------------------------
Welcome to the Wowza Streaming Engine Setup Wizard.
----------------------------------------------------------------------------

Please read the following License Agreement. You must accept the terms of this
agreement before continuing with the installation.

Press [Enter] to continue:
Enter your license key when prompted:

Enter License Key

Please enter your Wowza Streaming Engine License Key.

License Key: []: E****-****-****-****-****-****-***********3

Create Administrator Account

Enter a user name and password that will be used to manage Wowza Streaming Engine.

User Name: []: admin

Password: : 5KC8Dc9Q

Start Wowza Streaming Engine automatically [Y/n]: Y

Setup is now ready to begin installing Wowza Streaming Engine on your computer.

Do you want to continue? [Y/n]: Y

----------------------------------------------------------------------------

Please wait while Setup installs Wowza Streaming Engine on your computer.

 Installing
 0% ______________ 50% ______________ 100%
 #########################################
----------------------------------------------------------------------------

Setup has finished installing Wowza Streaming Engine on your computer.

root@main [~/wowza-4.2-installer]#
Make Wowza Streaming Engine use your own Java installation, not the default one that comes bundled.
The benefit is that when you apply Java security updates regularly (of course you do, right?), you automatically keep your Wowza upgraded too.

rm -rf /usr/local/WowzaStreamingEngine/java
ln -sf /usr/lib/jvm/jre /usr/local/WowzaStreamingEngine/java
Open up the required ports on the firewall. We need 1935 for RTMP and 8088 for the engine manager.
firewall-cmd --zone=public --add-port=1935/tcp --permanent
firewall-cmd --zone=public --add-port=8088/tcp --permanent
firewall-cmd --reload

Verify Installation

Check that Wowza is up and running by opening the http://localhost:1935 URL. By default there is a HTTP listener configured to catch all requests here and respond with the server version. As we are in command line, let's just use wget and not a browser.
wget http://localhost:1935
That's it, we have successfully installed Wowza Streming Engine 4.2 on our server. To check the logs, we can use this command:
less /usr/local/WowzaStreamingEngine/logs/wowzastreamingengine_access.log