README.mux 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. __ __ ____ ____ ____ __ __ _ __ __
  2. / \\/ \/ _ \/ _ \/ _ \/ \ \/ \___/_ / _\
  3. \ / __/ _ \ __/ / / (_/ /__
  4. \__\__/\_____/_____/__/ \__//_/\_____/__/___/v1.2.2
  5. Description:
  6. ============
  7. WebPMux: set of two libraries 'Mux' and 'Demux' for creation, extraction and
  8. manipulation of an extended format WebP file, which can have features like
  9. color profile, metadata and animation. Reference command-line tools 'webpmux'
  10. and 'vwebp' as well as the WebP container specification
  11. 'doc/webp-container-spec.txt' are also provided in this package.
  12. WebP Mux tool:
  13. ==============
  14. The examples/ directory contains a tool (webpmux) for manipulating WebP
  15. files. The webpmux tool can be used to create an extended format WebP file and
  16. also to extract or strip relevant data from such a file.
  17. A list of options is available using the -help command line flag:
  18. > webpmux -help
  19. Usage: webpmux -get GET_OPTIONS INPUT -o OUTPUT
  20. webpmux -set SET_OPTIONS INPUT -o OUTPUT
  21. webpmux -duration DURATION_OPTIONS [-duration ...]
  22. INPUT -o OUTPUT
  23. webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT
  24. webpmux -frame FRAME_OPTIONS [-frame...] [-loop LOOP_COUNT]
  25. [-bgcolor BACKGROUND_COLOR] -o OUTPUT
  26. webpmux -info INPUT
  27. webpmux [-h|-help]
  28. webpmux -version
  29. webpmux argument_file_name
  30. GET_OPTIONS:
  31. Extract relevant data:
  32. icc get ICC profile
  33. exif get EXIF metadata
  34. xmp get XMP metadata
  35. frame n get nth frame
  36. SET_OPTIONS:
  37. Set color profile/metadata/parameters:
  38. loop LOOP_COUNT set the loop count
  39. bgcolor BACKGROUND_COLOR set the animation background color
  40. icc file.icc set ICC profile
  41. exif file.exif set EXIF metadata
  42. xmp file.xmp set XMP metadata
  43. where: 'file.icc' contains the ICC profile to be set,
  44. 'file.exif' contains the EXIF metadata to be set
  45. 'file.xmp' contains the XMP metadata to be set
  46. DURATION_OPTIONS:
  47. Set duration of selected frames:
  48. duration set duration for each frames
  49. duration,frame set duration of a particular frame
  50. duration,start,end set duration of frames in the
  51. interval [start,end])
  52. where: 'duration' is the duration in milliseconds
  53. 'start' is the start frame index
  54. 'end' is the inclusive end frame index
  55. The special 'end' value '0' means: last frame.
  56. STRIP_OPTIONS:
  57. Strip color profile/metadata:
  58. icc strip ICC profile
  59. exif strip EXIF metadata
  60. xmp strip XMP metadata
  61. FRAME_OPTIONS(i):
  62. Create animation:
  63. file_i +di+[xi+yi[+mi[bi]]]
  64. where: 'file_i' is the i'th animation frame (WebP format),
  65. 'di' is the pause duration before next frame,
  66. 'xi','yi' specify the image offset for this frame,
  67. 'mi' is the dispose method for this frame (0 or 1),
  68. 'bi' is the blending method for this frame (+b or -b)
  69. LOOP_COUNT:
  70. Number of times to repeat the animation.
  71. Valid range is 0 to 65535 [Default: 0 (infinite)].
  72. BACKGROUND_COLOR:
  73. Background color of the canvas.
  74. A,R,G,B
  75. where: 'A', 'R', 'G' and 'B' are integers in the range 0 to 255 specifying
  76. the Alpha, Red, Green and Blue component values respectively
  77. [Default: 255,255,255,255]
  78. INPUT & OUTPUT are in WebP format.
  79. Note: The nature of EXIF, XMP and ICC data is not checked and is assumed to be
  80. valid.
  81. Note: if a single file name is passed as the argument, the arguments will be
  82. tokenized from this file. The file name must not start with the character '-'.
  83. Visualization tool:
  84. ===================
  85. The examples/ directory also contains a tool (vwebp) for viewing WebP files.
  86. It decodes the image and visualizes it using OpenGL. See the libwebp README
  87. for details on building and running this program.
  88. Mux API:
  89. ========
  90. The Mux API contains methods for adding data to and reading data from WebP
  91. files. This API currently supports XMP/EXIF metadata, ICC profile and animation.
  92. Other features may be added in subsequent releases.
  93. Example#1 (pseudo code): Creating a WebPMux object with image data, color
  94. profile and XMP metadata.
  95. int copy_data = 0;
  96. WebPMux* mux = WebPMuxNew();
  97. // ... (Prepare image data).
  98. WebPMuxSetImage(mux, &image, copy_data);
  99. // ... (Prepare ICC profile data).
  100. WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data);
  101. // ... (Prepare XMP metadata).
  102. WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data);
  103. // Get data from mux in WebP RIFF format.
  104. WebPMuxAssemble(mux, &output_data);
  105. WebPMuxDelete(mux);
  106. // ... (Consume output_data; e.g. write output_data.bytes to file).
  107. WebPDataClear(&output_data);
  108. Example#2 (pseudo code): Get image and color profile data from a WebP file.
  109. int copy_data = 0;
  110. // ... (Read data from file).
  111. WebPMux* mux = WebPMuxCreate(&data, copy_data);
  112. WebPMuxGetFrame(mux, 1, &image);
  113. // ... (Consume image; e.g. call WebPDecode() to decode the data).
  114. WebPMuxGetChunk(mux, "ICCP", &icc_profile);
  115. // ... (Consume icc_profile).
  116. WebPMuxDelete(mux);
  117. free(data);
  118. For a detailed Mux API reference, please refer to the header file
  119. (src/webp/mux.h).
  120. Demux API:
  121. ==========
  122. The Demux API enables extraction of images and extended format data from
  123. WebP files. This API currently supports reading of XMP/EXIF metadata, ICC
  124. profile and animated images. Other features may be added in subsequent
  125. releases.
  126. Code example: Demuxing WebP data to extract all the frames, ICC profile
  127. and EXIF/XMP metadata.
  128. WebPDemuxer* demux = WebPDemux(&webp_data);
  129. uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
  130. uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
  131. // ... (Get information about the features present in the WebP file).
  132. uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS);
  133. // ... (Iterate over all frames).
  134. WebPIterator iter;
  135. if (WebPDemuxGetFrame(demux, 1, &iter)) {
  136. do {
  137. // ... (Consume 'iter'; e.g. Decode 'iter.fragment' with WebPDecode(),
  138. // ... and get other frame properties like width, height, offsets etc.
  139. // ... see 'struct WebPIterator' below for more info).
  140. } while (WebPDemuxNextFrame(&iter));
  141. WebPDemuxReleaseIterator(&iter);
  142. }
  143. // ... (Extract metadata).
  144. WebPChunkIterator chunk_iter;
  145. if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter);
  146. // ... (Consume the ICC profile in 'chunk_iter.chunk').
  147. WebPDemuxReleaseChunkIterator(&chunk_iter);
  148. if (flags & EXIF_FLAG) WebPDemuxGetChunk(demux, "EXIF", 1, &chunk_iter);
  149. // ... (Consume the EXIF metadata in 'chunk_iter.chunk').
  150. WebPDemuxReleaseChunkIterator(&chunk_iter);
  151. if (flags & XMP_FLAG) WebPDemuxGetChunk(demux, "XMP ", 1, &chunk_iter);
  152. // ... (Consume the XMP metadata in 'chunk_iter.chunk').
  153. WebPDemuxReleaseChunkIterator(&chunk_iter);
  154. WebPDemuxDelete(demux);
  155. For a detailed Demux API reference, please refer to the header file
  156. (src/webp/demux.h).
  157. AnimEncoder API:
  158. ================
  159. The AnimEncoder API can be used to create animated WebP images.
  160. Code example:
  161. WebPAnimEncoderOptions enc_options;
  162. WebPAnimEncoderOptionsInit(&enc_options);
  163. // ... (Tune 'enc_options' as needed).
  164. WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options);
  165. while(<there are more frames>) {
  166. WebPConfig config;
  167. WebPConfigInit(&config);
  168. // ... (Tune 'config' as needed).
  169. WebPAnimEncoderAdd(enc, frame, duration, &config);
  170. }
  171. WebPAnimEncoderAssemble(enc, webp_data);
  172. WebPAnimEncoderDelete(enc);
  173. // ... (Write the 'webp_data' to a file, or re-mux it further).
  174. For a detailed AnimEncoder API reference, please refer to the header file
  175. (src/webp/mux.h).
  176. AnimDecoder API:
  177. ================
  178. This AnimDecoder API allows decoding (possibly) animated WebP images.
  179. Code Example:
  180. WebPAnimDecoderOptions dec_options;
  181. WebPAnimDecoderOptionsInit(&dec_options);
  182. // Tune 'dec_options' as needed.
  183. WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options);
  184. WebPAnimInfo anim_info;
  185. WebPAnimDecoderGetInfo(dec, &anim_info);
  186. for (uint32_t i = 0; i < anim_info.loop_count; ++i) {
  187. while (WebPAnimDecoderHasMoreFrames(dec)) {
  188. uint8_t* buf;
  189. int timestamp;
  190. WebPAnimDecoderGetNext(dec, &buf, &timestamp);
  191. // ... (Render 'buf' based on 'timestamp').
  192. // ... (Do NOT free 'buf', as it is owned by 'dec').
  193. }
  194. WebPAnimDecoderReset(dec);
  195. }
  196. const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec);
  197. // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data).
  198. WebPAnimDecoderDelete(dec);
  199. For a detailed AnimDecoder API reference, please refer to the header file
  200. (src/webp/demux.h).
  201. Bugs:
  202. =====
  203. Please report all bugs to the issue tracker:
  204. https://bugs.chromium.org/p/webp
  205. Patches welcome! See this page to get started:
  206. https://www.webmproject.org/code/contribute/submitting-patches/
  207. Discuss:
  208. ========
  209. Email: webp-discuss@webmproject.org
  210. Web: https://groups.google.com/a/webmproject.org/group/webp-discuss