hooks.texi 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. \input texinfo @c -*- texinfo -*-
  2. @settitle Video Hook Documentation
  3. @titlepage
  4. @sp 7
  5. @center @titlefont{Video Hook Documentation}
  6. @sp 3
  7. @end titlepage
  8. @chapter Introduction
  9. @var{Please be aware that vhook is deprecated, and hence its development is
  10. frozen (bug fixes are still accepted).
  11. The substitute will be 'libavfilter', the result of our 'Video Filter API'
  12. Google Summer of Code project. You may monitor its progress by subscribing to
  13. the ffmpeg-soc mailing list at
  14. @url{http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc}.}
  15. The video hook functionality is designed (mostly) for live video. It allows
  16. the video to be modified or examined between the decoder and the encoder.
  17. Any number of hook modules can be placed inline, and they are run in the
  18. order that they were specified on the ffmpeg command line.
  19. The video hook modules are provided for use as a base for your own modules,
  20. and are described below.
  21. Modules are loaded using the -vhook option to ffmpeg. The value of this parameter
  22. is a space separated list of arguments. The first is the module name, and the rest
  23. are passed as arguments to the Configure function of the module.
  24. The modules are dynamic libraries: They have different suffixes (.so, .dll, .dylib)
  25. depending on your platform. And your platform dictates if they need to be
  26. somewhere in your PATH, or in your LD_LIBRARY_PATH. Otherwise you will need to
  27. specify the full path of the vhook file that you are using.
  28. @section null.c
  29. This does nothing. Actually it converts the input image to RGB24 and then converts
  30. it back again. This is meant as a sample that you can use to test your setup.
  31. @section fish.c
  32. This implements a 'fish detector'. Essentially it converts the image into HSV
  33. space and tests whether more than a certain percentage of the pixels fall into
  34. a specific HSV cuboid. If so, then the image is saved into a file for processing
  35. by other bits of code.
  36. Why use HSV? It turns out that HSV cuboids represent a more compact range of
  37. colors than would an RGB cuboid.
  38. @section imlib2.c
  39. This module implements a text overlay for a video image. Currently it
  40. supports a fixed overlay or reading the text from a file. The string
  41. is passed through strftime() so that it is easy to imprint the date and
  42. time onto the image.
  43. This module depends on the external library imlib2, available on
  44. Sourceforge, among other places, if it is not already installed on
  45. your system.
  46. You may also overlay an image (even semi-transparent) like TV stations do.
  47. You may move either the text or the image around your video to create
  48. scrolling credits, for example.
  49. The font file used is looked for in a FONTPATH environment variable, and
  50. prepended to the point size as a command line option and can be specified
  51. with the full path to the font file, as in:
  52. @example
  53. -F /usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf/20
  54. @end example
  55. where 20 is the point size.
  56. You can specify the filename to read RGB color names from. If it is not
  57. specified, these defaults are used: @file{/usr/share/X11/rgb.txt} and
  58. @file{/usr/lib/X11/rgb.txt}
  59. Options:
  60. @multitable @columnfractions .2 .8
  61. @item @option{-C <rgb.txt>} @tab The filename to read RGB color names from
  62. @item @option{-c <color>} @tab The color of the text
  63. @item @option{-F <fontname>} @tab The font face and size
  64. @item @option{-t <text>} @tab The text
  65. @item @option{-f <filename>} @tab The filename to read text from
  66. @item @option{-x <expression>}@tab x coordinate of text or image
  67. @item @option{-y <expression>}@tab y coordinate of text or image
  68. @item @option{-i <filename>} @tab The filename to read a image from
  69. @item @option{-R <expression>}@tab Value for R color
  70. @item @option{-G <expression>}@tab Value for G color
  71. @item @option{-B <expression>}@tab Value for B color
  72. @item @option{-A <expression>}@tab Value for Alpha channel
  73. @end multitable
  74. Expressions are functions of these variables:
  75. @multitable @columnfractions .2 .8
  76. @item @var{N} @tab frame number (starting at zero)
  77. @item @var{H} @tab frame height
  78. @item @var{W} @tab frame width
  79. @item @var{h} @tab image height
  80. @item @var{w} @tab image width
  81. @item @var{X} @tab previous x coordinate of text or image
  82. @item @var{Y} @tab previous y coordinate of text or image
  83. @end multitable
  84. You may also use the constants @var{PI}, @var{E}, and the math functions available at the
  85. FFmpeg formula evaluator at (@url{ffmpeg-doc.html#SEC13}), except @var{bits2qp(bits)}
  86. and @var{qp2bits(qp)}.
  87. Usage examples:
  88. @example
  89. # Remember to set the path to your fonts
  90. FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
  91. FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
  92. FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
  93. export FONTPATH
  94. # Bulb dancing in a Lissajous pattern
  95. ffmpeg -i input.avi -vhook \
  96. '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' \
  97. -acodec copy -sameq output.avi
  98. # Text scrolling
  99. ffmpeg -i input.avi -vhook \
  100. 'vhook/imlib2.dll -c red -F Vera.ttf/20 -x 150+0.5*N -y 70+0.25*N -t Hello' \
  101. -acodec copy -sameq output.avi
  102. # Date and time stamp, security-camera style:
  103. ffmpeg -r 29.97 -s 320x256 -f video4linux -i /dev/video0 \
  104. -vhook 'vhook/imlib2.so -x 0 -y 0 -i black-260x20.png' \
  105. -vhook 'vhook/imlib2.so -c white -F VeraBd.ttf/12 -x 0 -y 0 -t %A-%D-%T' \
  106. output.avi
  107. In this example the video is captured from the first video capture card as a
  108. 320x256 AVI, and a black 260 by 20 pixel PNG image is placed in the upper
  109. left corner, with the day, date and time overlaid on it in Vera Bold 12
  110. point font. A simple black PNG file 260 pixels wide and 20 pixels tall
  111. was created in the GIMP for this purpose.
  112. # Scrolling credits from a text file
  113. ffmpeg -i input.avi -vhook \
  114. 'vhook/imlib2.so -c white -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \
  115. -sameq output.avi
  116. In this example, the text is stored in a file, and is positioned 100
  117. pixels from the left hand edge of the video. The text is scrolled from the
  118. bottom up. Making the y factor positive will scroll from the top down.
  119. Increasing the magnitude of the y factor makes the text scroll faster,
  120. decreasing it makes it scroll slower. Hint: Blank lines containing only
  121. a newline are treated as end-of-file. To create blank lines, use lines
  122. that consist of space characters only.
  123. # Scrolling credits with custom color from a text file
  124. ffmpeg -i input.avi -vhook \
  125. 'vhook/imlib2.so -C rgb.txt -c CustomColor1 -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \
  126. -sameq output.avi
  127. This example does the same as the one above, but specifies an rgb.txt file
  128. to be used, which has a custom-made color in it.
  129. # Variable colors
  130. ffmpeg -i input.avi -vhook \
  131. '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))' \
  132. -sameq output.avi
  133. In this example, the color for the text goes up and down from black to
  134. white.
  135. # Text fade-out
  136. ffmpeg -i input.avi -vhook \
  137. 'vhook/imlib2.so -t Hello -A max(0,255-exp(N/47))' \
  138. -sameq output.avi
  139. In this example, the text fades out in about 10 seconds for a 25 fps input
  140. video file.
  141. # scrolling credits from a graphics file
  142. ffmpeg -sameq -i input.avi \
  143. -vhook 'vhook/imlib2.so -x 0 -y -1.0*N -i credits.png' output.avi
  144. In this example, a transparent PNG file the same width as the video
  145. (e.g. 320 pixels), but very long, (e.g. 3000 pixels), was created, and
  146. text, graphics, brushstrokes, etc, were added to the image. The image
  147. is then scrolled up, from the bottom of the frame.
  148. @end example
  149. @section ppm.c
  150. It's basically a launch point for a PPM pipe, so you can use any
  151. executable (or script) which consumes a PPM on stdin and produces a PPM
  152. on stdout (and flushes each frame). The Netpbm utilities are a series of
  153. such programs.
  154. A list of them is here:
  155. @url{http://netpbm.sourceforge.net/doc/directory.html}
  156. Usage example:
  157. @example
  158. ffmpeg -i input -vhook "/path/to/ppm.so some-ppm-filter args" output
  159. @end example
  160. @section drawtext.c
  161. This module implements a text overlay for a video image. Currently it
  162. supports a fixed overlay or reading the text from a file. The string
  163. is passed through strftime() so that it is easy to imprint the date and
  164. time onto the image.
  165. Features:
  166. @itemize @minus
  167. @item TrueType, Type1 and others via the FreeType2 library
  168. @item Font kerning (better output)
  169. @item Line Wrap (put the text that doesn't fit one line on the next line)
  170. @item Background box (currently in development)
  171. @item Outline
  172. @end itemize
  173. Options:
  174. @multitable @columnfractions .2 .8
  175. @item @option{-c <color>} @tab Foreground color of the text ('internet' way) <#RRGGBB> [default #FFFFFF]
  176. @item @option{-C <color>} @tab Background color of the text ('internet' way) <#RRGGBB> [default #000000]
  177. @item @option{-f <font-filename>} @tab font file to use
  178. @item @option{-t <text>} @tab text to display
  179. @item @option{-T <filename>} @tab file to read text from
  180. @item @option{-x <pos>} @tab x coordinate of the start of the text
  181. @item @option{-y <pos>} @tab y coordinate of the start of the text
  182. @end multitable
  183. Text fonts are being looked for in a FONTPATH environment variable.
  184. If the FONTPATH environment variable is not available, or is not checked by
  185. your target (i.e. Cygwin), then specify the full path to the font file as in:
  186. @example
  187. -f /usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf
  188. @end example
  189. Usage Example:
  190. @example
  191. # Remember to set the path to your fonts
  192. FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
  193. FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
  194. FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
  195. export FONTPATH
  196. # Time and date display
  197. ffmpeg -f video4linux2 -i /dev/video0 \
  198. -vhook 'vhook/drawtext.so -f VeraBd.ttf -t %A-%D-%T' movie.mpg
  199. This example grabs video from the first capture card and outputs it to an
  200. MPEG video, and places "Weekday-dd/mm/yy-hh:mm:ss" at the top left of the
  201. frame, updated every second, using the Vera Bold TrueType Font, which
  202. should exist in: /usr/X11R6/lib/X11/fonts/TTF/
  203. @end example
  204. Check the man page for strftime() for all the various ways you can format
  205. the date and time.
  206. @section watermark.c
  207. Command Line options:
  208. @multitable @columnfractions .2 .8
  209. @item @option{-m [0|1]} @tab Mode (default: 0, see below)
  210. @item @option{-t 000000 - FFFFFF} @tab Threshold, six digit hex number
  211. @item @option{-f <filename>} @tab Watermark image filename, must be specified!
  212. @end multitable
  213. MODE 0:
  214. The watermark picture works like this (assuming color intensities 0..0xFF):
  215. Per color do this:
  216. If mask color is 0x80, no change to the original frame.
  217. If mask color is < 0x80 the absolute difference is subtracted from the
  218. frame. If result < 0, result = 0.
  219. If mask color is > 0x80 the absolute difference is added to the
  220. frame. If result > 0xFF, result = 0xFF.
  221. You can override the 0x80 level with the -t flag. E.g. if threshold is
  222. 000000 the color value of watermark is added to the destination.
  223. This way a mask that is visible both in light and dark pictures can be made
  224. (e.g. by using a picture generated by the Gimp and the bump map tool).
  225. An example watermark file is at:
  226. @url{http://engene.se/ffmpeg_watermark.gif}
  227. MODE 1:
  228. Per color do this:
  229. If mask color > threshold color then the watermark pixel is used.
  230. Example usage:
  231. @example
  232. ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif' -an out.mov
  233. ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif -m 1 -t 222222' -an out.mov
  234. @end example
  235. @bye