[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 1. Introduction

Please be aware that vhook is deprecated, and hence its development is frozen (bug fixes are still accepted). The substitute will be the result of our 'Video Filter API' Google Summer of Code project. You may monitor its progress by subscribing to the ffmpeg-soc mailing list at http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc.

The video hook functionality is designed (mostly) for live video. It allows the video to be modified or examined between the decoder and the encoder.

Any number of hook modules can be placed inline, and they are run in the order that they were specified on the ffmpeg command line.

The video hook modules are provided for use as a base for your own modules, and are described below.

Modules are loaded using the -vhook option to ffmpeg. The value of this parameter is a space separated list of arguments. The first is the module name, and the rest are passed as arguments to the Configure function of the module.

The modules are dynamic libraries: They have different suffixes (.so, .dll, .dylib) depending on your platform. And your platform dictates if they need to be somewhere in your PATH, or in your LD_LIBRARY_PATH. Otherwise you will need to specify the full path of the vhook file that you are using.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 1.1 null.c

This does nothing. Actually it converts the input image to RGB24 and then converts it back again. This is meant as a sample that you can use to test your setup.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 1.2 fish.c

This implements a 'fish detector'. Essentially it converts the image into HSV space and tests whether more than a certain percentage of the pixels fall into a specific HSV cuboid. If so, then the image is saved into a file for processing by other bits of code.

Why use HSV? It turns out that HSV cuboids represent a more compact range of colors than would an RGB cuboid.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 1.3 imlib2.c

This module implements a text overlay for a video image. Currently it supports a fixed overlay or reading the text from a file. The string is passed through strftime() so that it is easy to imprint the date and time onto the image.

This module depends on the external library imlib2, available on Sourceforge, among other places, if it is not already installed on your system.

You may also overlay an image (even semi-transparent) like TV stations do. You may move either the text or the image around your video to create scrolling credits, for example.

The font file used is looked for in a FONTPATH environment variable, and prepended to the point size as a command line option and can be specified with the full path to the font file, as in:

    -F /usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf/20

where 20 is the point size.

You can specify the filename to read RGB color names from. If it is not specified, these defaults are used: ``/usr/share/X11/rgb.txt'` and ``/usr/lib/X11/rgb.txt'`

Options:

``-C <rgb.txt>'` | The filename to read RGB color names from
``-c <color>'` | The color of the text
``-F <fontname>'` | The font face and size
``-t <text>'` | The text
``-f <filename>'` | The filename to read text from
``-x <expression>'` | x coordinate of text or image
``-y <expression>'` | y coordinate of text or image
``-i <filename>'` | The filename to read a image from
``-R <expression>'` | Value for R color
``-G <expression>'` | Value for G color
``-B <expression>'` | Value for B color
``-A <expression>'` | Value for Alpha channel

Expressions are functions of these variables:

N | frame number (starting at zero)
H | frame height
W | frame width
h | image height
w | image width
X | previous x coordinate of text or image
Y | previous y coordinate of text or image

You may also use the constants PI, E, and the math functions available at the FFmpeg formula evaluator at (ffmpeg-doc.html#SEC13), except bits2qp(bits) and qp2bits(qp).

Usage examples:

       # Remember to set the path to your fonts
       FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
       FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
       FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
       export FONTPATH

       # Bulb dancing in a Lissajous pattern
       ffmpeg -i input.avi -vhook \
         'vhook/imlib2.dll -x W*(0.5+0.25*sin(N/47*PI))-w/2 -y H*(0.5+0.50*cos(N/97*PI))-h/2 -i /usr/share/imlib2/data/images/bulb.png' \
         -acodec copy -sameq output.avi

       # Text scrolling
       ffmpeg -i input.avi -vhook \
         'vhook/imlib2.dll -c red -F Vera.ttf/20 -x 150+0.5*N -y 70+0.25*N -t Hello' \
         -acodec copy -sameq output.avi

       # Date and time stamp, security-camera style:
       ffmpeg -r 29.97 -s 320x256 -f video4linux -i /dev/video0 \
         -vhook 'vhook/imlib2.so -x 0 -y 0 -i black-260x20.png' \
         -vhook 'vhook/imlib2.so -c white -F VeraBd.ttf/12 -x 0 -y 0 -t %A-%D-%T' \
         output.avi

         In this example the video is captured from the first video capture card as a
         320x256 AVI, and a black 260 by 20 pixel PNG image is placed in the upper
         left corner, with the day, date and time overlaid on it in Vera Bold 12
         point font. A simple black PNG file 260 pixels wide and 20 pixels tall
         was created in the GIMP for this purpose.

       # Scrolling credits from a text file
       ffmpeg -i input.avi -vhook \
         'vhook/imlib2.so -c white -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \
         -sameq output.avi

         In this example, the text is stored in a file, and is positioned 100
         pixels from the left hand edge of the video. The text is scrolled from the
         bottom up. Making the y factor positive will scroll from the top down.
         Increasing the magnitude of the y factor makes the text scroll faster,
         decreasing it makes it scroll slower. Hint: Blank lines containing only
         a newline are treated as end-of-file. To create blank lines, use lines
         that consist of space characters only.

       # Scrolling credits with custom color from a text file
       ffmpeg -i input.avi -vhook \
         'vhook/imlib2.so -C rgb.txt -c CustomColor1 -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \
         -sameq output.avi

         This example does the same as the one above, but specifies an rgb.txt file
         to be used, which has a custom-made color in it.

       # Variable colors
       ffmpeg -i input.avi -vhook \
         'vhook/imlib2.so -t Hello -R abs(255*sin(N/47*PI)) -G abs(255*sin(N/47*PI)) -B abs(255*sin(N/47*PI))' \
         -sameq output.avi

         In this example, the color for the text goes up and down from black to
         white.

       # Text fade-out
       ffmpeg -i input.avi -vhook \
         'vhook/imlib2.so -t Hello -A max(0,255-exp(N/47))' \
         -sameq output.avi

         In this example, the text fades out in about 10 seconds for a 25 fps input
         video file.

       # scrolling credits from a graphics file
       ffmpeg -sameq -i input.avi \
         -vhook 'vhook/imlib2.so -x 0 -y -1.0*N -i credits.png' output.avi

         In this example, a transparent PNG file the same width as the video
         (e.g. 320 pixels), but very long, (e.g. 3000 pixels), was created, and
         text, graphics, brushstrokes, etc, were added to the image. The image
         is then scrolled up, from the bottom of the frame.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 1.4 ppm.c

It's basically a launch point for a PPM pipe, so you can use any executable (or script) which consumes a PPM on stdin and produces a PPM on stdout (and flushes each frame). The Netpbm utilities are a series of such programs.

A list of them is here:

http://netpbm.sourceforge.net/doc/directory.html

Usage example:

    ffmpeg -i input -vhook "/path/to/ppm.so some-ppm-filter args" output

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 1.5 drawtext.c

This module implements a text overlay for a video image. Currently it supports a fixed overlay or reading the text from a file. The string is passed through strftime() so that it is easy to imprint the date and time onto the image.

Features:

Options:

``-c <color>'` | Foreground color of the text ('internet' way) <#RRGGBB> [default #FFFFFF]
``-C <color>'` | Background color of the text ('internet' way) <#RRGGBB> [default #000000]
``-f <font-filename>'` | font file to use
``-t <text>'` | text to display
``-T <filename>'` | file to read text from
``-x <pos>'` | x coordinate of the start of the text
``-y <pos>'` | y coordinate of the start of the text

Text fonts are being looked for in a FONTPATH environment variable. If the FONTPATH environment variable is not available, or is not checked by your target (i.e. Cygwin), then specify the full path to the font file as in:

    -f /usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf

Usage Example:

       # Remember to set the path to your fonts
       FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
       FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
       FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
       export FONTPATH

       # Time and date display
       ffmpeg -f video4linux2 -i /dev/video0 \
       -vhook 'vhook/drawtext.so -f VeraBd.ttf -t %A-%D-%T' movie.mpg

         This example grabs video from the first capture card and outputs it to an
         MPEG video, and places "Weekday-dd/mm/yy-hh:mm:ss" at the top left of the
         frame, updated every second, using the Vera Bold TrueType Font, which
         should exist in: /usr/X11R6/lib/X11/fonts/TTF/

Check the man page for strftime() for all the various ways you can format the date and time.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 1.6 watermark.c

Command Line options:

``-m [0|1]'` | Mode (default: 0, see below)
``-t 000000 - FFFFFF'` | Threshold, six digit hex number
``-f <filename>'` | Watermark image filename, must be specified!

MODE 0: The watermark picture works like this (assuming color intensities 0..0xFF): Per color do this: If mask color is 0x80, no change to the original frame. If mask color is < 0x80 the absolute difference is subtracted from the frame. If result < 0, result = 0. If mask color is > 0x80 the absolute difference is added to the frame. If result > 0xFF, result = 0xFF.

You can override the 0x80 level with the -t flag. E.g. if threshold is 000000 the color value of watermark is added to the destination.

This way a mask that is visible both in light and dark pictures can be made (e.g. by using a picture generated by the Gimp and the bump map tool).

An example watermark file is at: http://engene.se/ffmpeg_watermark.gif

MODE 1: Per color do this: If mask color > threshold color then the watermark pixel is used.

Example usage:

       ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif' -an out.mov
       ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif -m 1 -t 222222' -an out.mov

[Top] | [Contents] | [Index] | [ ? ]

# About This Document

This document was generated by Charlie & on December, 1 2007 using texi2html 1.76.

The buttons in the navigation panels have the following meaning:

Button | Name | Go to | From 1.2.3 go to
--- | --- | --- | ---
[ < ] | Back | previous section in reading order | 1.2.2
[ > ] | Forward | next section in reading order | 1.2.4
[ << ] | FastBack | beginning of this chapter or previous chapter | 1
[ Up ] | Up | up section | 1.2
[ >> ] | FastForward | next chapter | 2
[Top] | Top | cover (top) of document |
[Contents] | Contents | table of contents |
[Index] | Index | index |
[ ? ] | About | about (help) |

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:

- 1. Section One
  - 1.1 Subsection One-One
    - ...
  - 1.2 Subsection One-Two
    - 1.2.1 Subsubsection One-Two-One
    - 1.2.2 Subsubsection One-Two-Two
    - 1.2.3 Subsubsection One-Two-Three <== Current Position
    - 1.2.4 Subsubsection One-Two-Four
  - 1.3 Subsection One-Three
    - ...
  - 1.4 Subsection One-Four

This document was generated by Charlie & on December, 1 2007 using texi2html 1.76.