You are here

function _video_ffmpeg_helper_auto_playtime in Video 6.2

Same name and namespace in other branches
  1. 5 plugins/video_ffmpeg_helper/video_ffmpeg_helper.module \_video_ffmpeg_helper_auto_playtime()
  2. 6 plugins/video_ffmpeg_helper/video_ffmpeg_helper.module \_video_ffmpeg_helper_auto_playtime()

Return the playtime seconds of a video

1 call to _video_ffmpeg_helper_auto_playtime()
video_upload_v_auto_playtime in types/video_upload/video_upload.module
Implements the hook_v_auto_resolution

File

plugins/video_ffmpeg_helper/video_ffmpeg_helper.module, line 404
Provide some api for use ffmpeg. Simplify video nodes creation.

Code

function _video_ffmpeg_helper_auto_playtime(&$node) {
  if (variable_get('video_ffmpeg_helper_auto_playtime', false)) {

    // call ffmpeg -i
    $ffmpeg_output = _video_ffmpeg_helper_get_video_info($node);

    // 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;
  }
}