Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

thanks

share|improve this question
    
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

4 Answers 4

up vote 0 down vote accepted

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.

share|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.

share|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 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 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;
}
add_filter('wp_generate_attachment_metadata','my_attachment_metadata',10,2);

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 ).

share|improve this answer

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

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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