Allow to define temp folder
Some systems might have limited temp folder sizes. A new option is added to configure the folder to use for temp files.
This commit is contained in:
parent
4fa3cef8c3
commit
8124631d5d
3 changed files with 15 additions and 6 deletions
1
cutvideo
1
cutvideo
|
@ -16,6 +16,7 @@ use Symfony\Component\Console\SingleCommandApplication;
|
|||
->addArgument('end', InputArgument::REQUIRED, 'The end point of the video')
|
||||
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force generation, even if target already exists.')
|
||||
->addOption('remove', 'r', InputOption::VALUE_NONE, 'Remove input file on success.')
|
||||
->addOption('tmp', 't', InputOption::VALUE_OPTIONAL, 'Temporary folder for temporary files. Defaults to system temp.')
|
||||
->addOption('ad', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Start and end of ads, separate start and end via "/".', [])
|
||||
->setCode(new Command())
|
||||
->run();
|
||||
|
|
|
@ -52,7 +52,7 @@ class Command
|
|||
return 1;
|
||||
}
|
||||
|
||||
$cutting = new Cutting($videoInfo);
|
||||
$cutting = new Cutting($videoInfo, $input->getOption('tmp'));
|
||||
|
||||
$this->executeStep('Generating temp cutted video files.');
|
||||
foreach ($cutting->getCommandsForCutting() as $command) {
|
||||
|
|
|
@ -30,14 +30,22 @@ class Cutting
|
|||
*/
|
||||
private $video;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $tempFolder = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $tempFilenames = [];
|
||||
|
||||
public function __construct(VideoInfo $video)
|
||||
{
|
||||
public function __construct(
|
||||
VideoInfo $video,
|
||||
?string $tempFolder = null
|
||||
) {
|
||||
$this->video = $video;
|
||||
$this->tempFolder = $tempFolder ?? sys_get_temp_dir();
|
||||
}
|
||||
|
||||
public function getCommandsForCutting(): \Generator
|
||||
|
@ -136,7 +144,7 @@ class Cutting
|
|||
private function getNextTempFilename(): string
|
||||
{
|
||||
$count = count($this->tempFilenames) + 1;
|
||||
$nextName = sys_get_temp_dir()
|
||||
$nextName = $this->tempFolder
|
||||
. DIRECTORY_SEPARATOR
|
||||
. $this->video->getOriginalFilenameWithSuffix('cut-' . $count);
|
||||
|
||||
|
@ -148,13 +156,13 @@ class Cutting
|
|||
{
|
||||
$file = new \SplFileInfo($this->video->getOriginalFilenameWithSuffix('metadata'));
|
||||
|
||||
return sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt';
|
||||
return $this->tempFolder . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt';
|
||||
}
|
||||
|
||||
private function getConcatFilename(): string
|
||||
{
|
||||
$file = new \SplFileInfo($this->video->getOriginalFilenameWithSuffix('concat'));
|
||||
|
||||
return sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt';
|
||||
return $this->tempFolder . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue