From 26c1297c16432f07e05da1bb941de09a12db8fa8 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Fri, 12 Mar 2021 19:17:11 -0500 Subject: [PATCH] strip and remux uploaded videos, fixes philomena-dev/philomena#104 --- lib/philomena/processors/webm.ex | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/philomena/processors/webm.ex b/lib/philomena/processors/webm.ex index 52f81d7a..342135ce 100644 --- a/lib/philomena/processors/webm.ex +++ b/lib/philomena/processors/webm.ex @@ -5,16 +5,18 @@ defmodule Philomena.Processors.Webm do def process(analysis, file, versions) do dimensions = analysis.dimensions duration = analysis.duration - preview = preview(duration, file) - palette = gif_palette(file, duration) - mp4 = scale_mp4_only(file, dimensions, dimensions) + stripped = strip(file) + preview = preview(duration, stripped) + palette = gif_palette(stripped, duration) + mp4 = scale_mp4_only(stripped, dimensions, dimensions) {:ok, intensities} = Intensities.file(preview) 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, thumbnails: scaled ++ [{:copy, preview, "rendered.png"}] } @@ -35,6 +37,28 @@ defmodule Philomena.Processors.Webm do preview 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 [ {:symlink_original, "full.webm"},