Check if result file exists, and provide force option

This commit is contained in:
Daniel Siepmann 2020-09-30 13:49:48 +02:00
parent 8b8f7fcab1
commit efb7991e57
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 13 additions and 4 deletions

View file

@ -16,6 +16,7 @@ use Symfony\Component\Console\SingleCommandApplication;
->addArgument('file', InputArgument::REQUIRED, 'The video file to cut.') ->addArgument('file', InputArgument::REQUIRED, 'The video file to cut.')
->addArgument('start', InputArgument::REQUIRED, 'The starting point of the video') ->addArgument('start', InputArgument::REQUIRED, 'The starting point of the video')
->addArgument('end', InputArgument::REQUIRED, 'The end point of the video') ->addArgument('end', InputArgument::REQUIRED, 'The end point of the video')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force generation, even if target already exists.')
->addOption('ad', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Start and end of ads, separate start and end via "/".', []) ->addOption('ad', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Start and end of ads, separate start and end via "/".', [])
->setCode(new Command()) ->setCode(new Command())
->run(); ->run();

View file

@ -44,6 +44,14 @@ class Command
$input->getOption('ad') $input->getOption('ad')
); );
if (
file_exists($videoInfo->getTargetFilePath())
&& $input->getOption('force') === false
) {
$this->io->error('Target file already exist, "-f" to force generation.');
return 1;
}
$cutting = new Cutting($videoInfo); $cutting = new Cutting($videoInfo);
$this->io->title('Generating temp cutted video files.'); $this->io->title('Generating temp cutted video files.');

View file

@ -65,7 +65,7 @@ class Cutting
public function getCommandForGeneratingMetadata(): Process public function getCommandForGeneratingMetadata(): Process
{ {
$command = sprintf( $command = sprintf(
'ffmpeg -i %s -f ffmetadata %s', 'ffmpeg -y -i %s -f ffmetadata %s',
escapeshellarg($this->video->getOriginalFilename()), escapeshellarg($this->video->getOriginalFilename()),
escapeshellarg($this->getMetadataFilename()) escapeshellarg($this->getMetadataFilename())
); );
@ -94,7 +94,7 @@ class Cutting
public function getCommandForGeneratingVideo(): Process public function getCommandForGeneratingVideo(): Process
{ {
$command = sprintf( $command = sprintf(
'ffmpeg -f concat -safe 0 -i %s -c copy' 'ffmpeg -y -f concat -safe 0 -i %s -c copy'
. ' -f ffmetadata -i %s -c copy -map_metadata 1' . ' -f ffmetadata -i %s -c copy -map_metadata 1'
// . ' -metadata Title="$episodeTitle"' // . ' -metadata Title="$episodeTitle"'
. ' %s', . ' %s',

View file

@ -132,7 +132,7 @@ class CuttingTest extends TestCase
$command = $subject->getCommandForGeneratingMetadata(); $command = $subject->getCommandForGeneratingMetadata();
static::assertSame( static::assertSame(
"ffmpeg -i 'Some-Video.mp4' -f ffmetadata '/tmp/Some-Video-metadata.txt'", "ffmpeg -y -i 'Some-Video.mp4' -f ffmetadata '/tmp/Some-Video-metadata.txt'",
$command->getCommandLine() $command->getCommandLine()
); );
} }
@ -236,7 +236,7 @@ class CuttingTest extends TestCase
$command = $subject->getCommandForGeneratingVideo(); $command = $subject->getCommandForGeneratingVideo();
static::assertSame( static::assertSame(
'ffmpeg -f concat -safe 0 -i \'/tmp/Series-Name_Series-01_episode-title-01-concat.txt\' -c copy' 'ffmpeg -y -f concat -safe 0 -i \'/tmp/Series-Name_Series-01_episode-title-01-concat.txt\' -c copy'
. ' -f ffmetadata -i \'/tmp/Series-Name_Series-01_episode-title-01-metadata.txt\' -c copy -map_metadata 1' . ' -f ffmetadata -i \'/tmp/Series-Name_Series-01_episode-title-01-metadata.txt\' -c copy -map_metadata 1'
// . ' -metadata Title="$episodeTitle"' // . ' -metadata Title="$episodeTitle"'
. ' \'Series-Name/Series-01/10-episode title.mp4\'', . ' \'Series-Name/Series-01/10-episode title.mp4\'',