Extract an image screenshot from a Video with ffmpeg 3

Posted by Antonin AMAND Mon, 27 Nov 2006 18:17:00 GMT

Here is a way to extract a sample image from a video with ffmpeg :

$ ffmpeg  -itsoffset -4  -i sample.mov -vcodec png -vframes 1 -an -f rawvideo -s 320x240 test.png
  • -itsoffset -4 : means that you want to extract the image 4 seconds after video starts.

Easy setup a Mongrel cluster with Apache 2.2 on Mac OS X

Posted by Antonin AMAND Mon, 02 Oct 2006 12:19:00 GMT

Mongrel is a very fast and secure server for Ruby On Rails applications. It also supports Nitro and Camping. Setting up a mongrel_cluster on Mac OS X is not very difficult but it is a bit different from other Unix platforms.

What you need to start :

Step 1 : Install Mongrel

Mongrel is available for unix platform and Win32 systems as a gem.

$ sudo gem install mongrel mongrel_cluster
Choose the latest ruby version.

Installing Apache 2.2

You can compile it from sources. But it is easier to install it via MacPorts.

$ sudo port install apache2

All apache2 files will be installed in /opt/local/apache2, including binaries and configuration files.

Setting up Apache 2.2

chdir to /opt/local/apache2/conf and copy the sample file to httpd.conf
$ cd /opt/local/apache2/conf
$ sudo cp httpd.conf.sample httpd.conf

Create a new directory that will contain your application specific configuration files for Apache.

$ sudo mkdir myapp
$ cd myapp

Create 3 files for your new application. (adapted from codahale blog)

$ sudo touch myapp.common myapp.conf myapp.cluster.conf

Here is the files content :

myapp.common :

  ServerName www.myserver.com  
  DocumentRoot /path/to/my/app/public

  <Directory "/path/to/my/app/public">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>

  RewriteEngine On

  # Make sure people go to www.myapp.com, not myapp.com
  RewriteCond %{HTTP_HOST} ^myapp.com$ [NC]
  RewriteRule ^(.*)$ http://www.myapp.com$1 [R=301,L]
  # Yes, I've read no-www.com, but my site already has much Google-Fu on
  # www.blah.com. Feel free to comment this out.

  # Uncomment for rewrite debugging
  #RewriteLog logs/myapp_rewrite_log
  #RewriteLogLevel 9 

  # Check for maintenance file and redirect all requests
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]

  # Rewrite index to check for static
  RewriteRule ^/$ /index.html [QSA] 

  # Rewrite to check for Rails cached page
  RewriteRule ^([^.]+)$ $1.html [QSA]

  # Redirect all non-static requests to cluster
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

  # Deflate
  AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch bMSIE !no-gzip !gzip-only-text/html

  # Uncomment for deflate debugging
  #DeflateFilterNote Input input_info
  #DeflateFilterNote Output output_info
  #DeflateFilterNote Ratio ratio_info
  #LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
  #CustomLog logs/myapp_deflate_log deflate

myapp.conf :

<VirtualHost *:80>
  Include /opt/local/apache2/conf/myapp/myapp.common

  ErrorLog /path/to/logs/error.log
  CustomLog /path/to/logs/access.log combined
</VirtualHost>

myapp.cluster.conf :

<Proxy balancer://mongrel_cluster>
  BalancerMember http://127.0.0.1:8000
  BalancerMember http://127.0.0.1:8001
  BalancerMember http://127.0.0.1:8002
</Proxy>

Now that your files are created. at this to the bottom of /opt/local/apache2/conf/httpd.conf

NameVirtualHost *:80

Include conf/myapp/myapp.conf
Include conf/sites/myapp.cluster.conf

Apache is now ready to run.

Setting up Mongrel cluster

Create a new dir for mongrel cluster config

mkdir /opt/local/etc/mongrel
cd /opt/local/etc/mongrel

And create a new file “myapp.yml”

--- 
user: www
group: www
port: "8000"
cwd: /path/to/your/app/root
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 3

Setting up Startup Scripts

Enable apache startup script

$ sudo vi /etc/hostconfig

#add the following lines

APACHE2=-YES-
MONGREL=-YES-

Copy the following into /Library/StartupItems/mongrel_cluster/mongrel_cluster

(adapted from original mongrel init script)
#!/bin/bash
#
# Copyright (c) 2006 Bradley Taylor, bradley@railsmachine.com
#
# mongrel_cluster       Startup script for Mongrel clusters.
#
# chkconfig: - 85 15
# description: mongrel_cluster manages multiple Mongrel processes for use \
#              behind a load balancer.
#              

[ -r "/etc/hostconfig" ] && . "/etc/hostconfig"

CONF_DIR="/opt/local/etc/mongrel"
RETVAL=0
ENABLE_FLAG=${MONGREL:=-NO-}

if [ "${ENABLE_FLAG}" = "-NO-" ]; then
        echo "Mongrel is disabled. see /etc/hostconfig"
        exit 0
fi

case "$1" in
    start)
      mongrel_cluster_ctl start -c $CONF_DIR
      RETVAL=$?
  ;;
    stop)
      mongrel_cluster_ctl stop -c $CONF_DIR
      RETVAL=$?
  ;;
    restart)
      mongrel_cluster_ctl restart -c $CONF_DIR
      RETVAL=$?
  ;;
    *)
      echo "Usage: mongrel_cluster {start|stop|restart}"
      exit 1
  ;;
esac      

exit $RETVAL

Linux : ethernet interface supported media

Posted by Antonin AMAND Sat, 30 Sep 2006 20:54:00 GMT

I was just checking on my machines if all my ethernet cards supports 1Gb ethernet. On OS X ifconfig will give you what you want under the section supported media, but on Linux Debian it doesn’t. For this you have to use ethtool :

sudo ethtool eth0

FLV encoding with ffmpeg 15

Posted by Antonin AMAND Mon, 25 Sep 2006 17:22:00 GMT

ffmeg is a command-line tool for video encoding which has the ability to encode videos in FLV format (Macromedia plugin for direct-streaming).

First, you need to install ffmpeg with liblame support.

You may grab it as package or compile from sources.

We will compile from sources in this article for more compatibility.

first step : Installing lame get sources at http://lame.sourceforge.net, untar the archive and chdir to unpacked sources directory.

$ ./configure && make && sudo make install

second step : Installing ffmpeg

Getting sources from svn :

 $ svn export svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

Change dir to ffmpeg and compile with liblame

$ ./configure --enable-mp3lame && make && sudo make install

Your now setup. You can continue with encoding your first video

$ /usr/local/bin/ffmpeg  -i input.mov -ar 22050 -ab 56 -aspect 4:3 \
 -b 200 -r 12 -f flv -s 320x240 -acodec mp3 -ac 1 output.flv

to view the result download a swf FLV player and create a html file :

<html>
<head>
<title>Flash FLV Player</title>
</head>
<body>
<h3>My First FLV video</h3>
<object type="application/x-shockwave-flash" width="320" height="260" wmode="transparent" data="flvplayer.swf?file=output.flv&amp;autoStart=false">
<param name="movie" value="flvplayer.swf?file=output.flv&amp;autoStart=false" />
<param name="wmode" value="transparent" />
</object>

</body>
</html>

Enjoy !

Creating favicon.ico on Unix machines

Posted by Antonin AMAND Sat, 23 Sep 2006 14:27:00 GMT

Favicon are little icons that you can see in your browser before URL address.

To create this icons on unix-likes proceed as follow.

Open your favourite Image manipulator program, for me It will be The GIMP.

Create a 16×16 px PNG, and optionally a 32×32 px PNG.

Install png2ico from sources, package or compile it via darwinports.

For OS X with darwinports :

$ sudo port install png2ico

and create your favicon file :

$ png2ico favicon.ico favicon16.png favicon32.png

Now that you have your favicon file, just put it in your web server root directory.

You can had the following for IE compatibily in your web pages :


<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

Mac OS X : change lookup order, files comes first

Posted by Antonin AMAND Sat, 23 Sep 2006 13:57:00 GMT

I’m originally a Linux user. Then, in Linux lookup default order is to look first in /etc/hosts file and then to launch the dns query.

But In OS X default is to search to into NetInfo DB first.

To change this behaviour you have to change the configuration of the lookup daemon.

$ cd /etc

#if lookupd directory doesn't exists create it
$ sudo mkdir lookupd

$ cd lookupd

$ sudo echo LookupOrder Cache FF NI DNS DS > /tmp/hosts

$ sudo mv /tmp/hosts .

# reload configuration of lookupd

$ sudo lookupd -configuration

All right, you’re now setup the old fashion way.

Egroupware : hide private contacts in LDAP

Posted by Antonin AMAND Mon, 28 Aug 2006 14:47:00 GMT

Egroupware can store contacts from address book in an LDAP server. So, it is possible to access address book from a Mail client that supports LDAP.

The problem is that users would see any contact, even if it is private.

To prevent this from happening you can add this in slapd.conf :

access to dn.sub="ou=contacts,dc=example,dc=com"
        filter="(&(objectClass=phpgwContact)(phpgwContactAccess=private))"
        by dn="cn=admin,dc=example,dc=com" write
        by * none

access to dn.sub="ou=contacts,dc=example,dc=com"
        by dn="cn=admin,dc=example,dc=com" write
        by * read
Remember to add this before :
access to *
        by dn="cn=admin,dc=example,dc=com" write
        by * read

pam_ldap : Impossible to connect with local account when ldap server is down

Posted by Antonin AMAND Mon, 28 Aug 2006 10:23:00 GMT

Versions (debian packages):

  • libnss_ldap : 251-1
  • libpam-ldap : 180-1

When using ldap authentification with pam_ldap, if ldap server fails it may be impossible, or very slow to login even with a local account.

This happen when libnss-ldap is configured with the option :

bind_policy hard_open

To fix this, use :

bind_policy soft