Added verbosity to image conversion errors
This commit is contained in:
parent
28bba097c3
commit
f5aed19bf3
1 changed files with 38 additions and 34 deletions
|
@ -56,10 +56,9 @@ class ImageConverter
|
|||
|
||||
private function convertFromFlash($sourcePath, $targetPath)
|
||||
{
|
||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_DUMP_GNASH))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_DUMP_GNASH,
|
||||
$this->convertWithPrograms(
|
||||
[
|
||||
self::PROGRAM_NAME_DUMP_GNASH =>
|
||||
[
|
||||
'--screenshot', 'last',
|
||||
'--screenshot-file', $targetPath,
|
||||
|
@ -67,63 +66,68 @@ class ImageConverter
|
|||
'-r1',
|
||||
'--max-advances', '15',
|
||||
$sourcePath,
|
||||
]);
|
||||
}
|
||||
],
|
||||
|
||||
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_SWFRENDER,
|
||||
self::PROGRAM_NAME_SWFRENDER =>
|
||||
[
|
||||
'swfrender',
|
||||
$sourcePath,
|
||||
'-o',
|
||||
$targetPath,
|
||||
]);
|
||||
}
|
||||
],
|
||||
|
||||
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_FFMPEG,
|
||||
self::PROGRAM_NAME_FFMPEG =>
|
||||
[
|
||||
'-i',
|
||||
$sourcePath,
|
||||
'-vframes', '1',
|
||||
$targetPath,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($targetPath))
|
||||
throw new \Exception('Error while converting Flash file to image');
|
||||
],
|
||||
],
|
||||
$targetPath);
|
||||
}
|
||||
|
||||
private function convertFromVideo($sourcePath, $targetPath)
|
||||
{
|
||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEGTHUMBNAILER))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_FFMPEGTHUMBNAILER,
|
||||
$this->convertWithPrograms(
|
||||
[
|
||||
self::PROGRAM_NAME_FFMPEGTHUMBNAILER =>
|
||||
[
|
||||
'-i' . $sourcePath,
|
||||
'-o' . $targetPath,
|
||||
'-s0',
|
||||
'-t12%%'
|
||||
]);
|
||||
}
|
||||
],
|
||||
|
||||
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
|
||||
{
|
||||
ProgramExecutor::run(self::PROGRAM_NAME_FFMPEG,
|
||||
self::PROGRAM_NAME_FFMPEG =>
|
||||
[
|
||||
'-i', $sourcePath,
|
||||
'-vframes', '1',
|
||||
$targetPath
|
||||
]);
|
||||
]
|
||||
],
|
||||
$targetPath);
|
||||
}
|
||||
|
||||
if (!file_exists($targetPath))
|
||||
throw new \Exception('Error while converting video file to image');
|
||||
private function convertWithPrograms($programs, $targetPath)
|
||||
{
|
||||
$any_program_available = false;
|
||||
foreach ($programs as $program => $args)
|
||||
$any_program_available |= ProgramExecutor::isProgramAvailable($program);
|
||||
if (!$any_program_available)
|
||||
throw new \Exception('No converter available (tried ' . join(', ', array_keys($programs)) . ')');
|
||||
|
||||
$errors = [];
|
||||
foreach ($programs as $program => $args)
|
||||
{
|
||||
if (ProgramExecutor::isProgramAvailable($program))
|
||||
{
|
||||
$errors[] = ProgramExecutor::run($program, $args);
|
||||
if (file_exists($targetPath))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \Exception('Error while converting file to image: ' . join(', ', $errors));
|
||||
}
|
||||
|
||||
private function deleteIfExists($path)
|
||||
|
|
Loading…
Reference in a new issue