2022-11-09 09:23:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2022, Varun Patil <radialapps@gmail.com>
|
|
|
|
* @author Varun Patil <radialapps@gmail.com>
|
|
|
|
* @license AGPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Memories\Command;
|
|
|
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class VideoSetup extends Command
|
|
|
|
{
|
|
|
|
protected IConfig $config;
|
|
|
|
protected OutputInterface $output;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
IConfig $config
|
|
|
|
) {
|
|
|
|
parent::__construct();
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure(): void
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('memories:video-setup')
|
|
|
|
->setDescription('Setup video streaming')
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
2022-11-15 10:27:20 +00:00
|
|
|
// Preset executables
|
|
|
|
$ffmpegPath = $this->config->getSystemValue('memories.ffmpeg_path', 'ffmpeg');
|
2022-11-21 10:38:12 +00:00
|
|
|
if ('ffmpeg' === $ffmpegPath) {
|
2022-11-21 10:34:57 +00:00
|
|
|
$ffmpegPath = trim(shell_exec('which ffmpeg') ?: 'ffmpeg');
|
|
|
|
$this->config->setSystemValue('memories.ffmpeg_path', $ffmpegPath);
|
|
|
|
}
|
2022-11-15 10:27:20 +00:00
|
|
|
$ffprobePath = $this->config->getSystemValue('memories.ffprobe_path', 'ffprobe');
|
2022-11-21 10:38:12 +00:00
|
|
|
if ('ffprobe' === $ffprobePath) {
|
2022-11-21 10:34:57 +00:00
|
|
|
$ffprobePath = trim(shell_exec('which ffprobe') ?: 'ffprobe');
|
|
|
|
$this->config->setSystemValue('memories.ffprobe_path', $ffprobePath);
|
|
|
|
}
|
2022-11-09 10:26:51 +00:00
|
|
|
|
2022-11-09 09:23:12 +00:00
|
|
|
// Get ffmpeg version
|
2023-01-18 03:11:20 +00:00
|
|
|
$ffmpeg = shell_exec("{$ffmpegPath} -version") ?: '';
|
2022-11-09 09:23:12 +00:00
|
|
|
if (false === strpos($ffmpeg, 'ffmpeg version')) {
|
|
|
|
$ffmpeg = null;
|
|
|
|
$output->writeln('<error>ffmpeg is not installed</error>');
|
|
|
|
} else {
|
|
|
|
$output->writeln('ffmpeg is installed');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get ffprobe version
|
2023-01-18 03:11:20 +00:00
|
|
|
$ffprobe = shell_exec("{$ffprobePath} -version") ?: '';
|
2022-11-09 09:23:12 +00:00
|
|
|
if (false === strpos($ffprobe, 'ffprobe version')) {
|
|
|
|
$ffprobe = null;
|
|
|
|
$output->writeln('<error>ffprobe is not installed</error>');
|
|
|
|
} else {
|
|
|
|
$output->writeln('ffprobe is installed');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null === $ffmpeg || null === $ffprobe) {
|
|
|
|
$output->writeln('ffmpeg and ffprobe are required for video transcoding');
|
2022-11-09 10:42:42 +00:00
|
|
|
|
2022-11-09 09:23:12 +00:00
|
|
|
return $this->suggestDisable($output);
|
|
|
|
}
|
|
|
|
|
2022-11-11 05:25:26 +00:00
|
|
|
// Check go-vod binary
|
|
|
|
$output->writeln('Checking for go-vod binary');
|
2022-11-21 10:43:03 +00:00
|
|
|
$goVodPath = $this->config->getSystemValue('memories.transcoder', false);
|
2022-11-09 09:23:12 +00:00
|
|
|
|
2022-11-23 09:38:36 +00:00
|
|
|
if (!\is_string($goVodPath) || !file_exists($goVodPath)) {
|
2022-11-21 10:43:03 +00:00
|
|
|
// Detect architecture
|
|
|
|
$arch = \OCA\Memories\Util::getArch();
|
2022-11-23 09:38:36 +00:00
|
|
|
$goVodPath = realpath(__DIR__."/../../exiftool-bin/go-vod-{$arch}");
|
2022-11-09 09:23:12 +00:00
|
|
|
|
2022-11-23 09:38:36 +00:00
|
|
|
if (!$goVodPath) {
|
2022-11-21 10:43:03 +00:00
|
|
|
$output->writeln('<error>Compatible go-vod binary not found</error>');
|
|
|
|
$this->suggestGoVod($output);
|
2022-11-09 10:42:42 +00:00
|
|
|
|
2022-11-21 10:43:03 +00:00
|
|
|
return $this->suggestDisable($output);
|
|
|
|
}
|
2022-11-09 09:23:12 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 05:25:26 +00:00
|
|
|
$output->writeln("Trying go-vod from {$goVodPath}");
|
|
|
|
chmod($goVodPath, 0755);
|
2022-11-09 09:23:12 +00:00
|
|
|
|
2022-11-11 05:25:26 +00:00
|
|
|
$goVod = shell_exec($goVodPath.' test');
|
|
|
|
if (!$goVod || false === strpos($goVod, 'test successful')) {
|
|
|
|
$output->writeln('<error>go-vod could not be run</error>');
|
|
|
|
$this->suggestGoVod($output);
|
2022-11-09 10:42:42 +00:00
|
|
|
|
2022-11-09 09:23:12 +00:00
|
|
|
return $this->suggestDisable($output);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go transcode is working. Yay!
|
2022-11-11 05:25:26 +00:00
|
|
|
$output->writeln('go-vod is installed!');
|
2022-11-09 09:23:12 +00:00
|
|
|
$output->writeln('');
|
|
|
|
$output->writeln('You can use transcoding and HLS streaming');
|
2022-11-09 10:26:51 +00:00
|
|
|
$output->writeln('This is recommended for better performance, but has implications if');
|
|
|
|
$output->writeln('you are using external storage or run Nextcloud on a slow system.');
|
|
|
|
$output->writeln('');
|
|
|
|
$output->writeln('Read the following documentation carefully before continuing:');
|
|
|
|
$output->writeln('https://github.com/pulsejet/memories/wiki/Configuration');
|
2022-11-09 09:23:12 +00:00
|
|
|
$output->writeln('');
|
|
|
|
$output->writeln('Do you want to enable transcoding and HLS? [Y/n]');
|
|
|
|
|
2022-11-09 14:21:17 +00:00
|
|
|
if ('n' === trim(fgets(fopen('php://stdin', 'r')))) {
|
2022-11-09 09:23:12 +00:00
|
|
|
$this->config->setSystemValue('memories.no_transcode', true);
|
|
|
|
$output->writeln('<error>Transcoding and HLS are now disabled</error>');
|
2022-11-09 10:42:42 +00:00
|
|
|
|
2022-11-09 09:23:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-11 05:25:26 +00:00
|
|
|
$this->config->setSystemValue('memories.transcoder', $goVodPath);
|
2022-11-09 09:23:12 +00:00
|
|
|
$this->config->setSystemValue('memories.no_transcode', false);
|
2022-11-12 02:24:37 +00:00
|
|
|
$output->writeln('Transcoding and HLS are now enabled! Monitor the output at /tmp/go-vod.log for any errors');
|
2022-11-15 10:27:20 +00:00
|
|
|
$output->writeln('You should restart the server for changes to take effect');
|
2022-11-09 09:23:12 +00:00
|
|
|
|
2022-11-09 14:21:17 +00:00
|
|
|
// Check for VAAPI
|
2023-01-19 18:39:19 +00:00
|
|
|
$output->writeln("\nChecking for VAAPI (/dev/dri/renderD128)");
|
2022-11-09 14:21:17 +00:00
|
|
|
if (file_exists('/dev/dri/renderD128')) {
|
2023-01-19 18:39:19 +00:00
|
|
|
$output->writeln('VAAPI is available. Do you want to enable it? [Y/n]');
|
2022-11-09 14:21:17 +00:00
|
|
|
|
|
|
|
if ('n' === trim(fgets(fopen('php://stdin', 'r')))) {
|
|
|
|
$this->config->setSystemValue('memories.qsv', false);
|
2023-01-19 18:39:19 +00:00
|
|
|
$output->writeln('VAAPI is now disabled');
|
2022-11-09 14:21:17 +00:00
|
|
|
} else {
|
2023-01-19 18:39:19 +00:00
|
|
|
$output->writeln("\nVAAPI is now enabled. You may still need to install the Intel Media Driver");
|
2022-11-12 02:26:02 +00:00
|
|
|
$output->writeln('and ensure proper permissions for /dev/dri/renderD128.');
|
2022-11-12 02:24:37 +00:00
|
|
|
$output->writeln('See the documentation for more details.');
|
2022-11-09 14:21:17 +00:00
|
|
|
$this->config->setSystemValue('memories.qsv', true);
|
|
|
|
}
|
|
|
|
} else {
|
2023-01-19 18:39:19 +00:00
|
|
|
$output->writeln('VAAPI is not available');
|
2022-11-09 14:21:17 +00:00
|
|
|
$this->config->setSystemValue('memories.qsv', false);
|
|
|
|
}
|
|
|
|
|
2022-11-09 09:23:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-11 05:25:26 +00:00
|
|
|
protected function suggestGoVod(OutputInterface $output): void
|
2022-11-09 09:23:12 +00:00
|
|
|
{
|
2022-11-11 05:25:26 +00:00
|
|
|
$output->writeln('You may build go-vod from source');
|
|
|
|
$output->writeln('It can be downloaded from https://github.com/pulsejet/go-vod');
|
2022-11-09 09:23:12 +00:00
|
|
|
$output->writeln('Once built, point the path to the binary in the config for `memories.transcoder`');
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:42:42 +00:00
|
|
|
protected function suggestDisable(OutputInterface $output)
|
|
|
|
{
|
2022-11-09 09:23:12 +00:00
|
|
|
$output->writeln('Without transcoding, video playback may be slow and limited');
|
|
|
|
$output->writeln('Do you want to disable transcoding and HLS streaming? [y/N]');
|
2022-11-09 14:21:17 +00:00
|
|
|
if ('y' !== trim(fgets(fopen('php://stdin', 'r')))) {
|
2022-11-09 09:23:12 +00:00
|
|
|
$output->writeln('Aborting');
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->config->setSystemValue('memories.no_transcode', true);
|
|
|
|
$output->writeln('<error>Transcoding and HLS are now disabled</error>');
|
2022-11-15 10:27:20 +00:00
|
|
|
$output->writeln('You should restart the server for changes to take effect');
|
2022-11-09 09:23:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|