uploads: move thumbnail generation code to MediaFile.
* Move image thumbnail generation code to MediaFile::Image. * Move video thumbnail generation code to MediaFile::Video. * Move ugoira->webm conversion code to MediaFile::Ugoira. This separates thumbnail generation from the upload process so that it's possible to generate thumbnails outside of uploads.
This commit is contained in:
@@ -1,9 +1,29 @@
|
||||
class MediaFile::Video < MediaFile
|
||||
extend Memoist
|
||||
|
||||
def dimensions
|
||||
[video.width, video.height]
|
||||
end
|
||||
|
||||
def video
|
||||
@video ||= FFMPEG::Movie.new(file.path)
|
||||
def preview(max_width, max_height)
|
||||
preview_frame.preview(max_width, max_height)
|
||||
end
|
||||
|
||||
def crop(max_width, max_height)
|
||||
preview_frame.crop(max_width, max_height)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def video
|
||||
FFMPEG::Movie.new(file.path)
|
||||
end
|
||||
|
||||
def preview_frame
|
||||
vp = Tempfile.new(["video-preview", ".jpg"], binmode: true)
|
||||
video.screenshot(vp.path, seek_time: 0)
|
||||
MediaFile.open(vp.path)
|
||||
end
|
||||
|
||||
memoize :video, :preview_frame
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user