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.

261 lines
9.8KB

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