Tricks and Tips about Systems/Network

October 6, 2010

Some useful ffmpeg commands ( commandline video converting tool)

Filed under: admins,CentOS,PHP — Liju Mathew @ 10:50 pm

1. Converting MOV/MPEG/AVI/MP4 –> flv
#ffmpeg -i input file output.flv

2. Convert and adjust the video file resolution to output file
# ffmpeg -i input.avi -s 500×500 output.flv

3. Converting 3GP –> FLV
#ffmpeg -i input.3gp -sameq -an output.flv

4. Converting MPEG –>3GP
#ffmpeg -i input.mpeg -ab 8.85k -acodec libamr_wb -ac 1 -ar 16000 -vcodec h263 -s qcif output.3gp

5. Converting WMV –> to MP3
#ffmpeg -i input.wmv output.mp3

6. Converting AMR –> MP3
#ffmpeg -i input.amr -ar 22050 output.mp3

7. Converting FLV –> MP4
# ffmpeg -i input.flv -ar 22050 output.mp4

Advanced flash supported conversion.

#ffmpeg -i input.flv -s 480×360 -vcodec libx264 -b 1900kb -flags +loop -cmp +chroma -me_range 16 -me_method hex -subq 5 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 1 -flags2 +fastpskip -dts_delta_threshold 1 -acodec libfaac -ab 128000 output.mp4

This code will support to play in Iphone.
#ffmpeg -i 400b75e5081fca44d094.flv -s 320x240 -r 24 -b 200k -bt 240k -vcodec libx264 -vpre hq -coder 0 -bf 0 -flags2 -wpred-dct8x8 -level 13 -maxrate 768k -bufsize 3M -acodec libfaac -ac 2 -ar 48000 -ab 192k new_output_new1.mp4

8. Converting AAC –> Mp3
#ffmpeg -i input.aac -ar 22050 -ab 32 output.mp3

Use ffmpeg with it’s best performance

The following arguments helps you to optimize the ffmpeg conversion to get the best result of converting mp4. to flv

# ffmpeg -i input.mp4 -ar 22050 -ab 56 -acodec mp3 -r 25 -f flv -b 400 -s 320×240 output.flv

-i = specify input file
-ar = audio sample rate
-ab = audio bitrate
-acodec = audio codec
-r = framerate
-f = output format
-b = bitrate (of video!)
-s = resize to width x height

10, Convert Video –> JPG Sequence
#ffmpeg -i input.mpg -an -r 10 -y -s 320×240 video%d.jpg

11. Convert Every n seconds to JPEG
#ffmpeg -i input.mpg -r 0.2 -sameq -f image2 thumbs%02d.jpg where r is the time when jpg file created. r can be 0.2 indicate every 5 second, if you need a jpeg on every 45 seconds use 1/45.

11. Crop the video between the specified time
#ffmpeg -i input.mpg -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 320×240 video%d.jpg where
-ss : Record start time
-t : No. of second to end suppose you want to crop 2 minutes video which starts from the 10 minutes play
-ss 00:10:00 -t 00:02:00
%d : Naming with timestamp

12. Converting flv –> mp3
#ffmpeg -i input.flv -vn -acodec copy output.mp3

13. Converting WAV –> MP3
#ffmpeg -i Input.wav -ab 128 Output.mp3
#ffmpeg -i input.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 output.mp3

14 : Encode a video sequence for the iPpod/iPhone
ffmpeg -i input.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320×180 -title X output.mp4

15. Converting AVI –> GIF
ffmpeg -i input.avi gif_anime.gif
16. Compress .avi –> divx
#ffmpeg -i input.avi -s 320×240 -vcodec msmpeg4v2 output.avi
Source : input.avi
Audio codec : aac
Audio bitrate : 128kb/s
Video codec : mpeg4
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : output.mp4

17. Converting flv –> Mp4
#ffmpeg -i sample.flv -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -s 320×240 final_video.mp4

some useful resources,

http://www.itbroadcastanddigitalcinema.com/ffmpeg_howto.html

http://ffmpeg.org/faq.html

-njoy

September 18, 2010

Enabling IMAP extension in PHP

Filed under: admins,Apache,PHP — Liju Mathew @ 6:50 am

My server configuration is,

Centos 5.4 with PHP 5.2.12 (compiled manually)

The steps you need to do is go through the source tree which has compiled previously
#yum install libc-client-devel
#cd /home/installation/php-5.2.12/ext/imap
#phpize
# ./configure --with-imap --with-kerberos --with-imap-ssl

If you haven’t installed the libc-client library before, you will get a similar error as below,

checking for IMAP SSL support... yes
checking for utf8_mime2text signature... new
checking for U8T_CANONICAL... no
configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

Which can be solved by installling the following yompackage

  • #yum install libc-client-devel
  • You may also use this config parameter during the php compilation time.
    “–with-imap –with-kerberos –with-imap-ssl”

    Verifying by
    #php -m | grep “imap” will returns
    imap

    September 7, 2010

    How do I convert .htaccess file to web.config

    Filed under: admins,IIS,PHP,Windows 2008 — Liju Mathew @ 6:09 pm

    I have a requirement to re-define the apache re-write rule to IIS knowing language using web.xml on Windows 2008 server. There is one easy trick to achieve this.

    Basic operations are,

    1. Install Mod Rewrite component on II7
    2. Create a website on IIS and import the .httaccess file

    1. Installing Mod Rewrite Module

    Download and install Mod Rewrite module from the following url according to your OS architecture.
    http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/. Then Close the IIS MMC and reopen it. Now you see that module is present as shown below

    Then Click on ” import rules” label showing on the right side of the window tree. Find the .htaccess file and import and t hen click to apply. It will create/update the web.config file in the document root directory.

    Here is the sample code which I used for re-writing Codeigniter frame work

    It’s file name is “web.config

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <configuration>
    <system.webServer>
    <rewrite>
    <rules>
    <rule name=”Imported Rule 1″ stopProcessing=”true”>
    <match url=”^(.*)$” ignoreCase=”false” />
    <conditions logicalGrouping=”MatchAll”>
    <add input=”{REQUEST_FILENAME}” matchType=”IsFile” ignoreCase=”false” negate=”true” />
    <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” ignoreCase=”false” negate=”true” />
    </conditions>
    <action type=”Rewrite” url=”index.php/{R:1}” />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    </configuration>

    August 30, 2010

    codeigniter : .htaccess entry for godaddy shared hosting

    Filed under: admins,PHP — Liju Mathew @ 9:50 pm


    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]

    April 22, 2010

    Customizing php local variables on web

    Filed under: admins,Apache,PHP — Liju Mathew @ 6:11 pm

    I need to reset the php values of ‘upload_max_filesize” to 11MB but the default settings were set to 2MB. But I do not want to change this setting affected globally.

    Here are the tips.

    1. Create a empty ‘php.ini; file on the web where you want to use the upload size high.

    I want upload variable set to 12MB on this web folder (/home/wwwasd/public_html/uploadsfiles) only.
    Eg. http://asd.com/uploadfiles
    I created a php.ini under ‘/home/wwwasd/public_html/uploadsfiles’ and add the values “upload_max_filesize = 20M”

    #vi /home/wwwasd/public_html/uploadsfiles/php.ini
    add the following lines and save the file.
    upload_max_filesize = 20M

    If it is not work in some servers, then you may use the .htaccess files to do that.
    Add the value in .htaccess file
    php_value variable value
    php_value upload_max_filesize 100M

    March 30, 2010

    How do I enable openssl extension on PHP

    Filed under: admins,PHP,Webserver — Liju Mathew @ 11:47 am

    I used a custom php build on My Centos server. Now I want to enable openssl extension in order to communicate with SSL.

    Solution.

    Download and install openssl
    1. #wget http://www.openssl.org/source/openssl-1.0.0.tar.gz
    #./config && make && make install you may use yum method to install it ( yom install openssl*)
    2. Next step is to start the phpp re-compilation. For this, have modified my config parameter in order to work with ‘openssl’

    ./configure –prefix=/usr/local/php –with-apxs2=/usr/sbin/apxs –with-xsl –with-mysql –with-config-file-scan-dir=/etc/php.d –prefix=/usr –exec-prefix=/usr –bindir=/usr/bin –sbindir=/usr/sbin –sysconfdir=/etc –datadir=/usr/share –includedir=/usr/include –libdir=/usr/lib –libexecdir=/usr/libexec –with-config-file-path=/etc –with-bz2 –with-curl –with-exec-dir=/usr/bin –with-png –with-zlib –with-pear=/usr/share/pear –with-zml –with-gd –with-libxml=/usr/lib –enable-calendar –with-openssl=shared –with-png –with-bcmath –with-mysqli –enable-soap -with-jpeg –enable-sockets –enable-mbstring –enable-shared –with-jpeg-dir=/usr/local –with-freetype-dir=/usr/local/lib –with-pdo-mysql=shared –with-gettext

    [root@rc-040 php-5.2.9]# mv /usr/lib/httpd/modules/libphp5.so /tmp/

    # cd php-5.2.9
    #make && make install

    I have modify the ext_dir (extension_dir = “/usr/lib/extensions/no-debug-non-zts-20060613″)  location on php.ini and add a new line “extension=openssl.so” at the end of  /etc/php/ini “file

    #service httpd restart
    [root@rc-040 php-5.2.9]# php -r 'phpinfo();' | grep openssl
    openss
    l

    Open the browser and verify “openssl “ is showing on phpinfo() function.

    February 25, 2010

    Enabling Zend optimizer on php

    Filed under: admins,PHP — Liju Mathew @ 7:25 pm
    Tags:

    How do I install zend optimiser enabled on php ?

    Download Zend optimizer from Zend website

    #tar -zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
    # cd ZendOptimizer-3.3.9-linux-glibc23-i386
    # cd data/5_2_x_comp/
    # cp ZendOptimizer.so /usr/lib/extensions/no-debug-non-zts-20060613/
    Where I set extension_dir varible set to “/usr/lib/extensions/no-debug-non-zts-20060613/” on php.ini

    Adding entry on php.ini
    #cat "zend_extension=/usr/lib/extensions/no-debug-non-zts-20060613/ZendOptimizer.so" >> /etc/php.ini

    Restart Apache and verify the installation

    [root@rc-033 5_2_x_comp]# service httpd restart
    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]
    [root@rc-033 5_2_x_comp]# php -r ‘phpinfo();’| grep “zend”
    report_zend_debug => Off => Off
    zend.ze1_compatibility_mode => Off => Off
    PWD => /home/installation/zendoptimiser/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp
    OLDPWD => /home/installation/zendoptimiser/ZendOptimizer-3.3.9-linux-glibc23-i386
    _SERVER["PWD"] => /home/installation/zendoptimiser/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp
    _SERVER["OLDPWD"] => /home/installation/zendoptimiser/ZendOptimizer-3.3.9-linux-glibc23-i386
    _ENV["PWD"] => /home/installation/zendoptimiser/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp
    _ENV["OLDPWD"] => /home/installation/zendoptimiser/ZendOptimizer-3.3.9-linux-glibc23-i386
    [root@rc-033 5_2_x_comp]#

    Fatal error: Allowed memory size of 134217728 bytes exhausted

    Filed under: admins,PHP — Liju Mathew @ 3:02 pm

    I got this error when I try to exeucute a scheduled job.

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16 bytes) in /home/login/www/libraries/joomla/database/database/mysql.php on line 462

    The solution is,

    Increase the memory_limit on php.ini. Since I am using a shared hosting I can’t change the settings globally. So I switched to the webroot and create .htaccess file then add the line


    -bash-3.2# vi .htaccess
    php_value memory_limit 400M
    php_value max_execution_time 18000

    Problem Solved !!

    February 16, 2010

    How Do I enable ffmpeg extension, flvtool2 and Mplayer + Mencoder

    Filed under: admins,PHP — Liju Mathew @ 6:18 am

    I’m using PHP 5.2.9 on Centos5.3 server where php is installed from the source compilation.

    First I added the diag repository on my yum path,


    #rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
    #yum clean all
    #yum update
    #yum install ffmpeg ffmpeg-devel
    #yum install mplayer mencoder

    How to test ffmpeg is installed

    [root@rc-149 ffmpeg-php-0.6.0]# ffmpeg
    FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration: –prefix=/usr –libdir=/usr/lib –shlibdir=/usr/lib –mandir=/usr/share/man –incdir=/usr/include –enable-libamr-nb –enable-libamr-wb –enable-libdirac –enable-libfaac –enable-libfaad –enable-libmp3lame –enable-libtheora –enable-libx264 –enable-gpl –enable-nonfree –enable-postproc –enable-pthreads –enable-shared –enable-swscale –enable-x11grab
    libavutil 49.15. 0 / 49.15. 0
    libavcodec 52.20. 0 / 52.20. 0
    libavformat 52.31. 0 / 52.31. 0
    libavdevice 52. 1. 0 / 52. 1. 0
    libswscale 0. 7. 1 / 0. 7. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    built on Nov 6 2009 19:05:03, gcc: 4.1.2 20080704 (Red Hat 4.1.2-46)
    At least one output file must be specified
    [root@rc-149 ffmpeg-php-0.6.0]#

    Then install flvtool2

    #yum install flvtool2*

    Then I download the latest from php-ffmpeg package from sourceforge.

    #wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2?use_mirror=nchc
    tar -xjf ffmpeg-0.5.2.1.tbz2
    #phpize
    #./configure
    #make
    #make install

    If you are hit back on this error during the php-ffmpeg compilation time  “php ffmpeg error In function ‘_php_convert_frame’”Try to download the latest php-ffmpeg

    [root@rc-111 ffmpeg-php-0.6.0]# wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2/download

    Then that error will disappear.

    Now I’m going to edit the php.ini (/etc/php.ini) and add/modify the following lines on it,
    extension_dir = “/usr/lib/extensions/no-debug-non-zts-20060613/”
    extension=ffmpeg.so

    [root@rc-149 ~]# php -r ‘phpinfo();’| grep “ffmpeg”
    ffmpeg
    ffmpeg-php version => 0.6.0-svn
    ffmpeg-php built on => Feb 15 2010 19:11:38
    ffmpeg-php gd support => enabled
    ffmpeg libavcodec version => Lavc52.20.0
    ffmpeg libavformat version => Lavf52.31.0
    ffmpeg swscaler version => SwS0.7.1
    ffmpeg.allow_persistent => 0 => 0
    ffmpeg.show_warnings => 0 => 0

    February 10, 2010

    How to convert word document/powerpoint file to pdf or jpg on LINUXhttp://www.serveridol.com/2010/02/10/how-to-convert-word-documentpowerpoint-file-to-pdf-or-jpg-on-linux/

    Filed under: admins,PHP — Liju Mathew @ 7:20 am

    Here are the quick work around to convert.odc/.ppt to image or pdf file.

    We need the following packages installed on the server,
    a. openoffice
    b. imagemagick
    c. Java

    Installing openoffice

    #yum install openoffice.org*
    #yum install ImageMagick*

    How to verify imagemagick is installed and working

    [root@rc-170 ~]# convert logo: logo.gif
    [root@rc-170 ~]# convert –version
    Version: ImageMagick 6.2.8 04/17/08 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
    Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC

    Downloading jodconverter from sourceforge

    #wget http://downloads.sourceforge.net/project/jodconverter/JODConverter/2.2.2/jodconverter-2.2.2.zip?use_mirror=nchc
    #unzip jodconverter-2.2.2.zip
    #mv jodconverter-2.2.2 /usr/local/jodconverter/ ( optional)

    Verify the java installed
    [root@rc-170 ~]# java -version
    java version "1.6.0_14"
    Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
    Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode)

    Now we need to run openoffice as a service. So we can create a init script for this. A sample scripts can be download from here
    #vi /etc/init.d/openofficed

    #!/bin/bash
    OOo_HOME=/usr/lib64/openoffice.org
    SOFFICE_PATH=$OOo_HOME/program/soffice
    PIDFILE=$OOo_HOME/openoffice-server.pid

    case “$1″ in
    start)
    if [ -f $PIDFILE ]; then
    echo “OpenOffice headless server has already started.”
    exit
    fi
    echo “Starting OpenOffice headless server”
    $SOFFICE_PATH -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard & > /dev/null 2>&1
    touch $PIDFILE
    ;;
    stop)
    if [ -f $PIDFILE ]; then
    echo “Stopping OpenOffice headless server.”
    killall -9 soffice && killall -9 soffice.bin
    rm -f $PIDFILE
    exit
    fi
    echo “Openoffice headless server is not running, foo.”
    exit
    ;;
    *)
    echo “Usage: $0 {start|stop}”
    exit 1
    esac
    exit 0

    In this script I found the open office installation for was different according to the OS architecture. Since my OS is 64 bit it will be “/usr/lib64/openoffice.org” else it is “/usr/lib/openoffice.org” on Linux box.

    [root@s15351481 ~]# vi /etc/rc.local then add the line “/etc/init.d/opeofficd start”

    # java -jar /usr/local/jodconverter/lib/jodconverter-cli-2.2.2.jar document.ppt mam.pdf
    You may use to call it from php using the “exec” funcation.
    exec(‘java -jar /usr/local/jodconverter/lib/jodconverter-cli-2.2.2.jar/lib/jodconverter-cli-2.2.2.jar document.doc mam.pdf’);

    This program will support for the following conversions,
    1. DOC —> PDF
    2. DOC —> ODT
    3. DOC —> RTF
    4. XLS —> PDF
    5. XLS –> ODS
    6. XLS –> CSV
    7. PPT –> PDF
    8. PPT —> ODP
    9. PPT —> SWF
    10. ODT –> PDF
    11. ODT —> DOC
    12. ODT —> RTF
    13. ODS —> PDF
    14. ODS —> XLS
    15. ODS —> CSV
    16.ODP —> PDF
    17. ODP —> PPT
    18. ODP —> SWF

    How do I solve this error ?

    [root@rc-040 installation]# /usr/lib/openoffice.org/program/soffice “-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager” -nologo -headless -nofirststartwizard
    /usr/lib/openoffice.org/program/soffice.bin X11 error: Can’t open display:
    Set DISPLAY environment variable, use -display option
    or check permissions of your X-Server
    (See “man X” resp. “man xhost” for details)
    [root@rc-040 installation]#

    Yoy may need Xserver started on the server. I started the vnc server and execute the service script. Only this method will work.
    /etc/init.d/openofficed start

    How to check openoffice service is running,

    We can test it either by telnet to the listening port or grep it from the process list.

    [root@rc-040 ~]# telnet localhost 8100
    Trying 127.0.0.1...
    Connected to localhost.localdomain (127.0.0.1).
    Escape character is '^]'.
    `\ufffd\ufffd'com.sun.star.bridge.XProtocolPropertiesUrpProtocolPropertiesO>?
    A\ufffdD+\ufffdX\ufffd\u0771\ufffdFq\ufffd\u055d
    ^]
    [root@rc-040 ~]# netstat -nlp| grep ":8100"
    tcp 0 0 127.0.0.1:8100 0.0.0.0:* LISTEN 21278/soffice.bin
    [root@rc-040 ~]#

    Next Page »

    Theme: Rubric. Blog at WordPress.com.

    Follow

    Get every new post delivered to your Inbox.