README.adoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. = audiowmark - Audio Watermarking
  2. == Description
  3. `audiowmark` is an Open Source solution for audio watermarking. It is
  4. distributed under the terms of the GNU General Public License. A sound file is
  5. read by the software, and a 128-bit message is stored in a watermark in the
  6. output sound file. For human listeners, the files typically sound the same.
  7. However, the 128-bit message can be retrieved from the output sound file. Our
  8. tests show, that even if the file is converted to mp3 or ogg (with bitrate 128
  9. kbit/s or higher), the watermark usually can be retrieved without problems. The
  10. process of retrieving the message does not need the original audio file (blind
  11. decoding).
  12. Internally, audiowmark is using the patchwork algorithm to hide the data in the
  13. spectrum of the audio file. The signal is split into 1024 sample frames. For
  14. each frame, some pseoudo-randomly selected amplitudes of the frequency bands of
  15. a 1024-value FFTs are increased or decreased slightly, which can be detected
  16. later. The algorithm used here is inspired by
  17. Martin Steinebach: Digitale Wasserzeichen für Audiodaten.
  18. Darmstadt University of Technology 2004, ISBN 3-8322-2507-2
  19. == Adding a Watermark
  20. To add a watermark to the soundfile in.wav with a 128-bit message (which is
  21. specified as hex-string):
  22. [subs=+quotes]
  23. ....
  24. *$ audiowmark add in.wav out.wav 0123456789abcdef0011223344556677*
  25. Input: in.wav
  26. Output: out.wav
  27. Message: 0123456789abcdef0011223344556677
  28. Strength: 10
  29. Time: 3:59
  30. Sample Rate: 48000
  31. Channels: 2
  32. Data Blocks: 4
  33. Volume Norm: 0.987 (-0.12 dB)
  34. ....
  35. The most important options for adding a watermark are:
  36. --key <filename>::
  37. Use watermarking key from file <filename> (see <<key>>).
  38. --strength <s>::
  39. Set the watermarking strength (see <<strength>>).
  40. == Retrieving a Watermark
  41. To get the 128-bit message from the watermarked file, use:
  42. [subs=+quotes]
  43. ....
  44. *$ audiowmark get out.wav*
  45. pattern 0:05 0123456789abcdef0011223344556677 1.324 0.059 A
  46. pattern 0:57 0123456789abcdef0011223344556677 1.413 0.112 B
  47. pattern 0:57 0123456789abcdef0011223344556677 1.368 0.086 AB
  48. pattern 1:49 0123456789abcdef0011223344556677 1.302 0.098 A
  49. pattern 2:40 0123456789abcdef0011223344556677 1.361 0.093 B
  50. pattern 2:40 0123456789abcdef0011223344556677 1.331 0.096 AB
  51. pattern all 0123456789abcdef0011223344556677 1.350 0.054
  52. ....
  53. The output of `audiowmark get` is designed to be machine readable. Each line
  54. that starts with `pattern` contains one decoded message. The fields are
  55. seperated by one or more space characters. The first field is a *timestamp*
  56. indicating the position of the data block. The second field is the *decoded
  57. message*. For most purposes this is all you need to know.
  58. The software was designed under the assumption that you - the user - will be
  59. able to decide whether a message is correct or not. To do this, on watermarking
  60. song files, you could list each message you embedded in a database. During
  61. retrieval, you should look up each pattern `audiowmark get` outputs in the
  62. database. If the message is not found, then you should assume that a decoding
  63. error occurred. In our example each pattern was decoded correctly, because
  64. the watermark was not damaged at all, but if you for instance use lossy
  65. compression (with a low bitrate), it may happen that only some of the decoded
  66. patterns are correct. Or none, if the watermark was damaged too much.
  67. The third field is the *sync score* (higher is better). The synchronization
  68. algorithm tries to find valid data blocks in the audio file, that become
  69. candidates for decoding.
  70. The fourth field is the *decoding error* (lower is better). During message
  71. decoding, we use convolutional codes for error correction, to make the
  72. watermarking more robust.
  73. The fifth field is the *block type*. There are two types of data blocks,
  74. A blocks and B blocks. A single data block can be decoded alone, as it
  75. contains a complete message. However, if during watermark detection an
  76. A block followed by a B block was found, these two can be decoded
  77. together (then this field will be AB), resulting in even higher error
  78. correction capacity than one block alone would have.
  79. To improve the error correction capacity even further, the `all` pattern
  80. combines all data blocks that are available. The combined decoded
  81. message will often be the most reliable result (meaning that even if all
  82. other patterns were incorrect, this could still be right).
  83. The most important options for getting a watermark are:
  84. --key <filename>::
  85. Use watermarking key from file <filename> (see <<key>>).
  86. --strength <s>::
  87. Set the watermarking strength (see <<strength>>).
  88. [[key]]
  89. == Watermark Key
  90. Since the software is Open Source, a watermarking key should be used to ensure
  91. that the message bits cannot be retrieved by somebody else (which would also
  92. allow removing the watermark without loss of quality). The watermark key
  93. controls all pseudo-random parameters of the algorithm. This means that
  94. it determines which frequency bands are increased or decreased to store a
  95. 0 bit or a 1 bit. Without the key, it is impossible to decode the message
  96. bits from the audio file alone.
  97. Our watermarking key is a 128-bit AES key. A key can be generated using
  98. audiowmark gen-key test.key
  99. and can be used for the add/get commands as follows:
  100. audiowmark add --key test.key in.wav out.wav 0123456789abcdef0011223344556677
  101. audiowmark get --key test.key out.wav
  102. [[strength]]
  103. == Watermark Strength
  104. The watermark strength parameter affects how much the watermarking algorithm
  105. modifies the input signal. A stronger watermark is more audible, but also more
  106. robust against modifications. The default strength is 10. A watermark with that
  107. strength is recoverable after mp3/ogg encoding with 128kbit/s or higher. In our
  108. informal listening tests, this setting also has a very good subjective quality.
  109. A higher strength (for instance 15) would be helpful for instance if robustness
  110. against multiple conversions or conversions to low bit rates (i.e. 64kbit/s) is
  111. desired.
  112. A lower strength (for instance 6) makes the watermark less audible, but also
  113. less robust. Strengths below 5 are not recommended. To set the strength, the
  114. same value has to be passed during both, generation and retrieving the
  115. watermark. Fractional strengths (like 7.5) are possible.
  116. audiowmark add --strength 15 in.wav out.wav 0123456789abcdef0011223344556677
  117. audiowmark get --strength 15 out.wav
  118. == Output as Stream
  119. Usually, an input file is read, watermarked and an output file is written.
  120. This means that it takes some time before the watermarked file can be used.
  121. An alternative is to output the watermarked file as stream to stdout. One use
  122. case is sending the watermarked file to a user via network while the
  123. watermarker is still working on the rest of the file. Here is an example how to
  124. watermark a wav file to stdout:
  125. audiowmark add in.wav - 0123456789abcdef0011223344556677 | play -
  126. In this case the file in.wav is read, watermarked, and the output is sent
  127. to stdout. The "play -" can start playing the watermarked stream while the
  128. rest of the file is being watermarked.
  129. If - is used as output, the output is a valid .wav file, so the programs
  130. running after `audiowmark` will be able to determine sample rate, number of
  131. channels, bit depth, encoding and so on from the wav header.
  132. Note that all input formats supported by audiowmark can be used in this way,
  133. for instance flac/mp3:
  134. audiowmark add in.flac - 0123456789abcdef0011223344556677 | play -
  135. audiowmark add in.mp3 - 0123456789abcdef0011223344556677 | play -
  136. == Input from Stream
  137. Similar to the output, the `audiowmark` input can be a stream. In this case,
  138. the input must be a valid .wav file. The watermarker will be able to
  139. start watermarking the input stream before all data is available. An
  140. example would be:
  141. cat in.wav | audiowmark add - out.wav 0123456789abcdef0011223344556677
  142. It is possible to do both, input from stream and output as stream.
  143. cat in.wav | audiowmark add - - 0123456789abcdef0011223344556677 | play -
  144. Streaming input is also supported for watermark detection.
  145. cat in.wav | audiowmark get -
  146. == Raw Streams
  147. So far, all streams described here are essentially wav streams, which means
  148. that the wav header allows `audiowmark` to determine sample rate, number of
  149. channels, bit depth, encoding and so forth from the stream itself, and the a
  150. wav header is written for the program after `audiowmark`, so that this can
  151. figure out the parameters of the stream.
  152. There are two cases where this is problematic. The first case is if the full
  153. length of the stream is not known at the time processing starts. Then a wav
  154. header cannot be used, as the wav file contains the length of the stream. The
  155. second case is that the program before or after `audiowmark` doesn't support wav
  156. headers.
  157. For these two cases, raw streams are available. The idea is to set all
  158. information that is needed like sample rate, number of channels,... manually.
  159. Then, headerless data can be processed from stdin and/or sent to stdout.
  160. --input-format raw::
  161. --output-format raw::
  162. --format raw::
  163. These can be used to set the input format or output format to raw. The
  164. last version sets both, input and output format to raw.
  165. --raw-rate <rate>::
  166. This should be used to set the sample rate. The input sample rate and
  167. the output sample rate will always be the same (no resampling is
  168. done by the watermarker). There is no default for the sampling rate,
  169. so this parameter must always be specified for raw streams.
  170. --raw-input-bits <bits>::
  171. --raw-output-bits <bits>::
  172. --raw-bits <bits>::
  173. The options can be used to set the input number of bits, the output number
  174. of bits or both. The number of bits can either be `16` or `24`. The default
  175. number of bits is `16`.
  176. --raw-input-endian <endian>::
  177. --raw-output-endian <endian>::
  178. --raw-endian <endian>::
  179. These options can be used to set the input/output endianness or both.
  180. The <endian> parameter can either be `little` or `big`. The default
  181. endianness is `little`.
  182. --raw-input-encoding <encoding>::
  183. --raw-output-encoding <encoding>::
  184. --raw-encoding <encoding>::
  185. These options can be used to set the input/output encoding or both.
  186. The <encoding> parameter can either be `signed` or `unsigned`. The
  187. default encoding is `signed`.
  188. --raw-channels <channels>::
  189. This can be used to set the number of channels. Note that the number
  190. of input channels and the number of output channels must always be the
  191. same. The watermarker has been designed and tested for stereo files,
  192. so the number of channels should really be `2`. This is also the
  193. default.
  194. == Dependencies
  195. If you compile from source, `audiowmark` needs the following libraries:
  196. * libfftw3
  197. * libsndfile
  198. * libgcrypt
  199. * libzita-resampler
  200. * libmpg123
  201. == Building fftw
  202. `audiowmark` needs the single prevision variant of fftw3.
  203. If you are building fftw3 from source, use the `--enable-float`
  204. configure parameter to build it, e.g.::
  205. cd ${FFTW3_SOURCE}
  206. ./configure --enable-float --enable-sse && \
  207. make && \
  208. sudo make install
  209. or, when building from git
  210. cd ${FFTW3_GIT}
  211. ./bootstrap.sh --enable-shared --enable-sse --enable-float && \
  212. make && \
  213. sudo make install
  214. == Docker Build
  215. You should be able to execute `audiowmark` via Docker.
  216. Example that outputs the usage message:
  217. docker build -t audiowmark .
  218. docker run -v <local-data-directory>:/data -it audiowmark -h