wp_read_video_metadata( string $file ): array|false
- Since
- 3.6.0
- Source
wp-admin/includes/media.php:3573
Compatibility
- WordPress
- since 3.6.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$filestring- Path to file.
Return value
array|false- Returns array of metadata, if found.
Performance profile
How much work a call to wp_read_video_metadata() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 73–122
- Plugin surface
- 1 hook
- Called by
- 1
Reads or writes the filesystem via file_exists().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 155.
Third-party callbacks on 'wp_read_video_metadata' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - filesystemfilesystem access
file_exists()called directly
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_read_video_metadata() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
file_exists() && defined('GETID3_TEMP_DIR') && !isset($value) && empty($value) && empty($data) && !empty($metadata) | 73–107 | file_exists(), ->analyze(), wp_add_id3_tag_data(), apply_filters() |
file_exists() && defined('GETID3_TEMP_DIR') && !isset($value) && empty($value) && empty($data) && empty($metadata) | 79–115 | file_exists(), ->analyze(), wp_get_media_creation_timestamp(), wp_add_id3_tag_data(), apply_filters() |
file_exists() && defined('GETID3_TEMP_DIR') && !isset($value) && empty($value) && !empty($metadata) | 80–114 | file_exists(), ->analyze(), round(), wp_add_id3_tag_data(), apply_filters() |
file_exists() && defined('GETID3_TEMP_DIR') && !isset($value) && empty($value) && empty($metadata) | 86–122 | file_exists(), ->analyze(), round(), wp_get_media_creation_timestamp(), wp_add_id3_tag_data(), apply_filters() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 155 | 73–122 | 20 | |
| 8.5 | 155 | 73–122 | 20 | |
| 8.4 | 155 | 73–122 | 20 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 158 | 76–125 | 20 | |
| 8.2 | 158 | 76–125 | 20 | |
| 8.1 | 158 | 76–125 | 20 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 159 | 76–126 | 20 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_read_video_metadata() runs, in this order:
- apply_filters( wp_read_video_metadata )filterline 3677 (+104 into the body)
Filters the array of metadata retrieved from a video.
Uses · 5
- get_temp_dir()Determines a writable directory for temporary files.
- wp_get_media_creation_timestamp()Parses creation date from media metadata.
- wp_add_id3_tag_data()Parses ID3v2, ID3v1, and getID3 comments to extract usable data.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- getID3::__construct()
Used by · 1
- wp_generate_attachment_metadata()Generates attachment meta data and create image sub-sizes for images.
Source code
function wp_read_video_metadata( $file ) { if ( ! file_exists( $file ) ) { return false; } $metadata = array(); if ( ! defined( 'GETID3_TEMP_DIR' ) ) { define( 'GETID3_TEMP_DIR', get_temp_dir() ); } if ( ! class_exists( 'getID3', false ) ) { require ABSPATH . WPINC . '/ID3/getid3.php'; } $id3 = new getID3(); // Required to get the `created_timestamp` value. $id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName $data = $id3->analyze( $file ); if ( isset( $data['video']['lossless'] ) ) { $metadata['lossless'] = $data['video']['lossless']; } if ( ! empty( $data['video']['bitrate'] ) ) { $metadata['bitrate'] = (int) $data['video']['bitrate']; } if ( ! empty( $data['video']['bitrate_mode'] ) ) { $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; } if ( ! empty( $data['filesize'] ) ) { $metadata['filesize'] = (int) $data['filesize']; } if ( ! empty( $data['mime_type'] ) ) { $metadata['mime_type'] = $data['mime_type']; } if ( ! empty( $data['playtime_seconds'] ) ) { $metadata['length'] = (int) round( $data['playtime_seconds'] ); } if ( ! empty( $data['playtime_string'] ) ) { $metadata['length_formatted'] = $data['playtime_string']; } if ( ! empty( $data['video']['resolution_x'] ) ) { $metadata['width'] = (int) $data['video']['resolution_x']; } if ( ! empty( $data['video']['resolution_y'] ) ) { $metadata['height'] = (int) $data['video']['resolution_y']; } if ( ! empty( $data['fileformat'] ) ) { $metadata['fileformat'] = $data['fileformat']; } if ( ! empty( $data['video']['dataformat'] ) ) { $metadata['dataformat'] = $data['video']['dataformat']; } if ( ! empty( $data['video']['encoder'] ) ) { $metadata['encoder'] = $data['video']['encoder']; } if ( ! empty( $data['video']['codec'] ) ) { $metadata['codec'] = $data['video']['codec']; } if ( ! empty( $data['audio'] ) ) { unset( $data['audio']['streams'] ); $metadata['audio'] = $data['audio']; } if ( empty( $metadata['created_timestamp'] ) ) { $created_timestamp = wp_get_media_creation_timestamp( $data );Changelog
Introduced in 3.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/media.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.