philomena/lib/philomena/analyzers/webm.ex

30 lines
697 B
Elixir
Raw Normal View History

2019-11-26 01:06:40 +01:00
defmodule Philomena.Analyzers.Webm do
def analyze(file) do
stats = stats(file)
2019-11-26 01:06:40 +01:00
%{
extension: "webm",
mime_type: "video/webm",
2021-12-20 20:44:52 +01:00
animated?: stats.animated?,
duration: stats.duration,
dimensions: stats.dimensions
2019-11-26 01:06:40 +01:00
}
end
defp stats(file) do
case System.cmd("mediastat", [file]) do
2019-11-26 01:06:40 +01:00
{output, 0} ->
2021-12-20 20:44:52 +01:00
[_size, frames, width, height, num, den] =
2019-11-26 01:06:40 +01:00
output
|> String.trim()
|> String.split(" ")
2019-11-26 01:06:40 +01:00
|> Enum.map(&String.to_integer/1)
2021-12-20 20:44:52 +01:00
%{animated?: frames > 1, dimensions: {width, height}, duration: num / den}
2019-11-26 01:06:40 +01:00
_ ->
2021-12-20 20:44:52 +01:00
%{animated?: false, dimensions: {0, 0}, duration: 0.0}
2019-11-26 01:06:40 +01:00
end
end
2020-01-11 05:20:19 +01:00
end