The truncation notice counts what a file could not give
Browse files at this commitce7b65f45f181f562de1ca16a77c5644efbc497bParent: 24df84c- fix
- the truncation notice counts what a file could not give
2 changed files +117 -7
- crates/engine/src/export.rs +20 -7
- crates/engine/tests/export.rs +97 -0
crates/engine/src/export.rsmodified+20 -7
| @@ -2784,6 +2784,9 @@ fn run( | ||
| 2784 | 2784 | let mut audio_fed = false; |
| 2785 | 2785 | let mut muxer = None; |
| 2786 | 2786 | let mut done = 0u32; |
| 2787 | + // ...and how many of the edit's frames a file could not give, summed over | |
| 2788 | + // the spans that ran out under their clip ([`Shared::truncated`]). | |
| 2789 | + let mut skipped = 0u32; | |
| 2787 | 2790 | let black = Black::new(meta); |
| 2788 | 2791 | // Spans, not clips: a gap in the video is part of the timeline and gets |
| 2789 | 2792 | // encoded too, as black frames. The picture count is therefore |
| @@ -3013,16 +3016,20 @@ fn run( | ||
| 3013 | 3016 | } |
| 3014 | 3017 | }; |
| 3015 | 3018 | let Some(frame) = picture else { |
| 3016 | - // The file ran out before its clip did, so the walk ends here | |
| 3017 | - // and the rest of the edit never gets a picture. Counted, not | |
| 3019 | + // The file ran out before its clip did: this span's tail never | |
| 3020 | + // gets a picture -- and *only* this span's tail, because the | |
| 3021 | + // span loop this break sits in carries on with the spans after | |
| 3022 | + // it and writes every picture they have. Counted, not | |
| 3018 | 3023 | // swallowed: the bar reaches its end whatever happens, so |
| 3019 | 3024 | // without this a truncated file reads as a whole one. The same |
| 3020 | 3025 | // sentence `planned_subtitles` gives cues that hang past the |
| 3021 | - // last picture -- and this one is said after the fact, because | |
| 3022 | - // how many pictures a *file* holds is only known by opening it. | |
| 3023 | - shared | |
| 3024 | - .truncated | |
| 3025 | - .fetch_max(total.saturating_sub(done), Ordering::Relaxed); | |
| 3026 | + // last picture, said after the fact here because how many | |
| 3027 | + // pictures a *file* holds is only known by opening it. | |
| 3028 | + // | |
| 3029 | + // `span.len > done_here` holds by the loop's own condition, and | |
| 3030 | + // the sum over every break is exactly `total - done` at the end | |
| 3031 | + // of the walk: the spans are disjoint and cover the whole edit. | |
| 3032 | + skipped += span.len - done_here; | |
| 3026 | 3033 | break; // source ran out early; the clip list outlives the file |
| 3027 | 3034 | }; |
| 3028 | 3035 | // A picture still on the GPU has nothing waiting for it here: the |
| @@ -3123,6 +3130,12 @@ fn run( | ||
| 3123 | 3130 | done_here += repeats; |
| 3124 | 3131 | } |
| 3125 | 3132 | } |
| 3133 | + // The whole walk is over, so what it could not write is known to the frame | |
| 3134 | + // and is published once. `fetch_max` and not `fetch_add`, because a | |
| 3135 | + // hardware seat that died has the *whole* walk run again from its first | |
| 3136 | + // frame ([`start`]): the same project and the same picture counts, so a | |
| 3137 | + // second run must not double a number that is already on the line. | |
| 3138 | + shared.truncated.fetch_max(skipped, Ordering::Relaxed); | |
| 3126 | 3139 | while let Some((au, key)) = encoder.drain()? { |
| 3127 | 3140 | write_video( |
| 3128 | 3141 | &mut muxer, |
crates/engine/tests/export.rsmodified+97 -0
| @@ -2127,6 +2127,103 @@ fn a_clip_that_outlives_its_source_says_so_on_the_card() { | ||
| 2127 | 2127 | std::fs::remove_file(&out).unwrap(); |
| 2128 | 2128 | } |
| 2129 | 2129 | |
| 2130 | +/// Two whole-clip spans of one source, both lanes: an edit whose first take is | |
| 2131 | +/// short and whose second one is whole. Both clips read the file from its own | |
| 2132 | +/// first frame, so the walk keeps two spans rather than fusing them into one | |
| 2133 | +/// window -- a span is continued only where the source window continues. | |
| 2134 | +fn two_clip_edit(source: &Path, first: u32, second: u32) -> (Project, engine::VideoMeta) { | |
| 2135 | + let (meta, _) = engine::demux::Demuxer::open(source).expect("open the fixture"); | |
| 2136 | + let clip = |start: u32, out_frame: u32| engine::Clip { | |
| 2137 | + fade_in: 0, | |
| 2138 | + fade_out: 0, | |
| 2139 | + transition_out: 0, | |
| 2140 | + visualizer: 0, | |
| 2141 | + viz_paint: 0, | |
| 2142 | + start, | |
| 2143 | + in_frame: 0, | |
| 2144 | + out_frame, | |
| 2145 | + source: 0, | |
| 2146 | + link: None, | |
| 2147 | + eq: None, | |
| 2148 | + color: None, | |
| 2149 | + transform: None, | |
| 2150 | + fit: FitPolicy::default(), | |
| 2151 | + speed: Speed::NORMAL, | |
| 2152 | + }; | |
| 2153 | + let clips = vec![clip(0, first), clip(first, second)]; | |
| 2154 | + let project = Project::from_parts( | |
| 2155 | + vec![Source { | |
| 2156 | + path: source.to_path_buf(), | |
| 2157 | + audio_stream: 0, | |
| 2158 | + }], | |
| 2159 | + vec![ | |
| 2160 | + (engine::project::LaneKind::Video, clips.clone()), | |
| 2161 | + (engine::project::LaneKind::Audio, clips), | |
| 2162 | + ], | |
| 2163 | + Vec::new(), | |
| 2164 | + Vec::new(), | |
| 2165 | + Vec::new(), | |
| 2166 | + ) | |
| 2167 | + .expect("a two-clip project"); | |
| 2168 | + (project, meta) | |
| 2169 | +} | |
| 2170 | + | |
| 2171 | +/// D4, the half the single-clip test cannot see: the walk carries on with the | |
| 2172 | +/// spans *after* a file runs out, so what went missing is that span's own tail | |
| 2173 | +/// and not everything the edit still had. Counting the rest would put 100 on | |
| 2174 | +/// the line for a file that holds 120 of the edit's 160 pictures. | |
| 2175 | +#[test] | |
| 2176 | +fn a_two_clip_timeline_reports_only_the_pictures_that_were_skipped() { | |
| 2177 | + let _seat = pin_software(); | |
| 2178 | + let source = asset("test_multiaudio.mp4"); // 60 frames | |
| 2179 | + let count = meta_frame_count(&source); | |
| 2180 | + // The first take asks for 40 pictures the file has not got; the second one | |
| 2181 | + // is whole and is written after the break. | |
| 2182 | + let (project, meta) = two_clip_edit(&source, count + 40, count); | |
| 2183 | + let out = out_path("truncated_two_clip"); | |
| 2184 | + let handle = engine::export::start(project, meta, &out, &ExportSettings::default(), None); | |
| 2185 | + wait(&handle, Duration::from_secs(900)).expect("export"); | |
| 2186 | + let line = handle.encoders().expect("the seats were published"); | |
| 2187 | + assert!( | |
| 2188 | + line.contains("40 frames of the edit past the last picture"), | |
| 2189 | + "the notice counts more than the file lost: {line}" | |
| 2190 | + ); | |
| 2191 | + // ...and the file really holds both spans' pictures, which is what makes | |
| 2192 | + // this the count of a tail and not of the whole rest of the edit: 60 of the | |
| 2193 | + // short take plus all 60 of the second one. | |
| 2194 | + assert_eq!( | |
| 2195 | + decode_all(&out).len(), | |
| 2196 | + (count * 2) as usize, | |
| 2197 | + "the span after the break was not written" | |
| 2198 | + ); | |
| 2199 | + std::fs::remove_file(&out).unwrap(); | |
| 2200 | +} | |
| 2201 | + | |
| 2202 | +/// D4's control: an edit whose every span ends on a picture its file really has | |
| 2203 | +/// carries no notice at all -- the count must never be invented. | |
| 2204 | +#[test] | |
| 2205 | +fn a_healthy_two_clip_timeline_carries_no_truncation_notice() { | |
| 2206 | + let _seat = pin_software(); | |
| 2207 | + let source = asset("test_multiaudio.mp4"); // 60 frames | |
| 2208 | + let count = meta_frame_count(&source); | |
| 2209 | + let (project, meta) = two_clip_edit(&source, count, count); | |
| 2210 | + let out = out_path("truncated_control"); | |
| 2211 | + let handle = engine::export::start(project, meta, &out, &ExportSettings::default(), None); | |
| 2212 | + wait(&handle, Duration::from_secs(900)).expect("export"); | |
| 2213 | + let line = handle.encoders().expect("the seats were published"); | |
| 2214 | + let notice = line.contains("past the last picture"); | |
| 2215 | + assert_eq!( | |
| 2216 | + notice, false, | |
| 2217 | + "a whole export says it was truncated: {line}" | |
| 2218 | + ); | |
| 2219 | + assert_eq!( | |
| 2220 | + decode_all(&out).len(), | |
| 2221 | + (count * 2) as usize, | |
| 2222 | + "both spans were written" | |
| 2223 | + ); | |
| 2224 | + std::fs::remove_file(&out).unwrap(); | |
| 2225 | +} | |
| 2226 | + | |
| 2130 | 2227 | /// D3: the catch_unwind branch settled the worker's slot but left the `.part` |
| 2131 | 2228 | /// on disk, against the module promise that every error path deletes it. The |
| 2132 | 2229 | /// panic is injected at the first coded picture, so the `.part` is provably |