You are here

public function video_ffmpeg::get_playtime in Video 6.4

Same name and namespace in other branches
  1. 7 transcoders/video_ffmpeg.inc \video_ffmpeg::get_playtime()

Return the playtime seconds of a video

1 call to video_ffmpeg::get_playtime()
video_ffmpeg::generate_thumbnails in transcoders/video_ffmpeg.inc

File

transcoders/video_ffmpeg.inc, line 288

Class

video_ffmpeg

Code

public function get_playtime($video) {
  $ffmpeg_output = $this
    ->get_video_info($video);

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