80 lines
2.7 KiB
Elixir
80 lines
2.7 KiB
Elixir
defmodule Bright.ImagesTest do
|
|
use Bright.DataCase
|
|
|
|
require Logger
|
|
alias Bright.Images
|
|
|
|
@test_mp4_fixture "./test/fixtures/SampleVideo_1280x720_1mb.mp4"
|
|
@test_ts_fixture "./test/fixtures/test-fixture.ts"
|
|
|
|
describe "thumbnails" do
|
|
@tag :unit
|
|
test "create_thumbnail/1" do
|
|
{:ok, filename} =
|
|
Images.create_thumbnail(@test_mp4_fixture)
|
|
|
|
assert Regex.match?(~r/^\/root\/\.cache\/futureporn\/[^\/]+\/[^\/]+\.png$/, filename)
|
|
assert File.exists?(filename)
|
|
assert File.stat!(filename).size > 0, "thumbnail file is empty"
|
|
end
|
|
|
|
@tag :unit
|
|
test "create_thumbnail/2" do
|
|
# ffmpeg -y -i ~/Videos/moose-encounter_75.mp4 -frames:v 1 -vf 'select=not(mod(n\,257)),scale=160:-1,tile=5x5' -update 1 -fps_mode passthrough ~/Videos/thumb.jpg
|
|
|
|
basename = "thumb.jpg"
|
|
|
|
random_string =
|
|
for _ <- 1..12,
|
|
into: "",
|
|
do:
|
|
<<Enum.random(~c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")>>
|
|
|
|
output_file = "/tmp/#{random_string}-#{basename}"
|
|
|
|
Logger.debug(
|
|
"output_file=#{inspect(output_file)} @test_mp4_fixture=#{inspect(@test_mp4_fixture)}"
|
|
)
|
|
|
|
{:ok, output} = Images.create_thumbnail(@test_mp4_fixture, output_file)
|
|
|
|
assert File.exists?(output_file)
|
|
{:ok, stat} = File.stat(output_file)
|
|
assert stat.size > 0, "File is empty"
|
|
assert output === output_file
|
|
end
|
|
|
|
# Feature creep! Download the image for now. Make it work, first. THen make it right. THEN make it fast.
|
|
# test "should generate a 5x5 thumbnail using a remote file" do
|
|
# basename = "thumb.jpg"
|
|
# random_string = for _ <- 1..12, into: "", do: <<Enum.random(~c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")>>
|
|
# output_file = "/tmp/#{random_string}-#{basename}"
|
|
# input_url = "http://38.242.193.246:8081/fixtures/2024-12-19T03-14-03Z.ts"
|
|
# {:ok, output} = Images.create_thumbnail(input_url, output_file)
|
|
# assert Regex.match?("/tmp", output)
|
|
# end
|
|
end
|
|
|
|
describe "get_video_duration" do
|
|
@tag :integration
|
|
test "should get video stream duration" do
|
|
{:ok, duration} = Images.get_video_duration(@test_mp4_fixture)
|
|
assert duration === "5.280000"
|
|
end
|
|
end
|
|
|
|
describe "get_video_framecount" do
|
|
@tag :integration
|
|
test "should get video frame count from a mp4 which contains framecount in metadata" do
|
|
{:ok, nb_frames} = Images.get_video_framecount(@test_mp4_fixture)
|
|
assert nb_frames === 132
|
|
end
|
|
|
|
@tag :integration
|
|
test "should get video frame count from a ts which does not contain framecount in metadata" do
|
|
{:ok, nb_read_frames} = Images.get_video_framecount(@test_ts_fixture)
|
|
assert nb_read_frames === 99
|
|
end
|
|
end
|
|
end
|