Host support for advanced multimedia features

Out of the box emergence will accept uploads for various image, video, and audio formats. Additional tools need to be installed on the host system though to enable features like video thumbnailing, face-detection cropping, and thumbnailing for advanced image formats.

Video thumbnails

The avconv command is used to extract thumbnails from videos, you can install it on Ubuntu with:

sudo apt-get install libav-tools

Video transcoding

Transcoding videos requires the avconv command as described above and additionally needs exiftool for extracting rotation metadata which can be installed on Ubuntu with:

sudo apt-get install libimage-exiftool-perl

Vector image thumbnails

To support generating thumbnails for vector formats like PDF, AI, SVG, and PostScript, the convert command from ImageMagick must be installed. On Ubuntu you can install it with:

sudo apt-get install imagemagick

As of this writing ImageMagick is installed by emergence’s quickinstall script and setup guide.

Face detection for cropping

When requesting cropped thumbnails, emergence will by default use a pure PHP library to detect the “noisiest” part of the image to center the crop on. This often works pretty well, but if the facedetect PHP extension is available emergence will prioritize using it to detect and center on a face in the image. Facial detection requires OpenCV and several other dependencies be in place on the host system.

Instructions on setting up the extension and its dependencies can be found on the project’s homepage: http://www.xarg.org/project/php-facedetect/

Installing

Installing facedetect has become a bit messy due to never actually being shipped to PECL, this works on Ubuntu 16.04:

  • Install dependencies:

    sudo apt-get install php5-dev pkg-config python libjpeg-dev libpng-dev libtiff-dev libopencv-dev
    
  • Clone facedetect source:

    git clone https://github.com/infusion/PHP-Facedetect.git
    cd PHP-Facedetect/
    
  • Add missing file (yeah, yuck):

    sudo wget https://raw.githubusercontent.com/ernetas/hi-php/latest/objdetect_c.h -O /usr/include/opencv2/objdetect/objdetect_c.h
    
  • Build and install extension:

    phpize
    ./configure
    make
    sudo make install
    
  • Enable extension for PHP FPM environment

    echo "extension=facedetect.so" | sudo tee /etc/php5/mods-available/facedetect.ini
    cd /etc/php5/fpm/conf.d/
    sudo ln -s ../../mods-available/facedetect.ini
    
  • Stop -> Start PHP service