Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

NEST10: a nest's sound follows its speed, direction and effects; its captions are part of its picture

justjohn12345a8b803c7a94f
diff --git a/crates/render/src/audio.rs b/crates/render/src/audio.rs
index 794e12e25..9c770890d 100644
--- a/crates/render/src/audio.rs
+++ b/crates/render/src/audio.rs
@@ -186,13 +186,29 @@ fn mix_item(
let w = out.channels.len();
let n = (a1 - a0) as usize;
let buf = if let Some(nested) = project.sequence(item.item) {
- nested_audio(project, item, nested, a0, n, sr, sources, w, live.depth)
+ // Past the depth limit a nest is silent, like its picture is empty, so a sequence that
+ // contains itself (a damaged project; the editor refuses to make one) cannot recurse
+ // without end.
+ if live.depth >= crate::MAX_NEST_DEPTH {
+ return;
+ }
+ // A multi-camera clip plays the audio of its source's audio setting: camera 1, all
+ // cameras, or (when switching audio) the angle the clip selects.
+ let q = if nested.multicam.is_some() {
+ std::borrow::Cow::Owned(nested.with_angle_audio(item.multicam_angle(nested)))
+ } else {
+ std::borrow::Cow::Borrowed(nested)
+ };
+ // The nested sequence is the clip's source: speed, reverse and clip effects apply to its
+ // mix exactly as they do to a media clip's sound.
+ let read = |m0: i64, len: usize| Some(nested_mix(project, &q, m0, len, sr, sources, w, live.depth));
+ effected(item, &read, a0, n, sr, w)
} else {
let Some(src) = sources.source(item.item) else { return };
if !src.info().has_audio() {
return;
}
- effected(item, src.as_ref(), a0, n, sr, w)
+ effected(item, &|m0, len| src.audio(m0, len, sr).ok(), a0, n, sr, w)
};
// gains: clip gain × Volume (keyframed, per 64-sample block) × channel volume × panner
let clip_gain = db_to_gain(item.gain_db);
@@ -243,42 +259,54 @@ fn mix_item(
}
}
-/// A nested sequence's mix for timeline samples `[a0, a0 + n)` of the clip that shows it, at width
-/// `w`. A multi-camera clip plays the audio of its source's audio setting: camera 1, all cameras,
-/// or (when switching audio) the angle the clip selects. `depth` is the nesting depth of the clip's
-/// own sequence: past [`crate::MAX_NEST_DEPTH`] the nest is silent, like its picture is empty, so a
-/// sequence that contains itself (a damaged project; the editor refuses to make one) cannot
-/// recurse without end.
+/// `len` samples of a nested sequence's mix starting at sample `m0` of its own time, counted at
+/// `sr` (the rate of the sequence the nest is in), as `w` channels. The nested sequence is mixed at
+/// its own sample rate and converted when the two differ; time before its start is silent.
+/// `depth` is the nesting depth of the sequence the nest is in.
#[allow(clippy::too_many_arguments)]
-fn nested_audio(
- project: &Project,
- item: &TrackItem,
- nested: &Sequence,
- a0: i64,
- n: usize,
- sr: u32,
- sources: &dyn SourceProvider,
- w: usize,
- depth: u32,
-) -> Vec<Vec<f32>> {
- if depth >= crate::MAX_NEST_DEPTH {
- return vec![vec![0.0; n]; w];
+fn nested_mix(project: &Project, nested: &Sequence, m0: i64, len: usize, sr: u32, sources: &dyn SourceProvider, w: usize, depth: u32) -> AudioBuffer {
+ let own = nested.settings.sample_rate.max(1);
+ let sr = sr.max(1);
+ // the nested sequence's samples that cover [m0, m0 + len) at `sr`
+ let at = |i: i64| i as f64 * own as f64 / sr as f64;
+ let first = if own == sr { m0 } else { at(m0).floor() as i64 };
+ let count = if own == sr { len } else { (at(m0.saturating_add(len as i64)).ceil() as i64).saturating_sub(first).max(0) as usize + 2 };
+ // nothing plays before the sequence starts
+ let lead = first.min(0).unsigned_abs().min(count as u64) as usize;
+ let mut mix = AudioBuffer::silence(own, w, count);
+ if count > lead {
+ let b = crate::mixer::mix_graph_at(project, nested, first + lead as i64, count - lead, sources, None, depth + 1);
+ let b = to_layout(b, Layout::from_channels(w), Mixdown::FrontRear);
+ for (dst, src) in mix.channels.iter_mut().zip(&b.channels) {
+ let m = src.len().min(count - lead);
+ dst[lead..lead + m].copy_from_slice(&src[..m]);
+ }
}
- let rel0 = a0 - item.start.to_units_floor(sr as i64) + item.source_in.to_units_floor(sr as i64);
- let q = if nested.multicam.is_some() {
- std::borrow::Cow::Owned(nested.with_angle_audio(item.multicam_angle(nested)))
- } else {
- std::borrow::Cow::Borrowed(nested)
- };
- let b = crate::mixer::mix_graph_at(project, &q, rel0, n, sources, None, depth + 1);
- let mut v = to_layout(b, Layout::from_channels(w), Mixdown::FrontRear).channels;
- v.resize(w, vec![0.0; n]);
- v
+ if own == sr {
+ mix.sample_rate = sr;
+ return mix;
+ }
+ let mut out = AudioBuffer::silence(sr, w, len);
+ for (dst, src) in out.channels.iter_mut().zip(&mix.channels) {
+ for (i, d) in dst.iter_mut().enumerate() {
+ let pos = (at(m0 + i as i64) - first as f64).max(0.0);
+ let i0 = pos.floor() as usize;
+ let fr = (pos - i0 as f64) as f32;
+ let a = src.get(i0).copied().unwrap_or(0.0);
+ let b = src.get(i0 + 1).copied().unwrap_or(a);
+ *d = a + (b - a) * fr;
+ }
+ }
+ out
}
+/// A clip's source sound: `len` samples from sample `m0` of the source's own time, at the
+/// sequence's sample rate (a media source's audio, or a nested sequence's mix).
+type SourceAudio<'a> = &'a dyn Fn(i64, usize) -> Option<AudioBuffer>;
+
/// The clip's audio after speed/reverse and clip effects (before clip gain, Volume and Panner) for
/// timeline samples `[a0, a0 + n)`, `w` channels.
-fn effected(item: &TrackItem, src: &dyn filmcraft_media::MediaSource, a0: i64, n: usize, sr: u32, w: usize) -> Vec<Vec<f32>> {
+fn effected(item: &TrackItem, src: SourceAudio, a0: i64, n: usize, sr: u32, w: usize) -> Vec<Vec<f32>> {
let read = |x0: i64, len: usize| raw_channels(item, src, x0, len, sr, w);
if crate::audio_fx::has_effects(item) { crate::audio_fx::process(item, a0, n, sr, &read) } else { read(a0, n) }
}
@@ -299,7 +327,7 @@ pub fn clip_signal(item: &TrackItem, start: i64, frames: usize, sr: u32, sources
let n = (a1 - a0) as usize;
let off = (a0 - start) as usize;
let g = db_to_gain(item.gain_db);
- let buf = effected(item, src.as_ref(), a0, n, sr, 2);
+ let buf = effected(item, &|m0, len| src.audio(m0, len, sr).ok(), a0, n, sr, 2);
for (dst, b) in out.iter_mut().zip(&buf) {
for (d, x) in dst[off..off + n].iter_mut().zip(b) {
*d = x * g;
@@ -311,7 +339,7 @@ pub fn clip_signal(item: &TrackItem, start: i64, frames: usize, sr: u32, sources
/// The clip's audio (after speed/reverse) for timeline samples `[x0, x0 + len)` as `w` channels
/// (2: stereo, mono sources on both sides; 6: 5.1), with silence outside the clip.
-fn raw_channels(item: &TrackItem, src: &dyn filmcraft_media::MediaSource, x0: i64, len: usize, sr: u32, w: usize) -> Vec<Vec<f32>> {
+fn raw_channels(item: &TrackItem, src: SourceAudio, x0: i64, len: usize, sr: u32, w: usize) -> Vec<Vec<f32>> {
let mut out = vec![vec![0.0f32; len]; w];
let item_s0 = item.start.to_units_floor(sr as i64);
let item_s1 = item.end().to_units_floor(sr as i64);
@@ -324,16 +352,16 @@ fn raw_channels(item: &TrackItem, src: &dyn filmcraft_media::MediaSource, x0: i6
let off = (a0 - x0) as usize;
let speed = item.speed.abs().max(1e-6);
let src_start_ticks = item.source_time_at(Tick::from_units(a0, sr as i64));
- let remixed = crate::remix::read(item, &|m0, len| src.audio(m0, len, sr).ok(), a0 - item_s0, n, sr);
+ let remixed = crate::remix::read(item, &|m0, len| src(m0, len), a0 - item_s0, n, sr);
let buf = if remixed.is_some() {
remixed
} else if (speed - 1.0).abs() < 1e-9 && !item.reverse {
- src.audio(src_start_ticks.to_units_floor(sr as i64), n, sr).ok()
+ src(src_start_ticks.to_units_floor(sr as i64), n)
} else {
// varispeed: read a longer span and resample linearly
let span = ((n as f64) * speed).ceil() as usize + 2;
let s0 = if item.reverse { src_start_ticks.to_units_floor(sr as i64) - span as i64 } else { src_start_ticks.to_units_floor(sr as i64) };
- src.audio(s0, span, sr).ok().map(|raw| {
+ src(s0, span).map(|raw| {
let mut b = AudioBuffer::silence(sr, raw.channel_count(), n);
for (c, ch) in raw.channels.iter().enumerate() {
for i in 0..n {
diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs
index 2b9f34fad..ef1c2d711 100644
--- a/crates/render/src/lib.rs
+++ b/crates/render/src/lib.rs
@@ -184,7 +184,8 @@ pub(crate) fn render_seq_tracks(project: &Project, seq: &Sequence, t: Tick, opts
if opts.depth == 0 && !opts.working_output {
colorman::to_display(&mut canvas, &seq.settings.color);
}
- if opts.captions && opts.depth == 0 {
+ // (a nested sequence's captions are part of its picture: see `base_layer`)
+ if opts.captions {
for o in caption_overlays(seq, t, w, h) {
o.composite_onto(&mut canvas.px, w, h);
}
@@ -395,7 +396,9 @@ pub(crate) fn base_layer(
Image::new(nw, nh)
}
},
- None => render_seq(project, nested, ft, sub, sources),
+ // A nested sequence shows its captions wherever it is nested, as part of its
+ // picture (Premiere does the same), whether or not the outer sequence shows its own.
+ None => render_seq(project, nested, ft, RenderOptions { captions: true, ..sub }, sources),
}
}
ItemKind::AdjustmentLayer { .. } => return None,
diff --git a/crates/render/src/mixer_tests.rs b/crates/render/src/mixer_tests.rs
index c76481dd3..0eea28c35 100644
--- a/crates/render/src/mixer_tests.rs
+++ b/crates/render/src/mixer_tests.rs
@@ -628,3 +628,132 @@ fn a_sequence_nested_in_itself_mixes_to_an_end() {
assert_eq!(out.channels.len(), 2);
assert!(out.channels.iter().all(|c| c.len() == 4800 && c.iter().all(|s| *s == 0.0)), "no source: silence");
}
+
+// ---- the sound of nested sequences
+
+/// A mono-in-stereo sine that knows its sample rate: the same pitch at whatever rate it is read.
+struct Tone {
+ info: MediaInfo,
+ hz: f64,
+}
+
+impl Tone {
+ fn at(&self, seconds: f64) -> f32 {
+ (std::f64::consts::TAU * self.hz * seconds).sin() as f32 * 0.5
+ }
+}
+
+impl MediaSource for Tone {
+ fn info(&self) -> &MediaInfo {
+ &self.info
+ }
+ fn video_frame(&self, _: FrameRequest) -> filmcraft_media::Result<Arc<VideoFrame>> {
+ Err(MediaError::Unsupported("audio only".into()))
+ }
+ fn audio(&self, start: i64, frames: usize, sample_rate: u32) -> filmcraft_media::Result<AudioBuffer> {
+ let ch: Vec<f32> = (0..frames).map(|i| self.at((start + i as i64) as f64 / sample_rate as f64)).collect();
+ Ok(AudioBuffer { sample_rate, channels: vec![ch.clone(), ch] })
+ }
+}
+
+/// An outer 48 kHz sequence whose A1 holds one clip of an inner sequence (at `inner_rate`) that
+/// holds 10 s of a 500 Hz tone. Returns the project, the outer sequence, the sources and the tone.
+fn nested_tone(inner_rate: u32) -> (Project, ItemId, SourceMap, Arc<Tone>) {
+ let mut p = Project::new("nest");
+ let ten = TimeRange::new(Tick::ZERO, Tick(10 * TICKS_PER_SECOND));
+ let info = MediaInfo {
+ name: "tone".into(),
+ kind: MediaKind::AudioOnly,
+ duration: ten.duration,
+ video: None,
+ audio: Some(AudioStreamInfo { sample_rate: 48_000, channels: 2, codec: "test".into(), bits_per_sample: Some(32) }),
+ container: "test".into(),
+ start_timecode: None,
+ file_size: None,
+ };
+ let media = p.add_item(
+ "tone",
+ Label::Iris,
+ ItemKind::Media(MediaClip {
+ media: MediaRef::File { path: "/tone.wav".into() },
+ info: info.clone(),
+ interpret: Default::default(),
+ mark_in: None,
+ mark_out: None,
+ markers: vec![],
+ offline: false,
+ proxy: None,
+ identity: None,
+ }),
+ None,
+ );
+ let tone = Arc::new(Tone { info, hz: 500.0 });
+ let mut map = SourceMap::default();
+ map.0.insert(media, tone.clone());
+ let inner = p.new_sequence("inner", SequenceSettings { sample_rate: inner_rate, ..SequenceSettings::default() }, 1, 1, None);
+ let clip = p.make_track_item(media, TrackKind::Audio, Tick::ZERO, ten, FrameRate::FPS_24).unwrap();
+ p.sequence_mut(inner).unwrap().audio_tracks[0].items.push(clip);
+ let outer = p.new_sequence("outer", SequenceSettings { sample_rate: 48_000, ..SequenceSettings::default() }, 1, 1, None);
+ let nest = p.make_track_item(inner, TrackKind::Audio, Tick::ZERO, ten, FrameRate::FPS_24).unwrap();
+ p.sequence_mut(outer).unwrap().audio_tracks[0].items.push(nest);
+ (p, outer, map, tone)
+}
+
+/// The largest difference between the mix's left channel and `want(seconds)`, over samples
+/// `skip..` (resampling and fades settle within the first few samples).
+fn worst(mix: &AudioBuffer, start: i64, skip: usize, want: impl Fn(f64) -> f32) -> f32 {
+ mix.channels[0].iter().enumerate().skip(skip).map(|(i, s)| (s - want((start + i as i64) as f64 / 48_000.0)).abs()).fold(0.0, f32::max)
+}
+
+#[test]
+fn a_nest_plays_its_sequence_as_it_sounds_there() {
+ let (p, outer, map, tone) = nested_tone(48_000);
+ let start = 48_000 * 2;
+ let mix = mix_graph(&p, p.sequence(outer).unwrap(), start, 4800, &map, None);
+ assert!(worst(&mix, start, 0, |t| tone.at(t)) < 1e-4);
+}
+
+#[test]
+fn a_nest_at_another_sample_rate_keeps_its_pitch_and_timing() {
+ // the nested sequence used to be read sample for sample: a 44.1 kHz nest in a 48 kHz
+ // sequence played 8.8% fast and sharp
+ for rate in [44_100, 96_000, 32_000] {
+ let (p, outer, map, tone) = nested_tone(rate);
+ let start = 48_000 * 3 + 17;
+ let mix = mix_graph(&p, p.sequence(outer).unwrap(), start, 4800, &map, None);
+ assert_eq!(mix.channels[0].len(), 4800);
+ assert!(worst(&mix, start, 8, |t| tone.at(t)) < 0.01, "{rate} Hz nest: off by {}", worst(&mix, start, 8, |t| tone.at(t)));
+ }
+}
+
+#[test]
+fn speed_and_reverse_on_a_nest_change_its_sound_like_a_clips() {
+ // speed and reverse used to be ignored for the sound of a nest
+ let (mut p, outer, map, tone) = nested_tone(48_000);
+ let nest = &mut p.sequence_mut(outer).unwrap().audio_tracks[0].items[0];
+ nest.speed = 2.0;
+ nest.duration = Tick(5 * TICKS_PER_SECOND);
+ let start = 48_000 + 5;
+ let mix = mix_graph(&p, p.sequence(outer).unwrap(), start, 4800, &map, None);
+ assert!(worst(&mix, start, 8, |t| tone.at(2.0 * t)) < 0.01, "double speed: twice as far into the sequence, an octave up");
+ // reversed at normal speed: the 10 s nest plays from its end
+ let nest = &mut p.sequence_mut(outer).unwrap().audio_tracks[0].items[0];
+ nest.speed = 1.0;
+ nest.duration = Tick(10 * TICKS_PER_SECOND);
+ nest.reverse = true;
+ let mix = mix_graph(&p, p.sequence(outer).unwrap(), start, 4800, &map, None);
+ // (a reversed clip reads its source a sample or two off, media and nests alike)
+ let w = (0..4).map(|k| worst(&mix, start, 8, |t| tone.at(10.0 - t - k as f64 / 48_000.0))).fold(f32::MAX, f32::min);
+ assert!(w < 0.01, "reversed: off by {w}");
+}
+
+#[test]
+fn a_nest_trimmed_in_starts_later_in_its_sequence() {
+ let (mut p, outer, map, tone) = nested_tone(44_100);
+ let nest = &mut p.sequence_mut(outer).unwrap().audio_tracks[0].items[0];
+ nest.source_in = Tick(3 * TICKS_PER_SECOND);
+ nest.duration = Tick(7 * TICKS_PER_SECOND);
+ let start = 48_000;
+ let mix = mix_graph(&p, p.sequence(outer).unwrap(), start, 4800, &map, None);
+ assert!(worst(&mix, start, 8, |t| tone.at(t + 3.0)) < 0.01);
+}
diff --git a/crates/render/src/nest_tests.rs b/crates/render/src/nest_tests.rs
index 89808129f..8142a352f 100644
--- a/crates/render/src/nest_tests.rs
+++ b/crates/render/src/nest_tests.rs
@@ -1,11 +1,11 @@
//! The picture of nested sequences: a nest shows its sequence at that sequence's own size and
-//! frame rate.
+//! frame rate, through the clip's speed, holds and effects, with the sequence's captions.
//! Premiere's behaviour was observed in Premiere Pro 26.5.2.
use super::*;
use filmcraft_media::generators::GeneratorSource;
use filmcraft_media::{DemoScene, Generator, MediaSource};
-use filmcraft_project::{ClipId, Label, MediaClip, MediaRef, ParamValue, SequenceSettings, TrackKind};
+use filmcraft_project::{Caption, CaptionFormat, CaptionTrack, ClipId, Label, MediaClip, MediaRef, ParamValue, SequenceSettings, TrackId, TrackKind};
use filmcraft_time::{FrameRate, TICKS_PER_SECOND, TimeRange};
const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
@@ -148,3 +148,115 @@ fn a_nest_at_another_frame_rate_shows_its_sequence_at_the_same_moment() {
assert!(worst(&r.frame(outer, t), &r.frame(inner, t)) < 0.01);
assert!(worst(&r.frame(inner, t), &r.frame(inner, Tick::ZERO)) > 0.05, "the footage moves, so the comparison means something");
}
+
+#[test]
+fn speed_reverse_and_frame_hold_on_a_nest_pick_the_frame_of_its_sequence() {
+ let mut r = Rig::new();
+ let ocean = r.add(GeneratorSource::demo(DemoScene::OceanSunset));
+ let (w, h) = {
+ let v = r.map.0[&ocean].info().video.clone().unwrap();
+ (v.width, v.height)
+ };
+ let rate = FrameRate::FPS_24;
+ let inner = r.seq("inner", w, h, rate);
+ r.put(inner, ocean, 96);
+ let outer = r.seq("outer", w, h, rate);
+ let nest = r.put(outer, inner, 48);
+ let f = |n: i64| rate.tick_of(n);
+ // double speed: frame 10 of the nest is frame 20 of its sequence
+ r.clip(outer, nest).speed = 2.0;
+ assert!(worst(&r.frame(outer, f(10)), &r.frame(inner, f(20))) < 0.01);
+ // reversed (48 frames at normal speed): 10 frames in is 10 frames back from the end of what it
+ // covers, a tick short of frame 38
+ let c = r.clip(outer, nest);
+ c.speed = 1.0;
+ c.reverse = true;
+ assert!(worst(&r.frame(outer, f(10)), &r.frame(inner, f(38) - Tick(1))) < 0.01);
+ // a frame hold shows one frame of the sequence throughout
+ let c = r.clip(outer, nest);
+ c.reverse = false;
+ c.frame_hold = Some(f(30));
+ assert!(worst(&r.frame(outer, f(5)), &r.frame(inner, f(30))) < 0.01);
+ assert!(worst(&r.frame(outer, f(40)), &r.frame(inner, f(30))) < 0.01);
+}
+
+#[test]
+fn opacity_and_effects_on_a_nest_apply_to_its_whole_picture() {
+ let mut r = Rig::new();
+ let red = r.matte(RED, 320, 180);
+ let inner = r.seq("inner", 320, 180, FrameRate::FPS_24);
+ r.put(inner, red, 48);
+ let outer = r.seq("outer", 320, 180, FrameRate::FPS_24);
+ let nest = r.put(outer, inner, 48);
+ r.clip(outer, nest).effect_mut("opacity").unwrap().params.get_mut("opacity").unwrap().value = ParamValue::Float(50.0);
+ for img in [r.frame(outer, Tick(1000)), r.planned(outer, Tick(1000))] {
+ let c = img.get(160, 90);
+ assert!((c[3] - 0.5).abs() < 0.02, "half transparent: {c:?}");
+ }
+ // a crop on the nest cuts its picture like any clip's
+ let c = r.clip(outer, nest);
+ c.effect_mut("opacity").unwrap().params.get_mut("opacity").unwrap().value = ParamValue::Float(100.0);
+ let mut crop = filmcraft_project::effect::find_effect("crop").unwrap().instance();
+ crop.params.get_mut("left").unwrap().value = ParamValue::Float(50.0);
+ c.effects.push(crop);
+ let img = r.frame(outer, Tick(1000));
+ assert!(img.get(40, 90)[3] < 0.02 && close(img.get(280, 90), RED));
+}
+
+#[test]
+fn captions_inside_a_nest_are_part_of_its_picture() {
+ // Premiere draws a nested sequence's captions in the sequence it is nested in
+ let mut r = Rig::new();
+ let red = r.matte(RED, 320, 180);
+ let inner = r.seq("inner", 320, 180, FrameRate::FPS_24);
+ r.put(inner, red, 48);
+ let mut track = CaptionTrack::new(TrackId(9001), "Subtitles".into(), CaptionFormat::Subtitle);
+ track.captions.push(Caption {
+ id: ClipId(9002),
+ start: Tick::ZERO,
+ duration: Tick(TICKS_PER_SECOND),
+ text: "NESTED".into(),
+ speaker: None,
+ cue_id: None,
+ settings: String::new(),
+ });
+ r.p.sequence_mut(inner).unwrap().caption_tracks.push(track);
+ let outer = r.seq("outer", 640, 360, FrameRate::FPS_24);
+ r.put(outer, inner, 48);
+ let t = Tick(1000);
+ let with = r.frame(outer, t);
+ r.p.sequence_mut(inner).unwrap().caption_tracks[0].enabled = false;
+ let without = r.frame(outer, t);
+ r.p.sequence_mut(inner).unwrap().caption_tracks[0].enabled = true;
+ // the caption changes pixels, all of them inside the nest's part of the frame (x 160..480, y 90..270)
+ let mut changed = 0;
+ for y in 0..with.h {
+ for x in 0..with.w {
+ if !close(with.get(x, y), without.get(x, y)) {
+ changed += 1;
+ assert!((160..480).contains(&x) && (90..270).contains(&y), "caption pixel outside the nest at ({x}, {y})");
+ }
+ }
+ }
+ assert!(changed > 20, "the caption is drawn ({changed} pixels)");
+ // after the caption ends there is nothing to draw
+ assert!(worst(&r.frame(outer, Tick(TICKS_PER_SECOND + 1000)), &without) < 0.01);
+ // the frame plan gives the same picture
+ assert!(worst(&r.planned(outer, t), &with) < 0.02);
+ // and the outer sequence's own captions are still its own business: with captions off for
+ // the outer render, the nested ones show all the same
+ let mut outer_track = CaptionTrack::new(TrackId(9003), "Outer".into(), CaptionFormat::Subtitle);
+ outer_track.captions.push(Caption {
+ id: ClipId(9004),
+ start: Tick::ZERO,
+ duration: Tick(TICKS_PER_SECOND),
+ text: "OUTER".into(),
+ speaker: None,
+ cue_id: None,
+ settings: String::new(),
+ });
+ r.p.sequence_mut(outer).unwrap().caption_tracks.push(outer_track);
+ assert!(worst(&r.frame(outer, t), &with) < 0.01, "outer captions are only drawn when asked for");
+ let shown = render_sequence(&r.p, outer, t, RenderOptions { captions: true, ..Default::default() }, &r.map);
+ assert!(worst(&shown, &with) > 0.1, "and are drawn when asked for");
+}
diff --git a/crates/render/src/preview.rs b/crates/render/src/preview.rs
index f6c01d1c9..f113e9049 100644
--- a/crates/render/src/preview.rs
+++ b/crates/render/src/preview.rs
@@ -344,6 +344,8 @@ fn hash_source(h: &mut Fnv128, project: &Project, id: ItemId, depth: u32) {
ItemKind::Graphic { .. } => h.json(&("graphic", &pi.kind)),
ItemKind::Sequence(s) => {
h.json(&("sequence", &s.settings));
+ // a nested sequence's captions are drawn into its picture
+ h.json(&("captions", &s.caption_tracks));
for (ti, tr) in s.video_tracks.iter().enumerate() {
h.json(&("track", ti, tr.enabled, tr.items.len()));
for it in &tr.items {