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.

295 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 none are
  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. @end multitable
  69. Expressions are functions of these variables:
  70. @multitable @columnfractions .2 .8
  71. @item @var{N} @tab frame number (starting at zero)
  72. @item @var{H} @tab frame height
  73. @item @var{W} @tab frame width
  74. @item @var{h} @tab image height
  75. @item @var{w} @tab image width
  76. @item @var{X} @tab previous x coordinate of text or image
  77. @item @var{Y} @tab previous y coordinate of text or image
  78. @end multitable
  79. You may also use the constants @var{PI}, @var{E}, and the math functions available at the
  80. FFmpeg formula evaluator at (@url{ffmpeg-doc.html#SEC13}), except @var{bits2qp(bits)}
  81. and @var{qp2bits(qp)}.
  82. Usage examples:
  83. @example
  84. # Remember to set the path to your fonts
  85. FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
  86. FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
  87. FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
  88. export FONTPATH
  89. # Bulb dancing in a Lissajous pattern
  90. ffmpeg -i input.avi -vhook \
  91. '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' \
  92. -acodec copy -sameq output.avi
  93. # Text scrolling
  94. ffmpeg -i input.avi -vhook \
  95. 'vhook/imlib2.dll -c red -F Vera.ttf/20 -x 150+0.5*N -y 70+0.25*N -t Hello' \
  96. -acodec copy -sameq output.avi
  97. # Date and time stamp, security-camera style:
  98. ffmpeg -r 29.97 -s 320x256 -f video4linux -i /dev/video0 \
  99. -vhook 'vhook/imlib2.so -x 0 -y 0 -i black-260x20.png' \
  100. -vhook 'vhook/imlib2.so -c white -F VeraBd.ttf/12 -x 0 -y 0 -t %A-%D-%T' \
  101. output.avi
  102. In this example the video is captured from the first video capture card as a
  103. 320x256 AVI, and a black 260 by 20 pixel PNG image is placed in the upper
  104. left corner, with the day, date and time overlaid on it in Vera Bold 12
  105. point font. A simple black PNG file 260 pixels wide and 20 pixels tall
  106. was created in the GIMP for this purpose.
  107. # Scrolling credits from a text file
  108. ffmpeg -i input.avi -vhook \
  109. 'vhook/imlib2.so -c white -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \
  110. -sameq output.avi
  111. In this example, the text is stored in a file, and is positioned 100
  112. pixels from the left hand edge of the video. The text is scrolled from the
  113. bottom up. Making the y factor positive will scroll from the top down.
  114. Increasing the magnitude of the y factor makes the text scroll faster,
  115. decreasing it makes it scroll slower. Hint: Blank lines containing only
  116. a newline are treated as end-of-file. To create blank lines, use lines
  117. that consist of space characters only.
  118. # Scrolling credits with custom color from a text file
  119. ffmpeg -i input.avi -vhook \
  120. 'vhook/imlib2.so -C rgb.txt -c CustomColor1 -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \
  121. -sameq output.avi
  122. This example does the same as the one above, but specifies an rgb.txt file
  123. to be used, which has a custom made color in it.
  124. # Variable colors
  125. ffmpeg -i input.avi -vhook \
  126. '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))' \
  127. -sameq output.avi
  128. In this example, the color for the text goes up and down from black to
  129. white.
  130. # Text fade-out
  131. ffmpeg -i input.avi -vhook \
  132. 'vhook/imlib2.so -t Hello -A max(0,255-exp(N/47))' \
  133. -sameq output.avi
  134. In this example, the text fades out in about 10 seconds for a 25 fps input
  135. video file.
  136. # scrolling credits from a graphics file
  137. ffmpeg -sameq -i input.avi \
  138. -vhook 'vhook/imlib2.so -x 0 -y -1.0*N -i credits.png' output.avi
  139. In this example, a transparent PNG file the same width as the video
  140. (e.g. 320 pixels), but very long, (e.g. 3000 pixels), was created, and
  141. text, graphics, brushstrokes, etc, were added to the image. The image
  142. is then scrolled up, from the bottom of the frame.
  143. @end example
  144. @section ppm.c
  145. It's basically a launch point for a PPM pipe, so you can use any
  146. executable (or script) which consumes a PPM on stdin and produces a PPM
  147. on stdout (and flushes each frame). The Netpbm utilities are a series of
  148. such programs.
  149. A list of them is here:
  150. @url{http://netpbm.sourceforge.net/doc/directory.html}
  151. Usage example:
  152. @example
  153. ffmpeg -i input -vhook "/path/to/ppm.so some-ppm-filter args" output
  154. @end example
  155. @section drawtext.c
  156. This module implements a text overlay for a video image. Currently it
  157. supports a fixed overlay or reading the text from a file. The string
  158. is passed through strftime() so that it is easy to imprint the date and
  159. time onto the image.
  160. Features:
  161. @itemize @minus
  162. @item TrueType, Type1 and others via the FreeType2 library
  163. @item Font kerning (better output)
  164. @item Line Wrap (put the text that doesn't fit one line on the next line)
  165. @item Background box (currently in development)
  166. @item Outline
  167. @end itemize
  168. Options:
  169. @multitable @columnfractions .2 .8
  170. @item @option{-c <color>} @tab Foreground color of the text ('internet' way) <#RRGGBB> [default #FFFFFF]
  171. @item @option{-C <color>} @tab Background color of the text ('internet' way) <#RRGGBB> [default #000000]
  172. @item @option{-f <font-filename>} @tab font file to use
  173. @item @option{-t <text>} @tab text to display
  174. @item @option{-T <filename>} @tab file to read text from
  175. @item @option{-x <pos>} @tab x coordinate of the start of the text
  176. @item @option{-y <pos>} @tab y coordinate of the start of the text
  177. @end multitable
  178. Text fonts are being looked for in a FONTPATH environment variable.
  179. If the FONTPATH environment variable is not available, or is not checked by
  180. your target (i.e. Cygwin), then specify the full path to the font file as in:
  181. @example
  182. -f /usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf
  183. @end example
  184. Usage Example:
  185. @example
  186. # Remember to set the path to your fonts
  187. FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
  188. FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
  189. FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
  190. export FONTPATH
  191. # Time and date display
  192. ffmpeg -f video4linux2 -i /dev/video0 \
  193. -vhook 'vhook/drawtext.so -f VeraBd.ttf -t %A-%D-%T' movie.mpg
  194. This example grabs video from the first capture card and outputs it to an
  195. MPEG video, and places "Weekday-dd/mm/yy-hh:mm:ss" at the top left of the
  196. frame, updated every second, using the Vera Bold TrueType Font, which
  197. should exist in: /usr/X11R6/lib/X11/fonts/TTF/
  198. @end example
  199. Check the man page for strftime() for all the various ways you can format
  200. the date and time.
  201. @section watermark.c
  202. Command Line options:
  203. @multitable @columnfractions .2 .8
  204. @item @option{-m [0|1]} @tab Mode (default: 0, see below)
  205. @item @option{-t 000000 - FFFFFF} @tab Threshold, six digit hex number
  206. @item @option{-f <filename>} @tab Watermark image filename, must be specified!
  207. @end multitable
  208. MODE 0:
  209. The watermark picture works like this (assuming color intensities 0..0xFF):
  210. Per color do this:
  211. If mask color is 0x80, no change to the original frame.
  212. If mask color is < 0x80 the absolute difference is subtracted from the
  213. frame. If result < 0, result = 0.
  214. If mask color is > 0x80 the absolute difference is added to the
  215. frame. If result > 0xFF, result = 0xFF.
  216. You can override the 0x80 level with the -t flag. E.g. if threshold is
  217. 000000 the color value of watermark is added to the destination.
  218. This way a mask that is visible both in light and dark pictures can be made
  219. (e.g. by using a picture generated by the Gimp and the bump map tool).
  220. An example watermark file is at:
  221. @url{http://engene.se/ffmpeg_watermark.gif}
  222. MODE 1:
  223. Per color do this:
  224. If mask color > threshold color then the watermark pixel is used.
  225. Example usage:
  226. @example
  227. ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif' -an out.mov
  228. ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif -m 1 -t 222222' -an out.mov
  229. @end example
  230. @bye