You are here

function ffmpeg_wrapper_auto_playtime in Video 6.3

Return the playtime seconds of a video

File

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

Code

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

    // call ffmpeg -i
    $ffmpeg_output = ffmpeg_wrapper_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;
  }
}