You are here

function ffmpeg_auto_playtime in Video 6.3

Return the playtime seconds of a video

3 calls to ffmpeg_auto_playtime()
ffmpeg_auto_thumbnail in plugins/ffmpeg.inc
Generates a thumbnail from the video file Implementing hook_auto_thumbnail on inc
uploadfield_v_auto_playtime in types/uploadfield/uploadfield.module
Implements the hook_v_auto_resolution
uploadfield_v_auto_resolution in types/uploadfield/uploadfield.module
Implements the hook_v_auto_resolution

File

plugins/ffmpeg.inc, line 91
Provide a api for video conversion and auto thumbnailing using ffmpeg.

Code

function ffmpeg_auto_playtime($file) {
  if (!variable_get('video_ffmpeg_helper_auto_playtime', false)) {

    // call ffmpeg -i
    $ffmpeg_output = ffmpeg_get_video_info($file);

    // get playtime
    $pattern = '/Duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9])/';
    preg_match_all($pattern, $ffmpeg_output, $matches, PREG_PATTERN_ORDER);
    $playtime = $matches[1][0];

    // ffmpeg return lenght as 00:00:31.1 Let's get playtime from that
    $hmsmm = explode(":", $playtime);
    $tmp = explode(".", $hmsmm[2]);
    $seconds = $tmp[0];
    $hours = $hmsmm[0];
    $minutes = $hmsmm[1];
    return $seconds + $hours * 3600 + $minutes * 60;
  }
}