mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-07 23:06:42 +01:00
stop generating enormous gif thumbnails for videos
This commit is contained in:
parent
d783417608
commit
b9ad5643dc
3 changed files with 20 additions and 11 deletions
|
@ -10,7 +10,7 @@ defmodule Philomena.Processors.Webm do
|
||||||
|
|
||||||
{:ok, intensities} = Intensities.file(preview)
|
{:ok, intensities} = Intensities.file(preview)
|
||||||
|
|
||||||
scaled = Enum.flat_map(versions, &scale_if_smaller(file, palette, dimensions, &1))
|
scaled = Enum.flat_map(versions, &scale_if_smaller(file, palette, duration, dimensions, &1))
|
||||||
|
|
||||||
%{
|
%{
|
||||||
intensities: intensities,
|
intensities: intensities,
|
||||||
|
@ -35,7 +35,7 @@ defmodule Philomena.Processors.Webm do
|
||||||
preview
|
preview
|
||||||
end
|
end
|
||||||
|
|
||||||
defp scale_if_smaller(file, palette, dimensions, {:full, _target_dim}) do
|
defp scale_if_smaller(file, palette, _duration, dimensions, {:full, _target_dim}) do
|
||||||
{_webm, mp4} = scale_videos(file, palette, dimensions, dimensions)
|
{_webm, mp4} = scale_videos(file, palette, dimensions, dimensions)
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -44,12 +44,12 @@ defmodule Philomena.Processors.Webm do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp scale_if_smaller(file, palette, dimensions, {thumb_name, {target_width, target_height}}) do
|
defp scale_if_smaller(file, palette, duration, dimensions, {thumb_name, {target_width, target_height}}) do
|
||||||
{webm, mp4} = scale_videos(file, palette, dimensions, {target_width, target_height})
|
{webm, mp4} = scale_videos(file, palette, dimensions, {target_width, target_height})
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
thumb_name in [:thumb, :thumb_small, :thumb_tiny] ->
|
thumb_name in [:thumb, :thumb_small, :thumb_tiny] ->
|
||||||
gif = scale_gif(file, palette, {target_width, target_height})
|
gif = scale_gif(file, palette, duration, {target_width, target_height})
|
||||||
|
|
||||||
[
|
[
|
||||||
{:copy, webm, "#{thumb_name}.webm"},
|
{:copy, webm, "#{thumb_name}.webm"},
|
||||||
|
@ -79,14 +79,15 @@ defmodule Philomena.Processors.Webm do
|
||||||
{webm, mp4}
|
{webm, mp4}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp scale_gif(file, palette, {width, height}) do
|
defp scale_gif(file, palette, duration, {width, height}) do
|
||||||
gif = Briefly.create!(extname: ".gif")
|
gif = Briefly.create!(extname: ".gif")
|
||||||
scale_filter = "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease"
|
scale_filter = "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease"
|
||||||
palette_filter = "paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle"
|
palette_filter = "paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle"
|
||||||
filter_graph = "[0:v] #{scale_filter} [x]; [x][1:v] #{palette_filter}"
|
rate_filter = "fps=1/#{duration},settb=1/2,setpts=N"
|
||||||
|
filter_graph = "[0:v] #{scale_filter},#{rate_filter} [x]; [x][1:v] #{palette_filter}"
|
||||||
|
|
||||||
{_output, 0} =
|
{_output, 0} =
|
||||||
System.cmd("ffmpeg", ["-loglevel", "0", "-y", "-i", file, "-i", palette, "-lavfi", filter_graph, gif])
|
System.cmd("ffmpeg", ["-loglevel", "0", "-y", "-i", file, "-i", palette, "-lavfi", filter_graph, "-r", "2", gif])
|
||||||
|
|
||||||
gif
|
gif
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,7 @@ defmodule PhilomenaWeb.SettingController do
|
||||||
conn
|
conn
|
||||||
|> set_cookie(user_params, "hidpi", "hidpi")
|
|> set_cookie(user_params, "hidpi", "hidpi")
|
||||||
|> set_cookie(user_params, "webm", "webm")
|
|> set_cookie(user_params, "webm", "webm")
|
||||||
|
|> set_cookie(user_params, "serve_webm", "serve_webm")
|
||||||
|> set_cookie(user_params, "chan_nsfw", "chan_nsfw")
|
|> set_cookie(user_params, "chan_nsfw", "chan_nsfw")
|
||||||
|> set_cookie(user_params, "hide_staff_tools", "hide_staff_tools")
|
|> set_cookie(user_params, "hide_staff_tools", "hide_staff_tools")
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,20 +17,24 @@
|
||||||
|
|
||||||
- true ->
|
- true ->
|
||||||
|
|
||||||
.media-box__overlay.js-spoiler-info-overlay
|
|
||||||
|
|
||||||
= case render_intent(@conn, @image, @size) do
|
= case render_intent(@conn, @image, @size) do
|
||||||
- {:hidpi, small_url, medium_url, hover_text} ->
|
- {:hidpi, small_url, medium_url, hover_text} ->
|
||||||
|
.media-box__overlay.js-spoiler-info-overlay
|
||||||
a href=link title=hover_text
|
a href=link title=hover_text
|
||||||
picture
|
picture
|
||||||
img src=small_url srcset="#{small_url} 1x, #{medium_url} 2x" alt=hover_text
|
img src=small_url srcset="#{small_url} 1x, #{medium_url} 2x" alt=hover_text
|
||||||
|
|
||||||
- {:image, small_url, hover_text} ->
|
- {:image, small_url, hover_text} ->
|
||||||
|
.media-box__overlay.js-spoiler-info-overlay
|
||||||
|
= if @image.image_mime_type == "video/webm" do
|
||||||
|
| WebM
|
||||||
|
|
||||||
a href=link title=hover_text
|
a href=link title=hover_text
|
||||||
picture
|
picture
|
||||||
img src=small_url alt=hover_text
|
img src=small_url alt=hover_text
|
||||||
|
|
||||||
- {:video, webm, mp4, hover_text} ->
|
- {:video, webm, mp4, hover_text} ->
|
||||||
|
.media-box__overlay.js-spoiler-info-overlay
|
||||||
a href=link title=hover_text
|
a href=link title=hover_text
|
||||||
video alt=hover_text autoplay="autoplay" muted="muted" loop="loop" playsinline="playsinline"
|
video alt=hover_text autoplay="autoplay" muted="muted" loop="loop" playsinline="playsinline"
|
||||||
source src=webm type="video/webm"
|
source src=webm type="video/webm"
|
||||||
|
@ -38,15 +42,18 @@
|
||||||
img alt=hover_text
|
img alt=hover_text
|
||||||
|
|
||||||
- {:filtered_image, hover_text} ->
|
- {:filtered_image, hover_text} ->
|
||||||
|
.media-box__overlay.js-spoiler-info-overlay
|
||||||
a href=link title=hover_text
|
a href=link title=hover_text
|
||||||
picture
|
picture
|
||||||
img alt=hover_text
|
img alt=hover_text
|
||||||
|
|
||||||
- {:filtered_video, hover_text} ->
|
- {:filtered_video, hover_text} ->
|
||||||
|
.media-box__overlay.js-spoiler-info-overlay
|
||||||
a href=link title=hover_text
|
a href=link title=hover_text
|
||||||
video autoplay="autoplay" muted="muted" loop="loop" playsinline="playsinline"
|
video autoplay="autoplay" muted="muted" loop="loop" playsinline="playsinline"
|
||||||
img alt=hover_text
|
img alt=hover_text
|
||||||
|
|
||||||
- :not_rendered ->
|
- :not_rendered ->
|
||||||
|
.media-box__overlay.js-spoiler-info-overlay
|
||||||
a href=link
|
a href=link
|
||||||
' Thumbnails not yet generated
|
' Thumbnails not yet generated
|
Loading…
Reference in a new issue