when attaching videos (eg. .flv) to a post - is it possible to query its dimensions? the problem is - i've got videos in 4:3 and 16:9 format and i need to get this information.

any ideas?


  • Do you upload the videos yourself or do you embed them from other sites? Which sites then? – Jan Fabry Mar 24 '11 at 19:35

php-flvinfo and php-mp4info are php classes for reading flv and mp4 metadata. you could read it on the fly, or it may be possible to hook a save to get this info in the db somewhere.

|improve this answer|||||

This is how I retrieve video (or any non-image) meta data.

// assuming you have an attachment ID
$meta = wp_get_attachment_metadata( $attachment->ID );

// See what meta data is available
print_r( $meta );

// always check for the property's existence before trying to display it
if ( ! empty( $meta['width'] ) )
 echo $meta['width'];

You can echo any meta that is returned with print. Hope it helps someone.

|improve this answer|||||
  • Please add proper description to why your code would work, and how your code work. Just dropping code as an answer is not allowed – Pieter Goosen May 2 '14 at 15:29
  • The code I have shared was already commented inline, but I edited my response to include some additional information. Why the downvote though? :) – mightypixel May 4 '14 at 17:44

You would need a plugin to do this. It would need to parse the video and save the meta information.

I'd recommend taking a look at this library for starters: http://code.google.com/p/flv4php/

As for implementing this as a WordPress plugin, you would need to write a function and hook it to the wp_generate_attachment_metadata filter. The code will basically look something like this:

function my_attachment_metadata($meta, $attachment_id) {
  $attachment = get_post( $attachment_id );
  $mime = get_post_mime_type( $attachment );
  $file = get_attached_file( $attachment_id );
  // use the $mime value to determine if you need to scan the file (video/x-flv)
  // use the $file for scanning for any meta data
  // store the meta data in $meta['whatever'] for each piece of info
  return $meta;

Any meta data you add to $meta and return there will be stored along with the attachment post. You can then later retrieve it, without having to reparse the file or anything, with wp_get_attachment_metadata( $attachment_id ).

|improve this answer|||||

I don't use videos to test. My quick guess would be to try wp_get_attachment_metadata() function.

|improve this answer|||||
  • WordPress will only save attachment metadata for images (EXIF & sizes). Looks like the need of a plugin to add support for video.. – TheDeadMedic Mar 16 '11 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.