Effort free video editing!
Make copying a v3 a compile error
WyattBluef10e68227cf6
diff --git a/src/exports/edl.nim b/src/exports/edl.nimindex f81133df..ef13180c 100644--- a/src/exports/edl.nim+++ b/src/exports/edl.nim@@ -101,7 +101,7 @@ proc trackEvents(tl: v3, track: TrackExport, reels: Table[ptr string, string],let plan = transitionPlan(track.clips, track.transitions)let order = (if track.video: 0 else: ord(track.channel))- proc sourceAt(clip: Clip, frame: int64): int64 =+ template sourceAt(clip: Clip, frame: int64): int64 =## The source frame a clip shows at timeline `frame`, which may lie just## past its ends.let map = initSpeedMap(tl.effects[clip.effects])diff --git a/src/render/audio.nim b/src/render/audio.nimindex 49785cb7..a54ec4b1 100644--- a/src/render/audio.nim+++ b/src/render/audio.nim@@ -941,13 +941,18 @@ proc loudnormOutToChunk(outF: ptr AVFrame, channels: int): seq[int16] =if not outF.toInt16(0, outF.nb_samples.int, result, 0, channels):error &"Unexpected output format from loudnorm: {outF.format}"-proc makeAudioFrames*(fmt: AVSampleFormat, tl: v3, frameSize: int, layerIndices: seq[+proc makeAudioFrames*(fmt: AVSampleFormat, timeline: v3, frameSize: int, layerIndices: seq[int], norm: Norm,cache: MediaCache = nil, fromSample = 0, stop: ptr Atomic[bool] = nil):iterator(): (ptr AVFrame, int64) =## Samples from `fromSample` on (normalizing measures the whole timeline,## so it needs 0). A set `stop` ends the iterator at its next call, freeing## what it holds.+ # What this returns outlives the call, and capturing the timeline would+ # copy it whole. It is borrowed instead: the caller keeps it alive and+ # unmoved until done with the result.+ let tlPtr = addr timeline+ template tl: v3 = tlPtr[]# Paths are interned, so a path's pointer names its getter without a copy.var samples: Table[(ptr string, int16), Getter]diff --git a/src/render/partialplan.nim b/src/render/partialplan.nimindex 4db619d6..07609bfd 100644--- a/src/render/partialplan.nim+++ b/src/render/partialplan.nim@@ -310,9 +310,15 @@ func holdsFrames(tb, frameTb: AVRational): bool =## don't for 30 fps: a frame is 33 or 34 of them.(frameTb.num.int64 * tb.den.int64) mod (frameTb.den.int64 * tb.num.int64) == 0-proc makePartialLossless*(output: var OutputContainer, tl: v3, video: VideoSettings,+proc makePartialLossless*(output: var OutputContainer, timeline: v3,+ video: VideoSettings,spans: seq[SmartSpan], keyframes: seq[int64], codecId: AVCodecID):(ptr AVStream, iterator(): (ptr AVPacket, int64)) =+ # What this returns outlives the call, and capturing the timeline would+ # copy it whole. It is borrowed instead: the caller keeps it alive and+ # unmoved until done with the result.+ let tlPtr = addr timeline+ template tl: v3 = tlPtr[]let label = codecId.codecLabellet isNal = codecId.isNalCodeclet sourcePath = tl.v[0][0].src[]diff --git a/src/render/video.nim b/src/render/video.nimindex 5dfa4f57..c6148f5e 100644--- a/src/render/video.nim+++ b/src/render/video.nim@@ -1009,7 +1009,7 @@ func scaledVideoResolution*(resolution: (int32, int32),max(int32(round(resolution[1].float64 * scale)) and not 1'i32, 2),)-proc makeNewVideoFrames*(output: var OutputContainer, tl: v3, args: mainArgs,+proc makeNewVideoFrames*(output: var OutputContainer, timeline: v3, args: mainArgs,video: VideoSettings, myCache: MediaCache, startIndex = 0'i64,stop: ptr Atomic[bool] = nil, keep: VideoSources = nil):(ptr AVCodecContext, ptr AVStream, iterator(): (ptr AVFrame, int64)) =@@ -1017,6 +1017,11 @@ proc makeNewVideoFrames*(output: var OutputContainer, tl: v3, args: mainArgs,## call, freeing what it holds (a preview abandons a render this way).## With `keep`, sources' decoders come from it and stay in it at the end,## for the next render to pick up where this one left off.+ # What this returns outlives the call, and capturing the timeline would+ # copy it whole. It is borrowed instead: the caller keeps it alive and+ # unmoved until done with the result.+ let tlPtr = addr timeline+ template tl: v3 = tlPtr[]# One state object per source (decoders, seek bookkeeping, still/held frame# caches, loop accounting). Still-image sources (overlay logos/watermarks)diff --git a/src/timeline.nim b/src/timeline.nimindex eccee563..a5503018 100644--- a/src/timeline.nim+++ b/src/timeline.nim@@ -60,7 +60,7 @@ typekind*: TransitionKindalignment*: TransitionAlignment-type v3* = object+type v3* {.byref.} = objectlayout*: ref AVChannelLayoutres*: (int32, int32)tb*: AVRational@@ -80,6 +80,16 @@ type v3* = objectat*: seq[seq[Transition]]windows*: seq[seq[TransitionWindow]] # per video track, set by bakeTransitions+proc `=copy`*(dest: var v3, src: v3) {.error:+ "a v3 is too big to copy implicitly: move it, borrow it, or `clone` it".}+proc `=dup`*(src: v3): v3 {.error:+ "a v3 is too big to copy implicitly: move it, borrow it, or `clone` it".}++func clone*(tl: v3): v3 =+ ## The one way to copy a timeline.+ for dst, src in fields(result, tl):+ dst = src+func len*(self: v3): int64 {.raises: [].} =result = 0for clips in self.v:@@ -785,7 +795,7 @@ proc bakeTransitions*(source: v3): v3 =## Lower edit-point transitions for the native renderer to clip overlaps:## audio crossfades as gain ramps, video transitions as `windows` the## renderer blends. Exporters continue to consume the unmodified timeline.- result = source+ result = source.clonevar rampCache: Table[RampKey, uint32]var effectIndex: EffectIndex