Featured Posts

Converting HTML5 Video in Bulk Recently i've been working on a multimedia magazine project and i wanted to use HTML5 for playing video, i've decided to use VideoJs while there were also good tools like...

Readmore

Debian squeeze webserver setup This is a tutorial for fast setup of a webserver for a VPS or dedicated server with at least 256MB of RAM, in this tutorial I assume that you only have installed the base...

Readmore

Installing Trac and Git on Debian lenny I couldn't find a good article so I decided to write one, this is a very quick howto for installing Trac with Git on Debian Lenny for myself! First things first First...

Readmore

Arash Hemmat Rss

Converting HTML5 Video in Bulk

Posted on : 27-12-2011 | By : Arash Hemmat | In : Tutorials for myself

0

Recently i’ve been working on a multimedia magazine project and i wanted to use HTML5 for playing video, i’ve decided to use VideoJs while there were also good tools like MediaElementJs and SublimeVideo as you can see in below chart (borrowed from MediaElementJs website!) i needed to have both Webm and H.264 format in order to cover most of the browsers.

html5-video-support-chartThe first problem was the lack of good converters for Webm format, i could find few but most of them were lacking either advanced options or multiple file conversion, so i started using ffmpeg for Webm conversion and it was working pretty good until i realised that ffmpeg has dropped support for H.264 because of the some patent problems, i could build ffmpeg with H.264 support but Handbrake was out there with many more features and i decided to use ffmpeg for Webm conversion and Handbrake for H.264 conversion.

I needed to create both Linux and Windows converters for my own use and the other stuff who were using windows.

Windows Converter

First i downloaded the Windows builds of Handbrake and ffmpeg:

Handbrake: http://handbrake.fr/downloads.php

ffmpeg: http://ffmpeg.zeranoe.com/builds/

Then i created a batch file which was reading all files in “input” folder convert them and put in “ouput” folder, all the user needs to do is to put video files in “input” folder and click on “convert.bat” file. Here is the “convert.bat”:

@echo off
SET count=1
FOR /f “tokens=*” %%U IN (‘dir /b input’) DO (
echo %%~nU
ffmpeg.exe -i input\%%U -vcodec libvpx -s 640×360 -aspect 16:9 -b 256k -qmin 4 -qmax 63 -deinterlace -acodec libvorbis -ab 96k -aq 4 -ar 44100 -threads 8 output\%%~nU_normal.webm

ffmpeg -i input\%%U -vcodec libvpx -s 854×480 -aspect 16:9 -b 640k -qmin 4 -qmax 63 -deinterlace -acodec libvorbis -ab 128k -aq 4 -ar 44100 -threads 8 output\%%~nU_high.webm

handbrake -i input\%%U -t 1    -c 1 -o output\%%~nU_normal.mp4 -O -f mp4 -e x264 -w 640 -l 360 –custom-anamorphic -b 256 -a 1,1 -E faac,ac3 -6 stereo,auto -R 44.1,Auto -B 96,auto -D 0.0,0.0 -x cabac=0:ref=2:me=umh:bframes=0:8x8dct=0:trellis=0:subq=6:weightb=0 -v 1

handbrake.exe -i input\%%U -t 1    -c 1 -o output\%%~nU_high.mp4 -O -f mp4 -e x264 -w 854 -l 480 –custom-anamorphic -b 640 -a 1,1 -E faac,ac3 -6 stereo,auto -R 44.1,Auto -B 128,auto -D 0.0,0.0 -x cabac=0:ref=2:me=umh:bframes=0:8x8dct=0:trellis=0:subq=6:weightb=0 -v 1

set /a count+=1 )
pause

This bat file covnerts video files in “input” folder into two different quality and size which i needed for my project and you can customise them as you wish.

Linux Converter

The linux approach is almost the same but to make it work you need to install ffmpeg and Handbrake on your linux box first. Here is the convert.sh batch file:

for FILE in `ls input/`
do
NAME=${FILE%\.*}
ffmpeg -i input/$FILE -vcodec libvpx -s 640×360 -aspect 16:9 -b 256k -qmin 4 -qmax 63 -deinterlace -acodec libvorbis -ab 96k -aq 4 -ar 44100 -threads 8 output/”$NAME”_normal.webm
ffmpeg -i input/$FILE -vcodec libvpx -s 854×480 -aspect 16:9 -b 640k -qmin 4 -qmax 63 -deinterlace -acodec libvorbis -ab 128k -aq 4 -ar 44100 -threads 8 output/”$NAME”_high.webm
HandBrakeCLI -i input/$FILE -t 1    -c 1 -o output/”$NAME”_normal.mp4 -O -f mp4 -e x264 -w 640 -l 360 –custom-anamorphic -b 256 -a 1,1 -E faac,ac3 -6 stereo,auto -R 44.1,Auto -B 96,auto -D 0.0,0.0 -x cabac=0:ref=2:me=umh:bframes=0:8x8dct=0:trellis=0:subq=6:weightb=0 -v 1
HandBrakeCLI -i input/$FILE -t 1    -c 1 -o output/”$NAME”_high.mp4 -O -f mp4 -e x264 -w 854 -l 480 –custom-anamorphic -b 640 -a 1,1 -E faac,ac3 -6 stereo,auto -R 44.1,Auto -B 128,auto -D 0.0,0.0 -x cabac=0:ref=2:me=umh:bframes=0:8x8dct=0:trellis=0:subq=6:weightb=0 -v 1
done

 

Customising Video Quality and size

I needed two different quality and size for this project, the normal quality and the high quality and the options used in converter is based on these parameters:

Normal Quality

Video bitrate: 256k

Video Size: 640×360

Video Aspect: 16:9

Audio bitrate: 96k

 

High Quality

Video bitrate: 640k

Video Size: 854×480

Video Aspect: 16:9

Audio bitrate: 128k

The most important thing here is to make a video with a bitrate that suits your user’s bandwidth, the normal quality needs at least 352 kbps (256k video +96k audio) bandwidth for playing without buffering and the high quality needs at least 768kbps bandwidth for a smooth play, knowing these you should be able to customise the batch files based on your own needs.

Note 1: this approach won’t guarantee the bitrate and if you need a guaranteed bitrate you must use a two pass conversion method which is much more complicated.

Note 2: if you wonder what each of options i used here means you can take a look at ffmpeg and Handbrake cli guides:

Handbrake CLI Guide: https://trac.handbrake.fr/wiki/CLIGuide

ffmpeg documentation: http://ffmpeg.org/ffmpeg.html

Download the Converter Here

 

 

Debian squeeze webserver setup

Posted on : 14-07-2011 | By : Arash Hemmat | In : Tutorials for myself

0

This is a tutorial for fast setup of a webserver for a VPS or dedicated server with at least 256MB of RAM, in this tutorial I assume that you only have installed the base system and ssh server.

First step is to change the hostname

#hostname example.com

You should modify the resolv.conf file if your server is not able to resolve internet addresses

#nano /etc/resolv.conf

Modify the nameserver line to your network nameserver or to one of the primary name servers, i will use the sun and google nameservers here

nameserver 4.2.2.4
nameserver 8.8.8.8

Now you must edit the repositories click here for the list of official debian squeeze repositories.

# nano /etc/apt/sources.list

## Debian security updates:
deb http://security.debian.org/ squeeze/updates main contrib non-free
deb-src http://security.debian.org/ squeeze/updates main contrib non-free

## Debian.org:
deb http://ftp.debian.org/debian/ squeeze main contrib non-free
deb-src http://ftp.debian.org/debian/ squeeze main contrib non-free

Now let’s update the system

#apt-get update

#apt-get upgrade

Our server should sync the time with the outer world frequently so we need ntp

#apt-get install ntp ntpdate

Now we are going to install Apache2 and PHP5

#apt-get install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-mysql php5-cli apache2-suexec libapache2-mod-suphp

Then run the following command to enable the Apache modules

#a2enmod suexec rewrite ssl actions include

Restart Apache afterwards:

#service apache2 restart

We will need a virtual host here so let’s create it

#nano /etc/apache2/sites-available/example.com

Here is what you should use in this file

<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@example.com
ServerAlias www.example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
Order deny,allow
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

After you save the virtual host file you need to activate it

#a2ensite example.com

Now you need to restart the apache again

$service apache2 restart

Now let’s install Mysql

#apt-get install mysql-server mysql-client libmysqlclient15-dev

Bind DNS server can be installed as follows

#apt-get install bind9 dnsutils

Now we need to configure the bind for our fully qualified domain(s), first we need to add a zone to “/etc/bind/named.conf.local” file

#nano /etc/bind/named.conf.local

zone “example.com” {
type master;
file “/etc/bind/db.example.com”;
};

Now we must create the “/etc/bind/db.example.com” file

#nano /etc/bind/db.example.com

Now copy the below content below replaceing the “192.168.254.1″ with your server IP.

;
; BIND data file for example.com
;
$TTL    604800
@       IN      SOA     ns1.example.com. info.example.com. (
20100714         ; Serial based on date
7200         ; Refresh
120         ; Retry
2419200         ; Expire
604800)        ; Default TTL
;
@               IN      NS      ns1.example.com.
@               IN      NS      ns2.example.com.
example.com.        IN      MX      10      mail.example.com.
example.com.        IN      A       192.168.254.1
ns1                     IN      A       192.168.254.1
ns2                     IN      A       192.168.254.2
www                     IN      CNAME   example.com.
mail                    IN      A       192.168.254.1
ftp                     IN      CNAME   example.com.
example.com.            IN      TXT     “v=spf1 ip4:192.168.254.1 a mx ~all”
mail                    IN      TXT     “v=spf1 a -all”

Now we can restart bind

#service bind9 restart

Many applications need to send emails so we are going to install a send only mail server

#apt-get install exim4-daemon-light mailutils

Use the below command to start Exim configuration

#dpkg-reconfigure exim4-config

Choose “Internet Site” when asked about the mail configuration type.

Enter your system’s FQDN (fully qualified domain name) on the “mail name” configuration screen.

Enter “127.0.0.1″ when asked which IP address to listen on for SMTP connections.

Make sure you list your FQDN, hostname, and localhost entries when you’re asked which destinations mail should be accepted for.

Leave the relay domains and relay machines fields blank.

Select “No” when asked whether to keep DNS queries to a minimum.

You may select either “mbox” or “Maildir” when asked about the delivery method used for incoming mail. While many utilities use mbox format, Maildir format can make handling individual locally delivered mail messages easier, and is widely supporting by a range of applications.

Accept the default “non-split” option for your mail configuration file.

Issue the following command to send a test email, substituting an external email address for someone@somedomain.com.

echo "This is a test." | mail -s Testing someone@somedomain.com

 

Installing Trac and Git on Debian lenny

Posted on : 23-11-2009 | By : Arash Hemmat | In : Tutorials for myself

Tags: , , , , , , , , ,

11

I couldn’t find a good article so I decided to write one, this is a very quick howto for installing Trac with Git on Debian Lenny for myself!

First things first

First we should decide where to put our Trac files and Git repository, this is my fashion to put everything in /home directory so when i need a backup of my system all i have to do is to copy my /home directory.

Git repository files for the project test go here:

/home/repositories/test/

Trac files for project test go here:

/home/tracs/test

Installing Trac and Git

Thanks to apt magic installing Trac and Git is superb easy:

apt-get install trac-git

Initialize Git repository

We need  to initialize out  git repository first:

cd /home/repositories/test

git init

git commit

and it would be a good idea to add some files and folders before going to next step because trac-git plugin is not handling empty repositories very well.

Initializing Trac enviroment

trac-admin /home/tracs/test initenv

When asked for “Database connection string” just press Enter to use the default sqlite and when asked for “Repository type” type git and when asked for “Path to repository” enter the path like this “/home/repositories/test/.git” (Don’t forget to put the .git after the path)

Now we need to set the permissions:

find /home/tracs/test -type f -exec chmod 660 {} \;

find /home/tracs/test -type d -exec chmod 2770 {} \;

chown -R root.www-data /home/repositories

chown -R root.www-data /home/tracs

Adding Users to Trac

Let’s add an admin user to the Trac enviroment:

htpasswd -c /home/tracs/test/.htpasswd admin

You can add as many user as you want using this method.

Setting the Virtual Host

Now we will setup a virtual host like to be able to access trac from a sub domain like http://trac.example.com :

You’ll probably need to install and activate the apache python module if you don’t have it already:

apt-get install libapache2-mod-python

a2enmod python

Then we need to add the virtual host:

vim /etc/apache2/sites-available/trac.example.com

Now replace the example.com with your own domain name and paste the below lines into the newly created file:

<VirtualHost *:80>
ServerName  trac.example.com
ServerAdmin webmaster@example.com

# Note: This folder should exist, but will generally be empty
DocumentRoot /home/tracs/test/htdocs
<Directory /home/tracs/test/htdocs>
Order allow,deny
Allow from all
</Directory>

# Host the main Trac instance at /
<Location />
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonInterpreter main
PythonOption TracEnv /home/tracs/test
PythonOption TracUriRoot /
SetEnv PYTHON_EGG_CACHE /tmp
</Location>

# Host all others at /projects/$PROJECT
<Location /projects>
PythonOption TracEnv “”
PythonOption TracEnvParentDir /home/tracs/
</Location>

<Location /login>
AuthType Basic
AuthName “Test”
AuthUserFile /home/tracs/test/.htpasswd
Require valid-user
</Location>

</VirtualHost>

It is time to restart the apache:

/etc/init.d/apache2 restart

That’s it! Point your browser to http://trac.example.com and you’ll see Trac and Git running painless.

Troubleshooting

If you get an error message like below or something like that you will need to make some changes to the trac.ini file.

Warning: Can’t synchronize with the repository (GIT backend not available)

Let’s open trac.ini and take a look:

vim /home/tracs/example/conf/trac.ini

First find these lines:

[git]
cached_repository = false
git_bin = /usr/bin/git
persistent_cache = false
shortrev_len = 7

Now replace “git_bin = git” with “git_bin = /usr/bin/git”

This should solve the problem, if it is not then continue reading!

Ok, if you are still getting error about git these are the posibilities:

  • Make sure you did put the “/.git” after your repository path while initializing the trac enviroment, if not find “repository_dir” in trac.ini and fix it.
  • You may not set the permissions for your repository as described above, make sure www-data has permission to the repository
  • You may be working with an empty repository, if so add some files and commit.

UPDATE 10-02-2010: If you still have problems you may read the comments you may find the solution there!