From 2683dddb4c1e9a5161757a5c92843ec27c0720f6 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Thu, 14 May 2020 17:18:14 -0400 Subject: [PATCH] require mediastat for video processing, increase muxq --- docker/app/Dockerfile | 7 +++-- lib/philomena/analyzers/webm.ex | 50 +++++++------------------------- lib/philomena/processors/webm.ex | 6 +++- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index 7de35815..7d85b061 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -7,11 +7,12 @@ RUN apt-get update; \ wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -; \ wget -qO - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -; \ apt-get update; \ - apt-get -qq -y install inotify-tools postgresql-client build-essential git ffmpeg nodejs libmagic-dev libpng-dev gifsicle optipng libjpeg-progs librsvg2-bin; \ + apt-get -qq -y install inotify-tools postgresql-client build-essential git ffmpeg libavformat-dev libavcodec-dev nodejs libmagic-dev libpng-dev gifsicle optipng libjpeg-progs librsvg2-bin; \ cd /tmp; \ git clone https://github.com/derpibooru/cli_intensities; \ - cd cli_intensities; \ - make install; \ + git clone https://github.com/derpibooru/mediatools; \ + (cd cli_intensities && make install); \ + (cd mediatools && make install); \ mix local.hex --force; \ mix local.rebar --force diff --git a/lib/philomena/analyzers/webm.ex b/lib/philomena/analyzers/webm.ex index f139a6fc..2d670832 100644 --- a/lib/philomena/analyzers/webm.ex +++ b/lib/philomena/analyzers/webm.ex @@ -1,57 +1,29 @@ defmodule Philomena.Analyzers.Webm do def analyze(file) do + stats = stats(file) + %{ extension: "webm", mime_type: "video/webm", animated?: true, - duration: duration(file), - dimensions: dimensions(file) + duration: stats.duration, + dimensions: stats.dimensions } end - defp duration(file) do - with {output, 0} <- - System.cmd("ffprobe", [ - "-i", - file, - "-show_entries", - "format=duration", - "-v", - "quiet", - "-of", - "csv=p=0" - ]), - {duration, _} <- Float.parse(output) do - duration - else - _ -> - 0.0 - end - end - - defp dimensions(file) do - System.cmd("ffprobe", [ - "-i", - file, - "-show_entries", - "stream=width,height", - "-v", - "quiet", - "-of", - "csv=p=0" - ]) - |> case do + defp stats(file) do + case System.cmd("mediastat", [file]) do {output, 0} -> - [width, height] = + [_size, _frames, width, height, num, den] = output |> String.trim() - |> String.split(",") + |> String.split(" ") |> Enum.map(&String.to_integer/1) - {width, height} + %{dimensions: {width, height}, duration: num / den} - _error -> - {0, 0} + _ -> + %{dimensions: {0, 0}, duration: 0.0} end end end diff --git a/lib/philomena/processors/webm.ex b/lib/philomena/processors/webm.ex index ab6ede88..06c4424c 100644 --- a/lib/philomena/processors/webm.ex +++ b/lib/philomena/processors/webm.ex @@ -112,6 +112,8 @@ defmodule Philomena.Processors.Webm do scale_filter, "-threads", "1", + "-max_muxing_queue_size", + "512", webm ]) @@ -138,6 +140,8 @@ defmodule Philomena.Processors.Webm do scale_filter, "-threads", "1", + "-max_muxing_queue_size", + "512", mp4 ]) @@ -148,7 +152,7 @@ defmodule Philomena.Processors.Webm do gif = Briefly.create!(extname: ".gif") scale_filter = "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease" palette_filter = "paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" - rate_filter = "fps=1/#{duration / 10},settb=1/2,setpts=N" + rate_filter = "setpts=N/TB/2" filter_graph = "[0:v] #{scale_filter},#{rate_filter} [x]; [x][1:v] #{palette_filter}" {_output, 0} =