Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created April 13, 2016 05:39
Show Gist options
  • Save JacobHsu/bf409ae4add54e477f53e09c27e4eaaf to your computer and use it in GitHub Desktop.
Save JacobHsu/bf409ae4add54e477f53e09c27e4eaaf to your computer and use it in GitHub Desktop.
#ffmpeg #PHP
<?php
$ffmpeg_location ='"C:\Program Files\ffmpeg-20140928-git-3edb9aa-win64-static\bin\ffmpeg.exe"';
$file_path = 'C:\\ed2b6a653ded.mp4';
$src_cover = 'C:\src_cover.jpg';
$ffm = $ffmpeg_location . ' -i '. $file_path . ' -ss 00:00:01 -f image2 -vframes 1 ' . $src_cover.' 2>&1';
$xyz = shell_exec($ffm);
$search='/Duration: (.*?),/';
preg_match($search, $xyz, $matches);
$duration = explode(':', $matches[1]);
echo 'Hour: ' . $duration[0];
echo 'Minute: ' . $duration[1];
echo 'Seconds: ' . $duration[2];
$duration_in_seconds = $duration[0]*3600 + $duration[1]*60+ round($duration[2]);
echo 'Total Seconds: ' . $duration_in_seconds;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment