index.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. Presentation
  2. ============
  3. MediaVorus is a small PHP library wich provide a set of tools to extract every
  4. technical information from multimedia files.
  5. Example
  6. -------
  7. .. code-block:: php
  8. <?php
  9. use MediaVorus\MediaVorus;
  10. use MediaVorus\MediaVorus;
  11. use MediaVorus\Media\Image;
  12. $mediavorus = MediaVorus::create();
  13. $Media = $mediavorus->guess('tests/files/CanonRaw.CR2');
  14. if($Media instanceof Image)
  15. {
  16. echo sprintf("Image was taken with a %f shutter speed", $Media->getShutterSpeed());
  17. }
  18. Goals
  19. -----
  20. MediaVorus is a small PHP library wich provide a set of tools to deal with
  21. multimedia files.
  22. The aim is to provide an abstract layer between the program and the multimedia
  23. file.
  24. First, the need is to analyze multimedia files and get their properties.
  25. In a very next future, we would add metadata mapper to handle various
  26. configurations.
  27. API
  28. ===
  29. Guesser
  30. -------
  31. .. code-block:: php
  32. <?php
  33. use MediaVorus\MediaVorus;
  34. $Media = MediaVorus::guess('tests/files/ExifTool.jpg');
  35. //Returns a \Doctrine\Common\Collections\ArrayCollection of Medias
  36. $MediaCollection = MediaVorus::inspectDirectory($dir, $recursive);
  37. Medias
  38. ------
  39. Media\\DefaultMedia
  40. *******************
  41. Default Media is the Default container.
  42. This object provides GPS informations :
  43. .. code-block:: php
  44. <?php
  45. use MediaVorus\MediaVorus;
  46. use MediaVorus\Media;
  47. $Media = MediaVorus::guess('somefile.smf');
  48. if($Media instanceof Media\DefaultMedia)
  49. {
  50. /**
  51. * Returns the longitude as a described above
  52. */
  53. $Media->getLongitude();
  54. /**
  55. * Returns the longitude as a described above
  56. */
  57. $Media->getLatitude();
  58. /**
  59. * Returns Longitude reference (West or East) and equals to one of the
  60. * Media\DefaultMedia::GPSREF_LONGITUDE_* constants
  61. */
  62. $Media->getLongitudeRef();
  63. /**
  64. * Returns Latitude reference (North or South) and equals to one of the
  65. * Media\DefaultMedia::GPSREF_LATITUDE_* constants
  66. */
  67. $Media->getLatitudeRef();
  68. }
  69. Media\\Image
  70. ************
  71. Media Image extends the default media.
  72. It has much more methods and provides the following informations :
  73. .. code-block:: php
  74. <?php
  75. use MediaVorus\MediaVorus;
  76. use MediaVorus\Media;
  77. $Media = MediaVorus::guess('tests/files/ExifTool.jpg');
  78. if($Media instanceof Media\Image)
  79. {
  80. /**
  81. * It extends the DefaultMedia
  82. */
  83. assert($Media instanceof Media\DefaultMedia);
  84. /**
  85. * Returns the width (int)
  86. */
  87. $Media->getWidth();
  88. /**
  89. * Returns the height (int)
  90. */
  91. $Media->getHeight();
  92. /**
  93. * Returns the number of channels (int)
  94. */
  95. $Media->getChannels();
  96. /**
  97. * Returns the focal length (string), not parsed
  98. */
  99. $Media->getFocalLength();
  100. /**
  101. * Returns the color depth in bits (int)
  102. */
  103. $Media->getColorDepth();
  104. /**
  105. * Returns the camera model name (string)
  106. */
  107. $Media->getCameraModel();
  108. /**
  109. * Returns true if the flash has been fired (bool)
  110. */
  111. $Media->getFlashFired();
  112. /**
  113. * Returns the aperture (string), not parsed
  114. */
  115. $Media->getAperture();
  116. /**
  117. * Returns the shutter speed (string), not parsed
  118. */
  119. $Media->getShutterSpeed();
  120. /**
  121. * Returns the orientation (string), one of the Media\Image::ORIENTATION_*
  122. */
  123. $Media->getOrientation();
  124. /**
  125. * Returns the date when the photos has been taken (string), not parsed
  126. */
  127. $Media->getCreationDate();
  128. /**
  129. * Returns the hyperfocal distance (string), not parsed
  130. */
  131. $Media->getHyperfocalDistance();
  132. /**
  133. * Returns the ISO value (int)
  134. */
  135. $Media->getISO();
  136. /**
  137. * Returns the light value (string), not parsed
  138. */
  139. $Media->getLightValue();
  140. }
  141. Media serialization
  142. -------------------
  143. All medias are serializable with `JMS Serializer <http://jmsyst.com/libs/serializer>`_.
  144. For example :
  145. .. code-block:: php
  146. <?php
  147. use Doctrine\Common\Annotations\AnnotationRegistry;
  148. use JMS\Serializer\SerializerBuilder;
  149. use MediaVorus\MediaVorus;
  150. AnnotationRegistry::registerAutoloadNamespace(
  151. 'JMS\Serializer\Annotation', __DIR__.'/vendor/jms/serializer/src'
  152. );
  153. $serializer = SerializerBuilder::create()
  154. ->setCacheDir(__DIR__ . '/cache')
  155. ->build();
  156. $mediavorus = MediaVorus::create();
  157. print($serializer->serialize($mediavorus->guess('image.jpg'), 'json'));
  158. would result in the following output :
  159. .. code-block:: json
  160. {
  161. "type": "Image",
  162. "raw_image": false,
  163. "multiple_layers": false,
  164. "width": 3264,
  165. "height": 2448,
  166. "channels": 3,
  167. "focal_length": 4.28,
  168. "color_depth": 8,
  169. "camera_model": "iPhone 4S",
  170. "flash_fired": false,
  171. "aperture": 2.4,
  172. "shutter_speed": 0.05,
  173. "orientation": 90,
  174. "creation_date": "2012:03:16 16:29:09",
  175. "hyperfocal_distance": 2.0773522348635,
  176. "ISO": 400,
  177. "light_value": 4.847996906555,
  178. "color_space": "RGB"
  179. }
  180. Silex Service Provider
  181. ----------------------
  182. MediaVorus comes bundled with its `Silex Service Provider <silex.sensiolabs.org>`_.
  183. As MediaVorus relies on `PHP-Exiftool <https://github.com/romainneutron/PHPExiftool>`_
  184. and `FFProbe <http://ffmpeg-php.readthedocs.org/>`_, you'll have to register
  185. both bundles to use it :
  186. .. code-block:: php
  187. <?php
  188. use FFMpeg\FFMpegServiceProvider;
  189. use MediaVorus\MediaVorusServiceProvider;
  190. use PHPExiftool\PHPExiftoolServiceProvider;
  191. use Silex\Application;
  192. $app = new Application();
  193. $app->register(new MediaVorusServiceProvider());
  194. $app->register(new PHPExiftoolServiceProvider());
  195. $app->register(new FFMpegServiceProvider());
  196. // you will now have access to $app['mediavorus']
  197. $video = $app['mediavorus']->guess('/path/to/video/file');
  198. .. toctree::
  199. :maxdepth: 1
  200. API
  201. UseCases