strip and remux uploaded videos, fixes philomena-dev/philomena#104

This commit is contained in:
byte[] 2021-03-12 19:17:11 -05:00
parent efa1e6172a
commit 26c1297c16

View file

@ -5,16 +5,18 @@ defmodule Philomena.Processors.Webm do
def process(analysis, file, versions) do def process(analysis, file, versions) do
dimensions = analysis.dimensions dimensions = analysis.dimensions
duration = analysis.duration duration = analysis.duration
preview = preview(duration, file) stripped = strip(file)
palette = gif_palette(file, duration) preview = preview(duration, stripped)
mp4 = scale_mp4_only(file, dimensions, dimensions) palette = gif_palette(stripped, duration)
mp4 = scale_mp4_only(stripped, dimensions, dimensions)
{:ok, intensities} = Intensities.file(preview) {:ok, intensities} = Intensities.file(preview)
scaled = scaled =
Enum.flat_map(versions, &scale_if_smaller(file, mp4, palette, duration, dimensions, &1)) Enum.flat_map(versions, &scale_if_smaller(stripped, mp4, palette, duration, dimensions, &1))
%{ %{
replace_original: stripped,
intensities: intensities, intensities: intensities,
thumbnails: scaled ++ [{:copy, preview, "rendered.png"}] thumbnails: scaled ++ [{:copy, preview, "rendered.png"}]
} }
@ -35,6 +37,28 @@ defmodule Philomena.Processors.Webm do
preview preview
end end
defp strip(file) do
stripped = Briefly.create!(extname: ".webm")
{_output, 0} =
System.cmd("ffmpeg", [
"-loglevel",
"0",
"-y",
"-i",
file,
"-map_metadata",
"-1",
"-c",
"copy",
"-map",
"0",
stripped
])
stripped
end
defp scale_if_smaller(_file, mp4, _palette, _duration, _dimensions, {:full, _target_dim}) do defp scale_if_smaller(_file, mp4, _palette, _duration, _dimensions, {:full, _target_dim}) do
[ [
{:symlink_original, "full.webm"}, {:symlink_original, "full.webm"},