Community Documentation

Computed field: Calculate duration of CCK video field

Last updated October 11, 2011. Created by WildKitten on October 11, 2011.
Log in to edit this page.

If you have installed video and ffmpeg_wrapper modules and want to calculate duration of your video CCK field in Computed field in the same content type, this is the code for it.

In computed code enter this:

if (!$node->nid) node_save($node);
$filepath = "";
module_load_include('inc', 'ffmpeg_wrapper', 'ffmpeg_wrapper_class');
$duration = ffmpeg_wrapper_get_file_duration($node->field_video_file[0]['filepath']);
$node_field[0]['value'] = $duration;

where field_video_file is the name of CCK video file field (so change this to correspond to your CCK filed)

In display format eneter this:

$display = $node_field_item['value'] . ' sec';

About this page

Drupal version
Drupal 6.x
Audience
Contributors, Programmers

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.