You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
11KB

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