PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $text = 'out_time=00:00:00.300065 dup_frames=0 drop_frames=0 speed=0.542x progress=continue frame=144 fps=136.22 stream_0_0_q=31.0 bitrate=2859.9kbits/s total_size=524336 out_time_us=1466732 out_time_ms=1466732 out_time=00:00:01.466732 dup_frames=0 drop_frames=0 speed=1.39x progress=continue frame=195 fps=124.92 stream_0_0_q=31.0 bitrate=3621.0kbits/s total_size=1048624 out_time_us=2316732 out_time_ms=2316732 out_time=00:00:02.316732 dup_frames=0 drop_frames=0 speed=1.48x progress=continue frame=244 fps=118.08 stream_0_0_q=31.0 bitrate=3346.6kbits/s total_size=1310768 out_time_us=3133398 out_time_ms=3133398 out_time=00:00:03.133398 dup_frames=0 drop_frames=0 speed=1.52x progress=continue frame=300 fps=116.25 stream_0_0_q=31.0 bitrate=3609.9kbits/s total_size=1835056 out_time_us=4066732 out_time_ms=4066732 out_time=00:00:04.066732'; preg_match_all('/out_time=([\d:.]+)/', $text, $outTimeMatches); // var_dump($outTimeMatches[0]); function updateProgress($text) { $lastOutTime = null; while (true) { $fileContent = $text; $outTimeMatches = []; preg_match_all('/out_time=([\d:.]+)/', $fileContent, $outTimeMatches); if (!empty($outTimeMatches[0])) { $lastOutTime = end($outTimeMatches[0]); } sleep(2); // ждем 2 секунды if (!isFileProcessing($filePath)) { break; // файл закончил обработку } } if ($lastOutTime !== null) { $progress = floatval(str_replace('out_time=', '', $lastOutTime)); // сохраняем прогресс в базу данных // $model = Video::findOne(['file_path' => $filePath]); // if ($model !== null) { // $model->progress = $progress; // $model->save(false); // } echo 'мы тут'; } } function isFileProcessing($text) { $fileContent = $text; $progressMatches = []; preg_match_all('/progress=\d+/', $fileContent, $progressMatches); if (!empty($progressMatches[0])) { $lastProgress = end($progressMatches[0]); if ($lastProgress === 'progress=end') { return false; } } return true; } updateProgress($text);
Show:  
Copy Clear