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)
|
private function convertFromFlash($sourcePath, $targetPath)
|
||||||
{
|
{
|
||||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_DUMP_GNASH))
|
$this->convertWithPrograms(
|
||||||
{
|
[
|
||||||
ProgramExecutor::run(
|
self::PROGRAM_NAME_DUMP_GNASH =>
|
||||||
self::PROGRAM_NAME_DUMP_GNASH,
|
|
||||||
[
|
[
|
||||||
'--screenshot', 'last',
|
'--screenshot', 'last',
|
||||||
'--screenshot-file', $targetPath,
|
'--screenshot-file', $targetPath,
|
||||||
|
@ -67,63 +66,68 @@ class ImageConverter
|
||||||
'-r1',
|
'-r1',
|
||||||
'--max-advances', '15',
|
'--max-advances', '15',
|
||||||
$sourcePath,
|
$sourcePath,
|
||||||
]);
|
],
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER))
|
self::PROGRAM_NAME_SWFRENDER =>
|
||||||
{
|
|
||||||
ProgramExecutor::run(
|
|
||||||
self::PROGRAM_NAME_SWFRENDER,
|
|
||||||
[
|
[
|
||||||
'swfrender',
|
|
||||||
$sourcePath,
|
$sourcePath,
|
||||||
'-o',
|
'-o',
|
||||||
$targetPath,
|
$targetPath,
|
||||||
]);
|
],
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
|
self::PROGRAM_NAME_FFMPEG =>
|
||||||
{
|
|
||||||
ProgramExecutor::run(
|
|
||||||
self::PROGRAM_NAME_FFMPEG,
|
|
||||||
[
|
[
|
||||||
'-i',
|
'-i',
|
||||||
$sourcePath,
|
$sourcePath,
|
||||||
'-vframes', '1',
|
'-vframes', '1',
|
||||||
$targetPath,
|
$targetPath,
|
||||||
]);
|
],
|
||||||
}
|
],
|
||||||
|
$targetPath);
|
||||||
if (!file_exists($targetPath))
|
|
||||||
throw new \Exception('Error while converting Flash file to image');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function convertFromVideo($sourcePath, $targetPath)
|
private function convertFromVideo($sourcePath, $targetPath)
|
||||||
{
|
{
|
||||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEGTHUMBNAILER))
|
$this->convertWithPrograms(
|
||||||
{
|
[
|
||||||
ProgramExecutor::run(
|
self::PROGRAM_NAME_FFMPEGTHUMBNAILER =>
|
||||||
self::PROGRAM_NAME_FFMPEGTHUMBNAILER,
|
|
||||||
[
|
[
|
||||||
'-i' . $sourcePath,
|
'-i' . $sourcePath,
|
||||||
'-o' . $targetPath,
|
'-o' . $targetPath,
|
||||||
'-s0',
|
'-s0',
|
||||||
'-t12%%'
|
'-t12%%'
|
||||||
]);
|
],
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
|
self::PROGRAM_NAME_FFMPEG =>
|
||||||
{
|
|
||||||
ProgramExecutor::run(self::PROGRAM_NAME_FFMPEG,
|
|
||||||
[
|
[
|
||||||
'-i', $sourcePath,
|
'-i', $sourcePath,
|
||||||
'-vframes', '1',
|
'-vframes', '1',
|
||||||
$targetPath
|
$targetPath
|
||||||
]);
|
]
|
||||||
|
],
|
||||||
|
$targetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($targetPath))
|
private function convertWithPrograms($programs, $targetPath)
|
||||||
throw new \Exception('Error while converting video file to image');
|
{
|
||||||
|
$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)
|
private function deleteIfExists($path)
|
||||||
|
|
Loading…
Reference in a new issue