/** * Encode video * * @fixme проверить не осталось ли еще активных процессов на конвертацию от прошлой cron задачи, если осталось, то менять $threads для тещушего cron. * @return int * @throws \Exception * @throws \yii\web\UnsupportedMediaTypeHttpException */ public function actionEncode() { /** @var Video $video */ // get params $params = Yii::$app->params; $outputFormat = $params['video.encode.outputFormat']; $threads = $params['video.encode.threads']; $timeout = $params['video.encode.timeout']; $savePath = $params['path.video.converted']; // ffmpeg init $ffmpegConfig = ['ffmpeg.threads' => $threads, 'timeout' => $timeout]; // video processing $error = null; $videos = Video::getUnconvertedVideo($threads); foreach ($videos as $video) { $video->converted_filename = FileHelper::generateFileName($outputFormat, $savePath); $filePaths = $video->getPaths(); // video encode if (FfmpegHelper::convert($filePaths['upload'], $filePaths['converted'], $outputFormat, $ffmpegConfig)) { $meta = FfmpegHelper::getProperties($filePaths['converted']); $video->converted_video_bitrate = $meta['video_bitrate']; $video->converted_audio_bitrate = $meta['audio_bitrate']; $video->status = Video::STATUS_ENCODE_SUCCESS; } else { $video->status = Video::STATUS_ENCODE_ERROR; $error = true; } $video->save(false); } return $error === null ? Controller::EXIT_CODE_NORMAL : Controller::EXIT_CODE_ERROR; }