未验证 提交 68846bdc 编写于 作者: A Abhay Nikam 提交者: GitHub

Verify FFmpeg presence before attempting to preview videos

上级 3de96691
......@@ -2,8 +2,20 @@
module ActiveStorage
class Previewer::VideoPreviewer < Previewer
def self.accept?(blob)
blob.video?
class << self
def accept?(blob)
blob.video? && ffmpeg_exists?
end
def ffmpeg_exists?
return @ffmpeg_exists if defined?(@ffmpeg_exists)
@ffmpeg_exists = system(ffmpeg_path, "-version", out: File::NULL, err: File::NULL)
end
def ffmpeg_path
ActiveStorage.paths[:ffmpeg] || "ffmpeg"
end
end
def preview(**options)
......@@ -16,11 +28,7 @@ def preview(**options)
private
def draw_relevant_frame_from(file, &block)
draw ffmpeg_path, "-i", file.path, "-y", "-vframes", "1", "-f", "image2", "-", &block
end
def ffmpeg_path
ActiveStorage.paths[:ffmpeg] || "ffmpeg"
draw self.class.ffmpeg_path, "-i", file.path, "-y", "-vframes", "1", "-f", "image2", "-", &block
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册