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

Add virtual video.canvas for positioning video elements independently of the frame size. #3656

Merged
merged 16 commits into from
Jan 30, 2024
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
- id: ocamlformat

- repo: https://github.com/savonet/pre-commit-liquidsoap
rev: 5fadc94
rev: 1e33b9e
hooks:
- id: liquidsoap-prettier

Expand Down
33 changes: 33 additions & 0 deletions doc/content/liq/video-canvas-example.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
background = blank()

# BEGIN
# Change to video.canvas.virtual_10k.actual_720p etc.. to render
# in different sizes without changing the values below!
let {px, rem, vh, vw, width, height} = video.canvas.virtual_10k.actual_1080p

video.frame.width := width
video.frame.height := height

background =
video.add_image(
x=0.3 @ vw,
y=0.01 @ vh,
width=1562 @ px,
height=1562 @ px,
file="/path/to/cover.jpg",
background
)

background =
video.add_text(
color=0xFCB900,
speed=0,
x=234 @ px,
y=4437 @ px,
size=1.5 @ rem,
"Some text",
background
)
# END

output.dummy(fallible=true, background)
21 changes: 21 additions & 0 deletions doc/content/liq/video-default-canvas.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Standard video canvas based off a `10k` virtual canvas.
# @category Source / Video processing
def video.canvas.virtual_10k =
def make(width, height) =
video.canvas.make(
virtual_width=10000,
actual_size={width=width, height=height},
font_size=160
)
end

{
actual_360p=make(640, 360),
actual_480p=make(640, 480),
actual_720p=make(1280, 720),
actual_1080p=make(1920, 1080),
actual_1440p=make(2560, 1440),
actual_4k=make(3840, 2160),
actual_8k=make(7680, 4320)
}
end
33 changes: 33 additions & 0 deletions doc/content/video.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ size of videos have a great impact on computations; if your machine cannot
handle a stream (i.e. it's always catching up) you can try to encode to smaller
videos for a start.

### Setting up frame size and positions

We provide an abstract API to specify video frame sizes and positions that is idependent
from the actual rendered size. This way, you can define all your elements and have them
being rendered at different frame size without having to change their placement or size values!

This works by setting up a _virtual canvas_ that is larger than the _actual canvas_. You specify
your positions, sizes etc. in terms of units for the larger canvas and they are translated automatically
to values that apply for the actual canvas.

We provide some default values. They are all `16:9` ratio using a virtual canvas of `10 000` pixels height:

```{.liquidsoap include="video-default-canvas.liq"}

```

The returned canvas is a record with the following methods:

- `width`/`height`: size of the actual frame
- `px`: define values in terms of virtual pixels
- `vw`/`vh`: define values in terms of percentage (between `0.` and `1.`) of, resp., the actual frame width and height
- `rem`: define values in terms of percentage (between `0.` and `1.`) of the default font size

All the positioning methods are functions. For convenience, you can use the infix operator `@` to make things more readable. For instance,
instead of writing `px(120)` to define a size of `120px`, you can write: `120 @ px`. These two notations are equivalent but the second
one is more readable in this context.

Here's an example of how to use this:

```{.liquidsoap include="video-canvas-example.liq"}

```

### Encoding with FFmpeg

The `%ffmpeg` encoder is the recommended encoder when working with video. Not only does it support a wide range
Expand Down
8 changes: 4 additions & 4 deletions doc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
(include dune.inc)

(rule
(alias dummytest)
(package liquidsoap)
(action (run %{bin:liquidsoap} --version))
)
(alias dummytest)
(package liquidsoap)
(action
(run %{bin:liquidsoap} --version)))

(executable
(name gen_dune)
Expand Down
Loading
Loading