Thursday, May 24, 2007

Screenshots of Web Pages

It is not a problem to make a screenshots of web pages if you have running firefox on your desktop. But if you can’t start X11 (X.org), it is not so trivial. So the post is about how to create screenshots of web pages via firefox without X11 (X.org) server.

Unfortunately Firefox can’t work without a display it can connect to. Fortunately there are standard tools which allow to create the necessary environment without starting of X11 (X.org) server. Xvfb tool must be installed.

First of all extract the Firefox to some folder and start it in order to allow it to create profile in your home directory. Right now you need Xvfb.

$> Xvfb -ac -screen :0 1024x768x16 2>&1 > /dev/null &
$> firefox

Now you can terminate Firefox with Ctrl-C and continue the setup. We need a minimal Firefox application panels to make a good screenshots. Thus the Firefox have to be started in a full screen mode. The extension Autohide is very useful here. Just install it:

$> firefox -install-global-extension autohide.xpi

This command does not need X11 environment and will be successful. After the installation firefox will understand new command line option -fullscreen.

Also Firefox noises with various popups: yellow bar with prompt for plugin install, confirmation for previous session restoring, etc. The following setup strings disable most of them:

user_pref("browser.sessionstore.enabled", false);
user_pref("browser.sessionstore.resume_from_crash", false);
user_pref("browser.startup.page", 0);
user_pref("plugin.default_plugin_disabled", false);
user_pref("privacy.popups.disable_from_plugins", 3);
user_pref("alerts.totalOpenTime", 1);
user_pref("security.enable_ssl2", false);
user_pref("security.enable_ssl3", false);

The strings have to be placed in the file ~/.mozilla/firefox/XXXXX.nameofprofile/prefs.js Please see the site http://kb.mozillazine.org/Knowledge_Base for explanation of all this options. The topic is not about it.

If the Firefox and Xvfb are installed you can try to make a screenshot.

# first of all we have to start Xvfb (if not started yet)
$> Xvfb -ac -screen :0 1024x768x16 2>&1 > /dev/null &

$> firefox --display=:0 http://www.google.com/ \
-silent -nosplash -fullscreen 2>&1 > /dev/null

# dump X screen to file
$> xwd -root -out -display :0 screen.xwd

# convert dump file to some usual format
# and crop possible scrollers of Firefox
$> convert screen.xwd -crop 1005x768 screen.png

# care about closing of Xvfb and firefox
$> kill `pidof firefox`
$> kill `pidof Xvfb`

The same, for explanation of what is Xvfb, xwd, convert, pidof and kill tools please see the corresponding man pages, since it is not a subject of this topic.

Thursday, May 17, 2007

FFmpeg Compilation

How to compile ffmpeg with all almost all possible codecs.

Library Versions

  • a52dec-0.7.4.tar.gz
  • amrnb-6.1.0.3.tar.bz2
  • amrwb-7.0.0.0.tar.bz2
  • faac-1.24.tar.gz
  • faad2-2.0.tar.gz
  • lame-3.97.tar.gz
  • libogg-1.1.3.tar.gz
  • libvorbis-1.1.2.tar.gz
  • libtheora-mmx-1.0alpha5.zip
  • x264-snapshot-20070515-2245.tar.bz2 (with yasm-0.6.0.tar.gz )
  • xvidcore-1.1.2.tar.bz2
  • ffmpeg-checkout-snapshot.tar.bz2 (snapshort from 2007-05-09)

Actually the latest versions of all the libraries was got. Excluding faad and faac. The given pair is the only combination which I was able to compile and make work with ffmpeg.

Compilation Process

Suggestion: it is very useful to start ldconfig after every library compilation.

  • faad2 must be compiled (with option --with-mp4v2) before faac
    • Possible problem 1: when doing make it fails with error about missing separator. Fix: remove the target rpm at the bottom of Makefile, after editing the bottom of the file must look like that:
      ...
      # Tell versions [3.59,3.63) of GNU make to not export all variables.
      # Otherwise a system limit (for SysV at least) may be exceeded.
      .NOEXPORT:
    • Possible problem 2: invalid initializer for virtual method when compiling. Fix: in files mp4property.h and rtphint.h fix all virtual methods defined with NULL. Example:
      virtual void SetCount(u_int32_t count) = NULL;

      replace to

      virtual void SetCount(u_int32_t count) = 0;

      There are several methods in the files defines in such style, fix them all.

  • faac ensure that it’ll be build with mp4v2 from compiled faad. After configuration complete, check:
    cat config.log | grep 'with MP4'

    it must found string *** Building with MP4 support ***

  • libogg must be compiled before vorbis, ensure that vorbis config found libogg
  • libtheora-mmx must be compiled after libogg and vorbis
  • x264 must be compiled with --enable-shared
  • ffmpeg
    ./configure --enable-shared --enable-libfaad \
    --enable-libfaadbin --enable-libfaac \
    --enable-libvorbis --enable-libogg \
    --enable-libtheora --enable-xvid \
    --enable-libmp3lame --enable-liba52 \
    --enable-liba52bin --enable-libamr-nb \
    --enable-libamr-wb --enable-gpl --enable-x264
  • a52 it is not a mistake that the library is listed after ffmpeg.
    • Possible problem: If I configure a52 with the flag --enable-shared before ffmpeg compilation, then the ffmpeg compilation failed. If I do not recompile a52 after, ffmpeg can’t open shared a52 library because it is compiled as static by default. The way I was able to make it work:
      1. compile a52 without flags and install
      2. compile and install ffmpeg (see above)
      3. AGAIN configure a52 with flag --enable-shared, compile and install

Thursday, May 3, 2007

Safari Ajax Problem

Ajax (or AJAX) is shorthand for "Asynchronous JavaScript and XML". It's clear that this technology imply asynchronous communication, but XmlHttpRequest object can do synchronized calls to server. Avoid this practice because it's not working in Safari browser.

We have used phpRequest class for such calls (http://www.phphacks.com/content/view/52/33/). It has execute() method which sends request to server, wait for response, and return it as result. Example of the code:

var httpReq = new phpRequest('myScript.php');
var resp = httpReq.execute();
// do something with resp...
alert(resp);

This approach is not works in Safari browser (not sure about version number). Small refactoring of this code and new method executeWithCallback() makes everyone happy :-)

var httpReq = new phpRequest('myScript.php');
var cb = function(resp) {
// do something with resp...
alert(resp);
};
httpReq.executeWithCallback(cb);

Code for executeWithCallback() is trivial I suppose. So, make your code really asynchronous to make it robust and avoid problems like this. Good example is SAJAX library: http://www.modernmethod.com/sajax