Get Metadata from WordPress Video and Audio files
In addition to images, videos and audio files are other formats that we can upload to WordPress and make them accessible to users. Depending on the use case, it may be useful to get certain metadata from video or audio files to show more details for the user.
How can I get Metadata from a video file?
WordPress has an own wp_read_video_metadata() function that will help us in this case. However, this feature is only available in the WordPress backend by default. To get the video metadata on the frontend we create a small wrapper function.
First, we need the URL to the video file. This could e.g. “https://domain.com/video.mp4”. We can use a helper function to get metadata from WordPress videos like the following example:
IMPORTANT: To work with the above function, we need an additional function called
wordpress_get_full_path_of_url(); which you find in the following article:
Which video metadata can we get?
The following example shows which metadata can be included in a video file in WordPress. However, a video does not always have to contain all of this data. Sometimes only a small amount of data is available. It depends on the file and how it was created and compressed.
How I can get Audio file metadata in WordPress?
WordPress already has an own wp_read_audio_metadata() function to get audio metadata. By default this feature is only available in the WordPress backend. So, in this case we also build a small wrapper function.
IMPORTANT: We also need to include the
wordpress_get_full_path_of_url() function to get metadata from audio files in WordPress. To get this function, read the following article:
Which audio data can we get from a file?
To start we need the URL to the audio file. This could e.g. “https://domain.com/audio.mp3” be. With the helper function, we use from the example above, we can get the following metadata from WordPress audio files.