Pimcore\Video\Adapter\Ffmpeg::save PHP Method

save() public method

public save ( ) : mixed | void
return mixed | void
    public function save()
    {
        $success = false;
        if ($this->getDestinationFile()) {
            if (is_file($this->getConversionLogFile())) {
                $this->deleteConversionLogFile();
            }
            if (is_file($this->getDestinationFile())) {
                @unlink($this->getDestinationFile());
            }
            // get the argument string from the configurations
            $arguments = implode(" ", $this->arguments);
            // add format specific arguments
            if ($this->getFormat() == "mp4") {
                $arguments = "-strict experimental -f mp4 -vcodec libx264 -acodec aac -g 100 -pix_fmt yuv420p -movflags faststart " . $arguments;
            } elseif ($this->getFormat() == "webm") {
                // check for vp9 support
                $webmCodec = "libvpx";
                $codecs = Console::exec(self::getFfmpegCli() . " -codecs");
                if (stripos($codecs, "vp9")) {
                    //$webmCodec = "libvpx-vp9"; // disabled until better support in ffmpeg and browsers
                }
                $arguments = "-strict experimental -f webm -vcodec " . $webmCodec . " -acodec libvorbis -ar 44000 -g 100 " . $arguments;
            } else {
                throw new \Exception("Unsupported video output format: " . $this->getFormat());
            }
            // add some global arguments
            $arguments = "-threads 0 " . $arguments;
            $cmd = self::getFfmpegCli() . ' -i ' . escapeshellarg(realpath($this->file)) . ' ' . $arguments . " " . escapeshellarg(str_replace("/", DIRECTORY_SEPARATOR, $this->getDestinationFile()));
            Logger::debug("Executing FFMPEG Command: " . $cmd);
            $process = new Process($cmd);
            //symfony has a default timeout which is 60 sec. This is not enough for converting big video-files.
            $process->setTimeout(null);
            $process->start();
            $logHandle = fopen($this->getConversionLogFile(), "a");
            $process->wait(function ($type, $buffer) use($logHandle) {
                fwrite($logHandle, $buffer);
            });
            fclose($logHandle);
            if ($process->isSuccessful()) {
                // cleanup & status update
                $this->deleteConversionLogFile();
                $success = true;
            } else {
                // create an error log file
                copy($this->getConversionLogFile(), str_replace(".log", ".error.log", $this->getConversionLogFile()));
            }
        } else {
            throw new \Exception("There is no destination file for video converter");
        }
        return $success;
    }