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.

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