Skip to content

Effort free video editing!

Place a bottom clip that has a pos

WyattBlue5324ea74ae06
diff --git a/docs/src/docs/actions.md b/docs/src/docs/actions.md
index dc414bd1..4c355b14 100644
--- a/docs/src/docs/actions.md
+++ b/docs/src/docs/actions.md
@@ -344,14 +344,15 @@ auto-editor video.mp4 -w:1 confine:400:300:200:80,blur:30
### pos
-Place this clip as an overlay when it is composited over a lower video track,
+Place this clip as an overlay, composited over the video tracks below it,
`pos:x:y[:scale]`:
- **x**, **y** — the overlay's top-left corner, in canvas pixels.
- **scale** — optional size multiplier of the source's native size (default
`1.0`).
-`pos` has no effect on the base (bottom) track. It is mainly used inside a v3
+A clip with nothing under it is placed over the background color. Without a
+`pos`, the bottom clip fills the canvas instead. It is mainly used inside a v3
timeline's effects array (see [The v3 format](./v3)) or attached automatically by
the `add` action below.
diff --git a/docs/src/docs/v3.md b/docs/src/docs/v3.md
index bf795b47..26aceceb 100644
--- a/docs/src/docs/v3.md
+++ b/docs/src/docs/v3.md
@@ -101,7 +101,7 @@ interface Clip {
```
## Compositing layers
-When more than one video track has a clip active at the same timeline frame, the tracks are composited bottom-to-top: `v[0]` is the base layer and later tracks (`v[1]`, `v[2]`, ...) are painted on top. The base layer fills the canvas (its source is fit to `resolution`). Each higher layer is placed by a `pos:x:y[:scale]` effect in its `effects` array — `x`/`y` are the top-left corner in canvas pixels and `scale` (default `1.0`) multiplies the source's native size. Without a `pos` effect, an overlay is scaled to fit the canvas (preserving aspect ratio) and centered, like a full-frame layer. Other per-clip `effects` are applied to each clip before it is composited.
+When more than one video track has a clip active at the same timeline frame, the tracks are composited bottom-to-top: `v[0]` is the base layer and later tracks (`v[1]`, `v[2]`, ...) are painted on top. The base layer fills the canvas (its source is fit to `resolution`). Each higher layer is placed by a `pos:x:y[:scale]` effect in its `effects` array — `x`/`y` are the top-left corner in canvas pixels and `scale` (default `1.0`) multiplies the source's native size. Without a `pos` effect, an overlay is scaled to fit the canvas (preserving aspect ratio) and centered, like a full-frame layer. A `pos` places the base layer's clip too, over the `background` color, rather than letting it fill the canvas. Other per-clip `effects` are applied to each clip before it is composited.
Still images (PNG, JPG, BMP, TIFF, ...) may be used as a `src`; the single image is held for the clip's whole `dur`, which is convenient for logos and watermarks. Overlay transparency (e.g. a PNG alpha channel) is preserved.
diff --git a/src/render/video.nim b/src/render/video.nim
index c85430b0..3d3369ab 100644
--- a/src/render/video.nim
+++ b/src/render/video.nim
@@ -2234,6 +2234,11 @@ proc makeNewVideoFrames*(output: var OutputContainer, tl: v3, args: mainArgs,
result = overlayFrame(acc, top, ox, oy, oscale)
av_frame_free(addr top)
+ func placed(o: VideoFrame): bool =
+ ## A clip with a `pos` goes where it says even with nothing under it,
+ ## over the background, rather than filling the canvas as a base.
+ not o.fit
+
# Each layer's clips by start, and those started but not yet ended, so a
# frame looks only at the clips under it instead of every clip in the layer.
var byStart = newSeq[seq[int]](tl.v.len)
@@ -2340,9 +2345,10 @@ proc makeNewVideoFrames*(output: var OutputContainer, tl: v3, args: mainArgs,
let fps = (if rate.isValid: rate.float / tl.tb.float else: 1.0)
let last = int(ceil(float(obj.offset + obj.dur) * speed * fps - 1e-3)) - 1
i = min(i, max(last, 0))
- # nil src: the `-bg` canvas on the base track, a generator above it.
+ # nil src: the `-bg` canvas on the base track, a generator above it
+ # or where a `pos` places it.
objList.add VideoFrame(index: i, src: obj.src, effects: effectGroup,
- gen: obj.src == nil and layerIdx > 0,
+ gen: obj.src == nil and (layerIdx > 0 or hasPos),
local: int(index - obj.start), dur: int(obj.dur),
srcSecs: timelinePos * speed / tl.tb.float,
x: ox, y: oy, scale: oscale, fit: not hasPos, layer: layerIdx)
@@ -2367,16 +2373,18 @@ proc makeNewVideoFrames*(output: var OutputContainer, tl: v3, args: mainArgs,
var inWindow = false
for o in objList:
if o.win >= 0: inWindow = true
- if objList.len > 1 or inWindow:
+ if objList.len > 1 or inWindow or (objList.len == 1 and placed(objList[0])):
av_frame_free(addr frame)
var acc: ptr AVFrame = nil
var k = 0
while k < objList.len:
let o = objList[k]
if o.win < 0:
- if acc == nil:
+ if acc == nil and not placed(o):
acc = baseFrame(o)
else:
+ if acc == nil:
+ acc = makeSolid(tl.res[0], tl.res[1], tl.bg, solidTag)
let newAcc = overlayObj(acc, o)
if newAcc != nil:
av_frame_free(addr acc)
@@ -2395,7 +2403,7 @@ proc makeNewVideoFrames*(output: var OutputContainer, tl: v3, args: mainArgs,
var fromF, toF: ptr AVFrame = nil
for m in k ..< j:
var f =
- if isBase: baseFrame(objList[m])
+ if isBase and not placed(objList[m]): baseFrame(objList[m])
else: overlayObj(below, objList[m])
if f == nil: f = av_frame_clone(below)
if objList[m].incoming: