Added verbosity to image conversion errors

This commit is contained in:
rr- 2015-11-23 11:35:09 +01:00
parent 28bba097c3
commit f5aed19bf3

View file

@ -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)