Simple pay-per-minute solution for Wowza

Pay-per-minute is a typical use case that people want to implement on their sites that publish online streams. This tutorial shows you a simple way to achieve this on your site using Wrench.

Setting up Wrench

Please read the previous article about user authentication in Wowza Streaming Engine to understand how to set up Wrench in your website and in Wowza Streaming Engine. This is a prerequisite to pay-per-minute (ppm) and pay-per-view (ppv) as all this information needs to be associated to a particular user, so authentication is a necessary first step.

Configuring Wrench for pay-per-minute

First off, you need to create a table in your database to store the information collected by the module. The following is a simple table that would do for you:

CREATE TABLE wtb_minutes (
   `session` varchar(256),
   `user` varchar(64),
   `application` varchar(64),
   `total` int(11)

This table will be populated by Wrench using the query that you have to specify in the wrench.ppm.insert.sql application property. For this tutorial, open your Wowza application's Application.xml file and add the following properties in addition to any you have already set in the previous tutorial.

  <Value>update wtb_minutes set total=:elapsedtime where user=:username and application=:application and session=:session</Value>
  <Value>insert into wtb_minutes (user, application, total, session) values (:username, :application, 0,:session)</Value>

The property wrench.monitor.period sets the time interval for running the monitor job. As this job might possibly run as many queries as the number of your clients is, be careful not to set it too small. For pay-per-minute solutions, you typically want 30 or 60 second intervals.

When a user successfully passes user authentication and any optional authorization that you have set up, the first time Wrench monitor job runs, it will execute the wrench.ppm.update.sql query. If this was the very first time this user is processed in his session, the update has no effect and Wowza Wrench will issue the wrench.ppm.insert.sql which inserts the first entry for the user into the wtb_minutes table. Next time the job is executed, the update will be responsible for updating the elapsed time.

The session in this context identifies a user and the time he started watching the stream. It makes possible to collect consequtive logs in the same table and keeping each sessions's length recorded. If you want to summarize the total minutes that the user consumed your streams, you can run the following query:

select sum(total) from wtb_minutes where user = 'joe'

Setting up pay-per-view

A simple Wowza pay-per-view setup can be set up with Wrench by creating a table in your database that will store the statistics:

CREATE TABLE `wtb_views` (
  `user` varchar(64),
   `count` int(11)

Then set the following two properties in your Application.xml:

  <Value>update wtb_views set count = count + 1 where user=:username</Value>
  <Value>insert into wtb_views (user, count) values (:username, 1)</Value>

Whenever Wrench finds a new, yet unlogged client it executes the wrench.ppv.update.sql query. If the query did not update anything in the table, then most probably this client has never seen any streams, so it executes the wrench.ppv.insert.sql query. The optional wrench.ppv.grace.period parameter allows you to set a minimum time that is needed to pass before any client is counted.

Update: there is even more that you can do: the latest version supports dynamic balance checking of your clients.

Update: (starting with version 2015.03.22, you can use webservice based PPM)

Feel free to leave your feedback here about this tutorial.


Hi, I already got a listen of unique tokens provisioned in my sql database, what i would like to do is include a small textarea under my videoplayer where the user enters that token. The token will be then carries into wrench for checking in the sql db. The user does not need to be authenticated on the cms BUT the token can only be used once and cannot be shared. Do you think it would be possible to include a parameter in the sql db stating the status of the token? "Used,Not Used" and grant access accordingly? Appreciate if you can elaborate more on that workflow. Thanks

Hi ocx! As I understand, you need something like a preselled "coupon code" then. I think its possible to achieve with Wrench. If you had that textbox, the player could be generated dynamically with only few lines of JavaScript based on that "coupon code". I can help you setting up this, just contact me directly.

I am developing a commercial website which would be a service to a broadcasters in order to live stream their events with a pay per minute model. There can be multiple sessions created by multiple broadcasters to live stream their events using IP camera or a web camera. These event sessions need to be created dynamically as per the broadcaster event schedule from the website. And the live stream need to be recorded for future access. Is this something the proposed module can deliver when integrated with AWS? Thanks.

Yes, Wrench can be used for this. Also worth considering the HTTP POST based stream event publication feature for this. Let's go into the details by email.

Hello, I would like a pay per minute script on my clairvoyance website I'm in Paris. Script with the ability to work with other "pay per" system. Will it be possible to do this to me? Regards, Marie

Write new comment