/** * Generates image thumbnails from specified video file */ function generate_video_thumb($fileId, $where = '10%') { if (!is_numeric($fileId)) { return false; } if (!file_exists(File::getUploadPath($fileId))) { throw new \Exception('file ' . File::getUploadPath($fileId) . ' dont exist!'); } $c = 'avprobe ' . File::getUploadPath($fileId) . ' 2>&1 | /bin/grep Duration | cut -d, -f1'; // returns: "Duration: 00:00:08.50" //echo "Executing: ".$c."\n"; $x = exec($c); $xx = explode(': ', $x); $duration = in_seconds($xx[1]); // 00:00:08.50 => 8.5 $pos_val = intval($where) / 10; $pos = $duration * $pos_val; $tmpimg = tempnam('/tmp', 'vid-thumb'); $c = 'avconv -i ' . File::getUploadPath($fileId) . ' -ss ' . $pos . ' -vframes 1 -f image2 ' . $tmpimg . ' 2> /dev/null'; // echo "$ ".$c."\n"; exec($c); $key = array('tmp_name' => $tmpimg, 'name' => 'thumbnail', 'type' => 'image/jpeg', 'size' => filesize($tmpimg)); $thumbId = File::importImage(THUMB, $key, $fileId, true); return $thumbId; }
if (in_seconds('23:59:59') != 86399) { echo "FAIL 12\n"; } if (in_seconds('0:49:47.53') != 2987.53) { echo "FAIL 13\n"; } if (in_seconds('00:26:36,595') != 1596.595) { echo "FAIL 14\n"; } if (in_seconds('18:40:22') != 67222) { echo "FAIL 15\n"; } if (in_seconds('18:40:22.11') != 67222.11) { echo "FAIL 16\n"; } if (in_seconds('18:40:22,11') != 67222.11) { echo "FAIL 17\n"; } if (seconds_to_hms(65625) != '18:13:45') { echo "FAIL 20\n"; } if (seconds_to_hms(0) != '00:00:00') { echo "FAIL 21\n"; } if (seconds_to_hms(86399) != '23:59:59') { echo "FAIL 22\n"; } if (seconds_to_hms(2987.53) != '0:49:47.53') { echo "FAIL 23\n"; } if (seconds_to_hms(1596.595, true, 3, ',') != '0:26:36,595') {