Wednesday, January 16, 2013

Exiftool, quick and easy for RHEL/CentOS 5.x

Almost the latest version as of now, the one most 'production ready'.
Be root, cut and paste into your terminal and voila!

mkdir extra_packages
cd extra_packages/
wget http://owl.phy.queensu.ca/~phil/exiftool/Image-ExifTool-9.04.tar.gz
tar xvzf Image-ExifTool-9.04.tar.gz
cd Image-ExifTool-9.04
perl Makefile.PL
make
make test
make install

Tuesday, January 15, 2013

Wordpress & Varnish



Basic configuration, tiny bit of security and avoiding error 405 on post. This server runs other things as well, so configurations are not as aggressive as they might be in other places.

backend default {
.host = "127.0.0.1";
.port = "8080";
}

acl purge {
        "localhost";
}

sub vcl_recv {

    /* Before anything else we need to fix gzip compression */
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|mp4)$") {
            # No point in compressing these
            remove req.http.Accept-Encoding;
        } else if (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } else if (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unknown algorithm
            remove req.http.Accept-Encoding;
        }
    }
    # Login, administration and posting comments are to be completely and utterly left alone, no caching, no nothing.
    if (req.http.host == "my.blog.com") {
        if (req.url ~ "wp-(login|admin|comments-post)") {
                set req.backend = default;
            return(pipe);
        }
        # Drop any cookies sent to Wordpress.
    unset req.http.cookie;
        if (req.request == "PURGE") {
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
        }
        set req.backend = default;
        return (lookup);
    }
     if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|mp4)$") {
         unset req.http.cookie;
     set req.grace = 5m;
         return(lookup);
     }
     return(pass);
}

sub vcl_fetch {
    if (beresp.status == 302) {
        set beresp.http.X-Magic-Redirect = "1";
        return(deliver);
    }
    if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|mp4)$") {
        unset beresp.http.set-cookie;
    }
    set beresp.do_stream = true;
    if (req.http.Authorization) {
        return (hit_for_pass);
    }
}

sub vcl_hit {
    if (obj.http.X-Magic-Redirect == "1") {
        set req.url = obj.http.Location;
        return (restart);
    }

    if (req.request == "PURGE") {
        set obj.ttl = 0s;
        error 200 "Purged.";
    }

}
sub vcl_deliver {
    if (resp.http.X-Magic-Redirect == "1") {
        unset resp.http.X-Magic-Redirect;
        return(restart);
    }
    return(deliver);
}

Monday, January 7, 2013

Building FFMPEG for Centos


For some reason, FFMPEG on RHEL/Centos is pretty much crap for just about anything I needed so far, so the only option was building it myself. Hardly as simple as it might seem, most recipes out there are... crap. Yes, they are, really, especially when dealing with people needing it for video streaming with watermarks etc. etc. etc.

Anyway, this recipe works:

https://ffmpeg.org/trac/ffmpeg/wiki/CentosCompilationGuide

Good luck, you might need it.

UPDATE: the link above does no longer work for CentOS 5.9, at least not without some serious voodoo.
So, a cut and paste recipe to turn your relatively old linux into a media churning and streaming machine (executed as root):

rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
yum install zlib-devel autoconf automake gcc-c++  SDL-devel.x86_64 libexif.x86_64 libmcrypt.x86_64 libtool git perl-Git nasm freeglut-devel.x86_64 freetype-devel.x86_64 -y

echo "1   ImageMagic"
mkdir ~/extra_packages/
cd ~/extra_packages/
wget ftp://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/linux/CentOS/x86_64/ImageMagick-6.7.9-10.x86_64.rpm
wget ftp://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/linux/CentOS/x86_64/ImageMagick-devel-6.7.9-10.x86_64.rpm
yum localinstall ImageMagick-6.7.9-10.x86_64.rpm ImageMagick-devel-6.7.9-10.x86_64.rpm -y --nogpgcheck
cd -

echo "2   FFmpeg transcoder"
echo "(Based on http://ffmpeg.org/trac/ffmpeg/wiki/CentosCompilationGuide)"

mkdir ~/ffmpeg-source

echo "Yasm"
echo "Yasm is an assembler used by x264 and FFmpeg."
cd ~/ffmpeg-source
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install
cd -

echo "x264"
echo "H.264 video encoder."
cd ~/ffmpeg-source
git clone git://git.videolan.org/x264
cd x264
./configure --enable-static
make
make install
cd -

echo "LAME"
echo "MP3 audio encoder."
cd ~/ffmpeg-source
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --disable-shared --enable-nasm
make
make install
cd -

echo "libvpx"
echo "VP8 video encoder."
cd ~/ffmpeg-source
git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure
make
make install
cd -

echo "vo-aacenc"
echo "VisualOn AAC audio encoder."
cd ~/ffmpeg-source
wget http://downloads.sourceforge.net/opencore-amr/vo-aacenc-0.1.2.tar.gz
tar xzvf vo-aacenc-0.1.2.tar.gz
cd vo-aacenc-0.1.2
./configure --disable-shared
make
make install
cd -

echo "FFmpeg"
cd ~/ffmpeg-source
git clone git://source.ffmpeg.org/ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-libmp3lame  --enable-libvo-aacenc --enable-libvpx --enable-libx264 --enable-version3
make
make install
ln -s /usr/local/bin/ffmpeg /bin/ffmpeg
cd -

echo "3   Exiftool"
mkdir ~/extra_packages
cd ~/extra_packages/
wget http://owl.phy.queensu.ca/~phil/exiftool/Image-ExifTool-9.04.tar.gz
tar xvzf Image-ExifTool-9.04.tar.gz
cd Image-ExifTool-9.04
perl Makefile.PL
make
make test
make install
cd -

echo "4 MP4Box"
lastdir=`pwd`
mkdir ~/MP4box
cd !$
wget http://sourceforge.net/projects/gpac/files/GPAC/GPAC%200.4.5/gpac-0.4.5.tar.gz/download
wget http://sourceforge.net/projects/gpac/files/GPAC%20extra%20libs/GPAC%20extra%20libs%200.4.5/gpac_extra_libs-0.4.5.tar.gz/download
tar -xzf gpac-0.4.5.tar.gz
tar -xzf gpac_extra_libs-0.4.5.tar.gz
cd gpac_extra_libs
cp -rf * ../gpac/extra_lib/
cd ../gpac
chmod +x configure
./configure
make lib
make apps
make install lib
make install
cp bin/gcc/libgpac.so /usr/lib/
ln -s /usr/local/bin/MP4Box /bin/MP4Box
ldconfig
cd $lastdir