Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an artefact occuring if the position of an overlay is not :center or (0, 0). Bump to v0.1.1 #2

Merged
merged 3 commits into from
Mar 15, 2024
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The package can be installed by adding `membrane_overlay_plugin` to your list of
```elixir
def deps do
[
{:membrane_overlay_plugin, "~> 0.1.0"}
{:membrane_overlay_plugin, "~> 0.1.1"}
]
end
```
Expand Down
19 changes: 14 additions & 5 deletions lib/membrane_overlay_filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ defmodule Membrane.OverlayFilter do

@impl true
def handle_init(_ctx, options) do
opts_y = options |> Map.take([:x, :y, :blend_mode]) |> Enum.to_list()
uv_x = if is_integer(options.x), do: div(options.x, 2), else: options.x
uv_y = if is_integer(options.y), do: div(options.y, 2), else: options.y
opts_uv = [x: uv_x, y: uv_y, blend_mode: options.blend_mode]

state = %{
overlay_planes: open_overlay(options.overlay),
compose_options: options |> Map.take([:x, :y, :blend_mode]) |> Enum.to_list()
compose_options: {opts_y, opts_uv}
}

{[], state}
Expand Down Expand Up @@ -99,10 +104,14 @@ defmodule Membrane.OverlayFilter do
{y, u, v}
end

defp compose_planes({image_y, image_u, image_v}, {overlay_y, overlay_u, overlay_v}, opts) do
composed_y = compose_plane(image_y, overlay_y, opts)
composed_u = compose_plane(image_u, overlay_u, opts)
composed_v = compose_plane(image_v, overlay_v, opts)
defp compose_planes(
{image_y, image_u, image_v},
{overlay_y, overlay_u, overlay_v},
{opts_y, opts_uv}
) do
composed_y = compose_plane(image_y, overlay_y, opts_y)
composed_u = compose_plane(image_u, overlay_u, opts_uv)
composed_v = compose_plane(image_v, overlay_v, opts_uv)
composed_y <> composed_u <> composed_v
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Membrane.Overlay.Plugin.Mixfile do
use Mix.Project

@version "0.1.0"
@version "0.1.1"
@github_url "https://github.com/membraneframework/membrane_overlay_plugin"

def project do
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output.yuv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/fixtures/output_center.yuv

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions test/membrane_overlay_filter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ defmodule Membrane.OverlayFilterTest do
import Membrane.Testing.Assertions
alias Membrane.Testing

test "applies overlay on top of a YUV frame" do
test "applies overlay on a given position of a YUV frame" do
pipeline =
Testing.Pipeline.start_link_supervised!(
spec:
child(%Testing.Source{
output: [File.read!("test/fixtures/frame.yuv")]
})
|> child(%Membrane.RawVideo.Parser{width: 1920, height: 1080, pixel_format: :I420})
|> child(%Membrane.OverlayFilter{overlay: "test/fixtures/overlay.png"})
|> child(%Membrane.OverlayFilter{overlay: "test/fixtures/overlay.png", x: 200, y: 100})
|> child(:sink, Membrane.Testing.Sink)
)

Expand All @@ -21,4 +21,26 @@ defmodule Membrane.OverlayFilterTest do

Testing.Pipeline.terminate(pipeline)
end

test "applies overlay on a center of a YUV frame" do
pipeline =
Testing.Pipeline.start_link_supervised!(
spec:
child(%Testing.Source{
output: [File.read!("test/fixtures/frame.yuv")]
})
|> child(%Membrane.RawVideo.Parser{width: 1920, height: 1080, pixel_format: :I420})
|> child(%Membrane.OverlayFilter{
overlay: "test/fixtures/overlay.png",
x: :middle,
y: :center
})
|> child(:sink, Membrane.Testing.Sink)
)

assert_sink_buffer(pipeline, :sink, buffer)
assert buffer.payload == File.read!("test/fixtures/output_center.yuv")

Testing.Pipeline.terminate(pipeline)
end
end