Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/mediaproc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ADD https://api.github.com/repos/philomena-dev/mediatools/git/refs/heads/master

RUN wget -qO /tmp/FFmpeg.tar.gz https://github.com/philomena-dev/FFmpeg/archive/refs/heads/release/8.0.tar.gz \
&& wget -qO /tmp/cli_intensities.tar.gz https://github.com/philomena-dev/cli_intensities/archive/refs/heads/master.tar.gz \
&& wget -qO /tmp/mediatools.tar.gz https://github.com/philomena-dev/mediatools/archive/refs/heads/master.tar.gz
&& wget -qO /tmp/mediatools.tar.gz https://github.com/philomena-dev/mediatools/archive/refs/tags/1.2.3.tar.gz

RUN cd /tmp \
&& tar -xf FFmpeg.tar.gz \
Expand Down Expand Up @@ -57,7 +57,7 @@ RUN cd /tmp \
&& make -j$(nproc) install \
&& cd /tmp/cli_intensities-master \
&& make -j$(nproc) install \
&& cd /tmp/mediatools-master \
&& cd /tmp/mediatools-1.2.3 \
&& make -j$(nproc) install

COPY native/philomena /tmp/philomena
Expand Down
8 changes: 6 additions & 2 deletions lib/philomena/images/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ defmodule Philomena.Images.Image do
:image_size,
:image_width,
:image_height,
:image_aspect_ratio
:image_aspect_ratio,
:image_is_animated,
:image_duration
])
|> change(thumbnails_generated: true, duplication_checked: true)
end
Expand All @@ -254,7 +256,9 @@ defmodule Philomena.Images.Image do
:image_size,
:image_width,
:image_height,
:image_aspect_ratio
:image_aspect_ratio,
:image_is_animated,
:image_duration
])
|> change(processed: true)
end
Expand Down
8 changes: 6 additions & 2 deletions lib/philomena/images/thumbnailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,19 @@ defmodule Philomena.Images.Thumbnailer do
end

defp recompute_meta(image, file, changeset_fn) do
{:ok, %{dimensions: {width, height}}} = Analyzers.analyze_path(file)
{:ok, analysis} = Analyzers.analyze_path(file)

%{dimensions: {width, height}} = analysis

image
|> changeset_fn.(%{
"image_sha512_hash" => Sha512.file(file),
"image_size" => File.stat!(file).size,
"image_width" => width,
"image_height" => height,
"image_aspect_ratio" => width / height
"image_aspect_ratio" => width / height,
"image_is_animated" => analysis.animated?,
"image_duration" => analysis.duration
})
|> Repo.update!()
end
Expand Down
1 change: 1 addition & 0 deletions lib/philomena_media/analyzers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defmodule PhilomenaMedia.Analyzers do
:error = Analyzers.analyze_path(file)

"""
@spec analyze_path(Path.t()) :: {:ok, Result.t()} | {:unsupported_mime, Mime.t()}
def analyze_path(path) when is_binary(path) do
with {:ok, mime} <- Mime.file(path),
{:ok, analyzer} <- analyzer(mime) do
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena_media/analyzers/gif.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule PhilomenaMedia.Analyzers.Gif do
defp stats(file) do
case Remote.cmd("mediastat", [file]) do
{output, 0} ->
[_size, frames, width, height, num, den] =
[_animated, frames, width, height, num, den] =
output
|> String.trim()
|> String.split(" ")
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena_media/analyzers/jpeg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule PhilomenaMedia.Analyzers.Jpeg do
defp stats(file) do
case Remote.cmd("mediastat", [file]) do
{output, 0} ->
[_size, _frames, width, height, num, den] =
[_animated, _frames, width, height, num, den] =
output
|> String.trim()
|> String.split(" ")
Expand Down
4 changes: 2 additions & 2 deletions lib/philomena_media/analyzers/png.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ defmodule PhilomenaMedia.Analyzers.Png do
defp stats(file) do
case Remote.cmd("mediastat", [file]) do
{output, 0} ->
[_size, frames, width, height, num, den] =
[animated, _frames, width, height, num, den] =
output
|> String.trim()
|> String.split(" ")
|> Enum.map(&String.to_integer/1)

%{animated?: frames > 1, dimensions: {width, height}, duration: num / den}
%{animated?: animated != 0, dimensions: {width, height}, duration: num / den}

_ ->
%{animated?: false, dimensions: {0, 0}, duration: 0.0}
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena_media/analyzers/svg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule PhilomenaMedia.Analyzers.Svg do
defp stats(file) do
case Remote.cmd("svgstat", [file]) do
{output, 0} ->
[_size, _frames, width, height, _num, _den] =
[_animated, _frames, width, height, _num, _den] =
output
|> String.trim()
|> String.split(" ")
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena_media/analyzers/webm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule PhilomenaMedia.Analyzers.Webm do
defp stats(file) do
case Remote.cmd("mediastat", [file]) do
{output, 0} ->
[_size, frames, width, height, num, den] =
[_animated, frames, width, height, num, den] =
output
|> String.trim()
|> String.split(" ")
Expand Down
37 changes: 32 additions & 5 deletions lib/philomena_media/processors/png.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule PhilomenaMedia.Processors.Png do
@moduledoc false

alias PhilomenaMedia.Intensities
alias PhilomenaMedia.Analyzers
alias PhilomenaMedia.Analyzers.Result
alias PhilomenaMedia.Remote
alias PhilomenaMedia.Processors.Processor
Expand All @@ -17,9 +18,7 @@ defmodule PhilomenaMedia.Processors.Png do

@spec process(Result.t(), Path.t(), Processors.version_list()) :: Processors.edit_script()
def process(analysis, file, versions) do
animated? = analysis.animated?

stripped = strip(file, animated?)
{stripped, animated?} = strip(file, analysis.animated?)

{:ok, intensities} = Intensities.file(stripped)

Expand Down Expand Up @@ -55,8 +54,36 @@ defmodule PhilomenaMedia.Processors.Png do
intensities
end

defp strip(file, true = _animated?), do: file
defp strip(file, _animated?), do: Strip.strip(file, ".png")
@spec strip(Path.t(), boolean()) :: {Path.t(), boolean()}
defp strip(file, false = animated?), do: {Strip.strip(file, ".png"), animated?}

defp strip(file, _animated?) do
stripped = Briefly.create!(extname: ".png")

# Transcode animated PNG to normalize the format
{_output, 0} =
Remote.cmd("ffmpeg", [
"-loglevel",
"0",
"-y",
"-i",
file,
"-plays",
"0",
"-f",
"apng",
stripped
])

analysis = Analyzers.Png.analyze(stripped)

if analysis.animated? do
{stripped, analysis.animated?}
else
# If not considered animated after normalization, perform strip
{Strip.strip(stripped, ".png"), analysis.animated?}
end
end

# Sobelow misidentifies removing the .bak file
# sobelow_skip ["Traversal.FileModule"]
Expand Down
Loading