wp_read_video_metadata

Retrieve metadata from a video file's ID3 tags.

Description

(array|bool) wp_read_video_metadata( (string) $file ); 

Returns (array|bool)

Returns array of metadata, if found.

Parameters (1)

0. $file (string)
Path to file.

Usage

  1. if ( !function_exists( 'wp_read_video_metadata' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // Path to file. 
  5. $file = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_read_video_metadata($file); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function wp_read_video_metadata( $file ) { 
  2. if ( ! file_exists( $file ) ) { 
  3. return false; 
  4.  
  5. $metadata = array(); 
  6.  
  7. if ( ! defined( 'GETID3_TEMP_DIR' ) ) { 
  8. define( 'GETID3_TEMP_DIR', get_temp_dir() ); 
  9.  
  10. if ( ! class_exists( 'getID3', false ) ) { 
  11. require( ABSPATH . WPINC . '/ID3/getid3.php' ); 
  12. $id3 = new getID3(); 
  13. $data = $id3->analyze( $file ); 
  14.  
  15. if ( isset( $data['video']['lossless'] ) ) 
  16. $metadata['lossless'] = $data['video']['lossless']; 
  17. if ( ! empty( $data['video']['bitrate'] ) ) 
  18. $metadata['bitrate'] = (int) $data['video']['bitrate']; 
  19. if ( ! empty( $data['video']['bitrate_mode'] ) ) 
  20. $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; 
  21. if ( ! empty( $data['filesize'] ) ) 
  22. $metadata['filesize'] = (int) $data['filesize']; 
  23. if ( ! empty( $data['mime_type'] ) ) 
  24. $metadata['mime_type'] = $data['mime_type']; 
  25. if ( ! empty( $data['playtime_seconds'] ) ) 
  26. $metadata['length'] = (int) round( $data['playtime_seconds'] ); 
  27. if ( ! empty( $data['playtime_string'] ) ) 
  28. $metadata['length_formatted'] = $data['playtime_string']; 
  29. if ( ! empty( $data['video']['resolution_x'] ) ) 
  30. $metadata['width'] = (int) $data['video']['resolution_x']; 
  31. if ( ! empty( $data['video']['resolution_y'] ) ) 
  32. $metadata['height'] = (int) $data['video']['resolution_y']; 
  33. if ( ! empty( $data['fileformat'] ) ) 
  34. $metadata['fileformat'] = $data['fileformat']; 
  35. if ( ! empty( $data['video']['dataformat'] ) ) 
  36. $metadata['dataformat'] = $data['video']['dataformat']; 
  37. if ( ! empty( $data['video']['encoder'] ) ) 
  38. $metadata['encoder'] = $data['video']['encoder']; 
  39. if ( ! empty( $data['video']['codec'] ) ) 
  40. $metadata['codec'] = $data['video']['codec']; 
  41.  
  42. if ( ! empty( $data['audio'] ) ) { 
  43. unset( $data['audio']['streams'] ); 
  44. $metadata['audio'] = $data['audio']; 
  45.  
  46. wp_add_id3_tag_data( $metadata, $data ); 
  47.  
  48. return $metadata;