mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Change video preview format from PNG to JPG
This commit is contained in:
parent
70bd858af0
commit
b60ee86d94
3 changed files with 7 additions and 7 deletions
|
@ -9,15 +9,14 @@ module ActiveStorage
|
||||||
def preview
|
def preview
|
||||||
download_blob_to_tempfile do |input|
|
download_blob_to_tempfile do |input|
|
||||||
draw_relevant_frame_from input do |output|
|
draw_relevant_frame_from input do |output|
|
||||||
yield io: output, filename: "#{blob.filename.base}.png", content_type: "image/png"
|
yield io: output, filename: "#{blob.filename.base}.jpg", content_type: "image/jpeg"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def draw_relevant_frame_from(file, &block)
|
def draw_relevant_frame_from(file, &block)
|
||||||
draw ffmpeg_path, "-i", file.path, "-y", "-vcodec", "png",
|
draw ffmpeg_path, "-i", file.path, "-y", "-vframes", "1", "-f", "image2", "-", &block
|
||||||
"-vf", "thumbnail", "-vframes", "1", "-f", "image2", "-", &block
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ffmpeg_path
|
def ffmpeg_path
|
||||||
|
|
|
@ -22,8 +22,8 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase
|
||||||
preview = blob.preview(resize: "640x280").processed
|
preview = blob.preview(resize: "640x280").processed
|
||||||
|
|
||||||
assert_predicate preview.image, :attached?
|
assert_predicate preview.image, :attached?
|
||||||
assert_equal "video.png", preview.image.filename.to_s
|
assert_equal "video.jpg", preview.image.filename.to_s
|
||||||
assert_equal "image/png", preview.image.content_type
|
assert_equal "image/jpeg", preview.image.content_type
|
||||||
|
|
||||||
image = read_image(preview.image)
|
image = read_image(preview.image)
|
||||||
assert_equal 640, image.width
|
assert_equal 640, image.width
|
||||||
|
|
|
@ -12,12 +12,13 @@ class ActiveStorage::Previewer::VideoPreviewerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test "previewing an MP4 video" do
|
test "previewing an MP4 video" do
|
||||||
ActiveStorage::Previewer::VideoPreviewer.new(@blob).preview do |attachable|
|
ActiveStorage::Previewer::VideoPreviewer.new(@blob).preview do |attachable|
|
||||||
assert_equal "image/png", attachable[:content_type]
|
assert_equal "image/jpeg", attachable[:content_type]
|
||||||
assert_equal "video.png", attachable[:filename]
|
assert_equal "video.jpg", attachable[:filename]
|
||||||
|
|
||||||
image = MiniMagick::Image.read(attachable[:io])
|
image = MiniMagick::Image.read(attachable[:io])
|
||||||
assert_equal 640, image.width
|
assert_equal 640, image.width
|
||||||
assert_equal 480, image.height
|
assert_equal 480, image.height
|
||||||
|
assert_equal "image/jpeg", image.mime_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue