MistServer PHP API for Live Stream


Hits: 3828  

MistServer is a highly versatile, lightweight, customizable open-source multi-standard multimedia server. MistServer configuration is easy to use for full CDN solutions applications. Hope you already read our article to Install MistServer

Mistserver Manager Login

MistServer API provides a Server API and a Management API.

You can find MistServer PHP API Examples Here

Note: Make sure port 4242 used for MistServer is open on your web hosting firewall where you run MistServer PHP API for Live Stream

MistServer PHP API for Live Stream will try to put/get data using PHP CURL in port 4242

$server = new Mistserver();
$server->login(‘http://server-ip:4242/api’, ‘username’, ‘password’);

// you can add a live stream:
$server->add_stream( STREAM_NAME, push://@SOURCE, BUFFER_TIME);

mistserver-api-form

Your channel has been successfully created. Use the details below to broadcast:
Download: Download Flash Media Live Encoder 3.2
FMS URL: rtmp://server-ip:1935/live
Stream Name: churchstream

mistserver-stream

As you get Live Media Stream details you can use our article to make your event live…
Live video stream event for online Temple or Church

API Call Reference: http://www.mistserver.org/doxygen/api.html

Install AWStats with GeoIP Plugin


Hits: 7036  

AWStats is a free analytic tool that generates web, streaming, ftp or mail server statistics, graphically. There are many log analyzer but AWStats is open source Web analytics reporting tool, It can analyze log files from Apache, WebStar, IIS.

Installing AWStats on ubuntu 12.04

# apt-get install awstats

Configuring for yourdomain.com replace yourdomain.com with your real domain

# cp /etc/awstats/awstats.conf /etc/awstats/awstats.yourdomain.com.conf
# vi /etc/awstats/awstats.yourdomain.com.conf

Check you have below settings in /etc/awstats/awstats.yourdomain.com.conf

LogFile=”/var/log/apache2/access.log”
SiteDomain=”yourdomain.com”
HostAliases=”localhost 127.0.0.1 yourdomain.com”
DNSLookup=1
LogFormat=1
AllowFullYearView=3

Generate stats for AWStats for /var/log/apache2/access.log file (Make sure you have fresh log file)

# /usr/lib/cgi-bin/awstats.pl -config=yourdomain.com -update

configuration Apache2 with password

# htpasswd -c /etc/awstats/awstats.pwd admin
# chmod 755 /etc/awstats/awstats.pwd

# vi /etc/apache2/sites-available/awstats

<VirtualHost *:80>
ServerName awstats.yourdomain.com
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error_awstats.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access_awstats.log combined
<Directory “/usr/lib/cgi-bin/”>
<Files “awstats.pl”>
Options +ExecCGI
</Files>
</Directory>
Alias /awstats-icon/ “/usr/share/awstats/icon/”
<Directory /usr/share/awstats/icon>
Options None
AllowOverride All
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
RewriteRule /awstats-icon – [L]
RewriteCond %{QUERY_STRING} !^(.*&)?framename=index(&.*)?$
RewriteCond %{QUERY_STRING} ^(.*&)?framename=.*(&.*)?$
RewriteRule /(.*) /usr/lib/cgi-bin/awstats.pl [L]
RewriteCond %{QUERY_STRING} ^(.*&)?config=([^&]*)(&(.*))?$
RewriteRule /.* /%2?%1%4 [R,L]
RewriteRule /awstats.pl$ / [R,L]
RewriteRule /([^/]*)(/.*)? /usr/lib/cgi-bin/awstats.pl?config=$1 [QSA,L]
<Location />
SetHandler cgi-script
Satisfy any
Order deny,allow
Deny from all
AuthType Basic
AuthName “AWStats Access”
AuthUserFile /etc/awstats/awstats.pwd
require valid-user
</Location>
<LocationMatch /(?!awstats.pl|robots.txt)$>
Require user admin
</LocationMatch>
<Location /awstats-icon>
SetHandler None
Allow from all
</Location>
</VirtualHost>

Enable Virtual Host

# a2ensite awstats
# apache2ctl configtest
# /etc/init.d/apache2 reload

Auto update stats

# crontab -e

*/10 * * * * /usr/share/awstats/tools/update.sh
10 03 * * * /usr/share/awstats/tools/buildstatic.sh
*/10 * * * * /usr/lib/cgi-bin/awstats.pl -config=yourdomain.com -update > /dev/null

Set proper permission on logs

# sudo chmod 644 -R /var/log/apache2/*
# chmod 644 /var/log/apache2

# vi /etc/logrotate.d/apache2   (Replace create 640 root adm with create 644 root adm)

Install GeoIP for AWStats

# apt-get install build-essential zlib1g-dev apg libgeo-ipfree-perl libnet-ip-perl libnet-dns-perl liburi-perl apache2-utils

# cd /usr/src/
# wget http://zlib.net/zlib-1.2.8.tar.gz
# tar xvzf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure –prefix=/usr/local/zlib && make && make install

# wget http://www.maxmind.com/download/geoip/api/c/GeoIP-latest.tar.gz
# tar xzvf GeoIP-latest.tar.gz
# cd GeoIP-1.6.0
# ./configure && make && make install

# cpan
> install YAML
> install Geo::IP Geo::IPfree Geo::IP::PurePerl URI::Escape Net::IP Net::DNS Net::XWhois Time::HiRes Time::Local
> quit

# cd /usr/src/
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# gzip -d GeoLiteCity.dat.gz
# cp GeoLiteCity.dat /usr/share/GeoIP/GeoLiteCity.dat

Enable AWSTAT configuation for LoadPlugin

# vi /etc/awstats/awstats.yourdomain.com.conf

Remove comment from /etc/awstats/awstats.yourdomain.com.conf

LoadPlugin=”geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /usr/share/GeoIP/GeoLiteCity.dat”

# /etc/init.d/apache2 reload

AWStats will run here

http://awstats.yourdomain.com/yourdomain.com

AWStats-Stats

AWStats-country

AWStats-hours

Error opening /usr/share/GeoIP/GeoIPCity.dat at /usr/local/share/perl/5.14.2/Geo/IP/PurePerl.pm line [file name in /usr/share/GeoIP]

Make sure you have all files in folder /usr/share/GeoIP/GeoLiteCity.dat else copy

# cp /usr/share/GeoIP/GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

AWStats-UA

Other log file analysis and reporting tools

http://sawmill.net/
http://goaccess.io/
http://www.apacheviewer.com/
http://www.loganalyzer.net/
http://www.webalizer.org/
http://piwik.org/log-analytics/
http://www.w3perl.com/
http://http-analyze.org/index.php

Install Red5 1.0.1 on CentOS release 6.5 (Final) 64-Bit


Hits: 9168  

Contact us for Red5 HLS Plugin

Red5 MySQL Authentication Plugin

Wowza MySQL Authentication Plugin

1. Install Java

# yum -y install java-1.6.0-openjdk java-1.6.0-openjdk-devel

2. Install Ant

# cd /usr/local/src
# wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.8.2-bin.tar.gz
# tar zxvf apache-ant-1.8.2-bin.tar.gz
# mv apache-ant-1.8.2 /usr/local/ant

3. Export path for Ant and Java

# export ANT_HOME=/usr/local/ant
# export JAVA_HOME=/usr/lib/jvm/java
# export PATH=$PATH:/usr/local/ant/bin
# export CLASSPATH=.:$JAVA_HOME/lib/classes.zip

Also add these lines in /etc/bashrc at last to available every-time logged in to SSH

# echo ‘export ANT_HOME=/usr/local/ant’ >> /etc/bashrc
# echo ‘export JAVA_HOME=/usr/lib/jvm/java’ >> /etc/bashrc
# echo ‘export PATH=$PATH:/usr/local/ant/bin’ >> /etc/bashrc
# echo ‘export CLASSPATH=.:$JAVA_HOME/lib/classes.zip’ >> /etc/bashrc

4. Install RED5 Server

# cd /usr/local/src
# wget http://fossies.org/linux/privat/red5-1.0.1.tar.gz
# tar zxvf red5-1.0.1.tar.gz
# mv /usr/local/src/red5-server-1.0 /usr/local/red5

5. Create a service for Red5 to start and stop

# wget -O /etc/init.d/red5 http://www.sohailriaz.com/downloads/red5.txt
# chmod +x /etc/init.d/red5

6. Allow port 5080 and 1935 to your server firewall

# iptables -A INPUT -p tcp -m tcp –dport 5080 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp –dport 1935 -j ACCEPT

make sure you have double hyphen no space (- -) in dport option

OR allow from WHM

port-firewall-whm

7. Red5 Server Command

# /etc/init.d/red5 start
# /etc/init.d/red5 stop
# /etc/init.d/red5 status

# netstat -anp | grep 5080
# ps aux | grep red5

http://yourserver.com:5080/

Go to http://yourserver.com:5080/demos/ofla_demo.html to test Red5 Server Videos over RTMP

Red5-oflaDemo-VOD

Re Stream Radio Shoutcast / Icecast using Node JS


Hits: 5475  

Re-stream Radio (Shoutcast/Icecast) Stream using Node.JS and get Metadata current playing song title… Use port forwarding to hide real shoutcast IP …. Avoid PHP script to damage Server with too many calls on radio server

Start Restream

> node radio.js

node.js>node radio.js
Server running at http://192.168.1.4:8007

Radio Stream connected!
{ ‘icy-notice1’: ‘<BR>This stream requires <a href=”http’,
‘icy-notice2’: ‘SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR>’,
‘icy-name’: ‘Radio HSL – Hit Hai Toh Bajega!’,
‘icy-genre’: ‘Indian Hindi Top40’,
‘icy-url’: ‘http’,
‘content-type’: ‘audio/mpeg’,
‘icy-pub’: ‘1’,
‘icy-metaint’: ‘32768’,
‘icy-br’: ’64’ }
StreamTitle=’Bullett Raja – Tamanche Pe Disco [1e92]’;StreamUrl=”;

Get MetaData

> node radio-metadata.js

node.js>node radio-metadata.js
Server listening on port 8079
Radio Stream connected!
StreamTitle=’Bullett Raja – Tamanche Pe Disco [1e92]’;StreamUrl=”;

Output in browser:
“StreamTitle=’Bullett Raja – Tamanche Pe Disco [1e92]’;StreamUrl=”;\u0000\u0000\u0000\u0000\u0000″

Install MistServer


Hits: 10679  

MistServer is a highly versatile, lightweight, customizable open-source multi-standard multimedia server. MistServer configuration is easy to use for full CDN solutions applications.

Mistserver_pos

MistServer is Free, open and well-supported, Truly plug and play, Affordable, seamless and highly scalable control over your media servers. MistServer can be installed on any server to make multimedia server.

Download MistServer Binary here http://www.mistserver.org/index.php?title=Downloads

You can clone source from https://github.com/DDVTECH/

Check your server architecture Generic Linux 64-bit or Generic Linux 32-bit then download

# wget http://releases.ddvtech.com/download.php?pack=mistserver_64&ver=1.2.1

Now extract / copy files to /usr/local/bin/

Check quick start here http://www.mistserver.org/index.php?title=Quick_Start

# chmod a+x MistController
# MistController -a username:password -n

You need to point your browser to connect Mist Server Manager

http://server-ip:4242/#root@http://server-ip:4242/api

Mistserver Manager Login

Kill MistServer

# lsof -i:4242 (Find PID for MistServer)
# kill -9 PID

Find more info about MistServer from http://wiki.mistserver.org/

Compare MistServer with other Media Streaming Servers like Wowza or Red5 here http://www.mistserver.org/index.php?title=Compare

You can find Linux User Guide for MistServer from http://mistserver.org/index.php?title=User_Guide_(Linux)

Stay connected for more MistServer Configurations and Addons 😉

MP3 waveforms with PHP


Hits: 6487  

If you are thinking how soundcloud.com generates the waveform for sound MP3 player?

soundcloud-waveform

There are some audio processing libraries used to process MP3 files to WAV and then PNG / SVG images..

MP3 to WAV to PNG

1. LAME MP3 encoder/decoder

$ lame input.mp3 -f -m m -b 16 –resample 8 resampled.mp3 && lame –decode resampled.mp3 output.wav

2. SOX – Sound eXchange

$ sox output.wav −n spectrogram
$ sox output.wav -n spectrogram -Y 140 -l -r -o output.png

3. wav2png – Creates waveform pngs out of audio files

$ sox mp3-song.mp3 -c 1 -t wav – | wav2png -o mp3-song.png /dev/stdin
$ wav2png –foreground-color=2e4562ff –background-color=00000000 -o  output.png   input.wav

WaveForm generated using SOX

WaveForm Generator using SOX

Links:

https://github.com/afreiday/php-waveform-png
https://github.com/afreiday/php-waveform-svg
https://github.com/beschulz/wav2png
https://github.com/beschulz/wav2json
http://www.rarewares.org/mp3-lame-bundle.php

Media Streaming CMS


Hits: 11669  

WMSPanel is reporting and control cloud panel for Nimble Streamer and Wowza Streaming Engine. It’s also used as a control UI for Live Transcoder for Nimble Streamer

wmspanel

Kaltura, the Open Source Community provides tools such as: online video player, open source editor and open source video for websites.

Kaltura CMS
Kaltura CMS

EZserver is an Easy-to-Use Video Server to let you easily install, manage and provide video service. And, it is also integrated with IP Blocker, Player Filter, Time Shift, DVR, Subscriber Management and Middleware for IPTV / OTT and VOD service.

Ezhometech IPTV server, Video Server, IPTV player, IPTV Middleware

MEDIA CONTROL PANEL – supports all media server types including shoutcast, icecast, wowza media and windows media services.

cast control

Streamio – Online Video CMS – Managing HD video content on websites, intranets and social media networks.

streamio

ViMP is the professional Video CMS for WebTV, Social Media portals and Video Communities with mobile and HTML5 support. We also offer associated transcoding, hosting und dedicated servers.

vimp media product

Manage online videos with Brightcove’s video Content Management System (CMS). Learn how to sort, manage and organize your entire video library with ease.

brightcove

Build a centralized, searchable video library with Panopto Unison. Import, edit, and manage video of any format in Panopto’s powerful video CMS.

Online Video Platform - Panopto

Installing Apache, MySQL, PHP in Gentoo Server


Hits: 9049  

All commands are performed as root to install Apache, MySQL, PHP and phpMyAdmin in Gentoo Linux Server.

1. Update your System

# emerge –sync

2. Install Apache Webserver

# emerge apache

The web server ROOT is in /var/www/localhost/htdocs/

# /etc/init.d/apache2 start

Then go to http://server-ip/
it works on gentoo

Add apache2 to the startup script
# rc-update -v add apache2 default

3. Install MySQL Database

# emerge mysql

Install MySQL database
# /usr/bin/mysql_install_db

Start MySQL Server
# /etc/init.d/mysql start

Change MySQL User Password
# /usr/bin/mysqladmin -u root -h localhost password ‘new-password’

Test MySQL Server
# /etc/init.d/mysql restart

Add MySQL to the startup script
# rc-update -v add mysql default

4. Install the PHP with modules

# USE=”cli cgi apache2 xml mysql mysqli” emerge ‘dev-lang/php’

Before you can use PHP with Apache… Edit /etc/conf.d/apache2 and add “-D PHP5″ to APACHE2_OPTS

It looks like
APACHE2_OPTS=”-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D PHP5″

You can find php.ini in /etc/php/apache2-php5.4

then restart apache server
# /etc/init.d/apache2 restart

Then go to http://server-ip/info.php (Create phpinfo() file)

phpinfo on gentoo
phpinfo on Gentoo

phpinfo php

phpinfo mysql

5. Install phpMyAdmin

# emerge -av phpmyadmin

Then go to http://server-ip/phpmyadmin/

phpMyAdmin on gentoo
phpMyAdmin on Gentoo

Creating Zip Without Recording ROOT Paths


Hits: 3916  

Simply use chdir() to change the working directory before you exec()

Or you can use ….

exec(“cd /var/www/html/media; zip -r -9 Media.zip . 2>&1”, $log);

exec(“mv /var/www/html/media/Media.zip /var/www/html/Media.zip”);

Get zip file size

exec(“ls -ls /var/www/html/Media.zip | awk ‘{print $6}’ 2>&1”, $size);

$zipsize = implode(” “, $size);

Without this solution

Length Date Time Name
——– —- —- —-
0 03-08-13 15:10 /var/www/html/media/dialogs/
125305 08-07-12 16:31 /var/www/html/media/dialogs/1.3.mp3
125305 08-07-12 16:33 /var/www/html/media/dialogs/1.5.mp3
184864 08-07-12 16:32 /var/www/html/media/dialogs/1.4.mp3
125305 08-07-12 16:30 /var/www/html/media/dialogs/1.1.mp3
125305 02-24-13 16:48 /var/www/html/media/dialogs/1.2.mp3
125305 08-07-12 16:34 /var/www/html/media/dialogs/1.6.mp3

With this solution

Length Date Time Name
——– —- —- —-
0 03-08-13 16:40 dialogs/
125305 08-07-12 16:51 dialogs/1.3.mp3
125305 08-07-12 16:53 dialogs/1.5.mp3
184864 08-07-12 16:52 dialogs/1.4.mp3
125305 08-07-12 16:50 dialogs/1.1.mp3
125305 02-24-13 16:58 dialogs/1.2.mp3
125305 08-07-12 17:04 dialogs/1.6.mp3

PHP Run Background Process using Exec


Hits: 8678  

If you need to start process in background and get its PID to manage it later using PHP.

<?php

function runInBackground($command,$log,$priority=0)
{
if($priority)
   $PID=shell_exec("nohup nice -n $priority $command > $log 2>&1 & echo $!");
else
   $PID=shell_exec("nohup $command > $log 2>&1 & echo $!");
return($PID);
}

?>
PHP Process
PHP Process

echo $! will return process ID
# Command & echo $!

 

Check if process is running

<?php

function isProcessRunning($PID)
{

if($PID==0)return false;
if($PID=="")return false;

exec("ps -p $PID 2>&1",$state);
return(count($state)>=2);

}

?>

 

Display Process Logs

<?php

function displayProcessLog($logfile)
{

exec('cat $logfile 2>&1',$log);
return implode("\r\n",$log);

}

?>

 

Kill Process

<?php

function killProcess($PID)
{
 exec('kill '.$PID.' 2>&1',$status);
 return implode("\r\n",$status);
}

?>

 

Save Process ID to file

#!/bin/bash
Command &
echo $! >/path/to/pid.file