/** * Creates a new Resource model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Resource(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * [transcode Transcode video] * @param [Resource] $model [] * @return [bool] [success or failed] */ public function transcode(Resource $model) { if ($model->save()) { $rootPath = Yii::$app->params['uploadUrl']; $time = time(); exec("ffmpeg -i {$rootPath}{$model->url} -f mp4 -vcodec libx264 -s 640x360 {$rootPath}/uploads/video/{$model->name}.{$time}.mp4", $res, $rc); if (!$rc) { $model->status = static::STATUS_AUTHEN; $model->extension = 'mp4'; $model->url = "/uploads/video/{$model->name}.{$time}.mp4"; $model->update_time = Common::getTime(); if ($model->save()) { return true; } } } return false; }