mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
require mediastat for video processing, increase muxq
This commit is contained in:
parent
7fcc1ec4bf
commit
2683dddb4c
3 changed files with 20 additions and 43 deletions
|
@ -7,11 +7,12 @@ RUN apt-get update; \
|
||||||
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -; \
|
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 -; \
|
wget -qO - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -; \
|
||||||
apt-get update; \
|
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; \
|
cd /tmp; \
|
||||||
git clone https://github.com/derpibooru/cli_intensities; \
|
git clone https://github.com/derpibooru/cli_intensities; \
|
||||||
cd cli_intensities; \
|
git clone https://github.com/derpibooru/mediatools; \
|
||||||
make install; \
|
(cd cli_intensities && make install); \
|
||||||
|
(cd mediatools && make install); \
|
||||||
mix local.hex --force; \
|
mix local.hex --force; \
|
||||||
mix local.rebar --force
|
mix local.rebar --force
|
||||||
|
|
||||||
|
|
|
@ -1,57 +1,29 @@
|
||||||
defmodule Philomena.Analyzers.Webm do
|
defmodule Philomena.Analyzers.Webm do
|
||||||
def analyze(file) do
|
def analyze(file) do
|
||||||
|
stats = stats(file)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
extension: "webm",
|
extension: "webm",
|
||||||
mime_type: "video/webm",
|
mime_type: "video/webm",
|
||||||
animated?: true,
|
animated?: true,
|
||||||
duration: duration(file),
|
duration: stats.duration,
|
||||||
dimensions: dimensions(file)
|
dimensions: stats.dimensions
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp duration(file) do
|
defp stats(file) do
|
||||||
with {output, 0} <-
|
case System.cmd("mediastat", [file]) do
|
||||||
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
|
|
||||||
{output, 0} ->
|
{output, 0} ->
|
||||||
[width, height] =
|
[_size, _frames, width, height, num, den] =
|
||||||
output
|
output
|
||||||
|> String.trim()
|
|> String.trim()
|
||||||
|> String.split(",")
|
|> String.split(" ")
|
||||||
|> Enum.map(&String.to_integer/1)
|
|> 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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -112,6 +112,8 @@ defmodule Philomena.Processors.Webm do
|
||||||
scale_filter,
|
scale_filter,
|
||||||
"-threads",
|
"-threads",
|
||||||
"1",
|
"1",
|
||||||
|
"-max_muxing_queue_size",
|
||||||
|
"512",
|
||||||
webm
|
webm
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -138,6 +140,8 @@ defmodule Philomena.Processors.Webm do
|
||||||
scale_filter,
|
scale_filter,
|
||||||
"-threads",
|
"-threads",
|
||||||
"1",
|
"1",
|
||||||
|
"-max_muxing_queue_size",
|
||||||
|
"512",
|
||||||
mp4
|
mp4
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -148,7 +152,7 @@ defmodule Philomena.Processors.Webm 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"
|
||||||
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}"
|
filter_graph = "[0:v] #{scale_filter},#{rate_filter} [x]; [x][1:v] #{palette_filter}"
|
||||||
|
|
||||||
{_output, 0} =
|
{_output, 0} =
|
||||||
|
|
Loading…
Reference in a new issue