Merge pull request #747 from sanmadjack/ffmpeg_thumb_temp_file

Added handling to ensure that video thumbnails don't leave temp files…
This commit is contained in:
Shish 2020-09-16 11:20:51 +01:00 committed by GitHub
commit 111c4e3fb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -328,6 +328,7 @@ class Media extends Extension
$inname = warehouse_path(Image::IMAGE_DIR, $hash); $inname = warehouse_path(Image::IMAGE_DIR, $hash);
$tmpname = tempnam(sys_get_temp_dir(), "shimmie_ffmpeg_thumb"); $tmpname = tempnam(sys_get_temp_dir(), "shimmie_ffmpeg_thumb");
try {
$outname = warehouse_path(Image::THUMBNAIL_DIR, $hash); $outname = warehouse_path(Image::THUMBNAIL_DIR, $hash);
$orig_size = self::video_size($inname); $orig_size = self::video_size($inname);
@ -359,7 +360,7 @@ class Media extends Extension
exec($cmd, $output, $ret); exec($cmd, $output, $ret);
if ((int)$ret == (int)0) { if ((int)$ret === (int)0) {
log_debug('media', "Generating thumbnail with command `$cmd`, returns $ret"); log_debug('media', "Generating thumbnail with command `$cmd`, returns $ret");
create_scaled_image($tmpname, $outname, $scaled_size, MimeType::PNG); create_scaled_image($tmpname, $outname, $scaled_size, MimeType::PNG);
@ -370,6 +371,9 @@ class Media extends Extension
log_error('media', "Generating thumbnail with command `$cmd`, returns $ret"); log_error('media', "Generating thumbnail with command `$cmd`, returns $ret");
return false; return false;
} }
} finally {
@unlink($tmpname);
}
} }