A cut can be put where the export copies it, and the card says so
Browse files at this commitbea7164366308273c10e6e6f03b95f5dd73d56dbParent: 3fc6753- feat
- a cut can be put where the export copies it, and the card says so
4 changed files +271 -36
- crates/app/src/keymap.rs +28 -2
- crates/app/src/main.rs +211 -22
- crates/app/src/ui/cards.rs +14 -5
- crates/app/src/ui/timeline.rs +18 -7
crates/app/src/keymap.rsmodified+28 -2
| @@ -68,6 +68,13 @@ actions! { | |||
| 68 | JumpForward, | 68 | JumpForward, |
| 69 | GoStart, | 69 | GoStart, |
| 70 | GoEnd, | 70 | GoEnd, |
| 71 | + /// The two that put the playhead on a *source* sync point -- the frames a | ||
| 72 | + /// cut may be placed on for an export to copy the film's own coded pictures | ||
| 73 | + /// instead of decoding and coding every one of them again. Playback keys by | ||
| 74 | + /// what they do (they move the playhead and nothing else) and editing keys | ||
| 75 | + /// by what they are for. | ||
| 76 | + PrevSyncPoint, | ||
| 77 | + NextSyncPoint, | ||
| 71 | Export, | 78 | Export, |
| 72 | Save, | 79 | Save, |
| 73 | Copy, | 80 | Copy, |
| @@ -121,6 +128,8 @@ impl ActionId { | |||
| 121 | ActionId::JumpForward => "One second forward", | 128 | ActionId::JumpForward => "One second forward", |
| 122 | ActionId::GoStart => "Go to the start", | 129 | ActionId::GoStart => "Go to the start", |
| 123 | ActionId::GoEnd => "Go to the last frame", | 130 | ActionId::GoEnd => "Go to the last frame", |
| 131 | + ActionId::PrevSyncPoint => "Previous sync point (a cut here is copied, not re-encoded)", | ||
| 132 | + ActionId::NextSyncPoint => "Next sync point (a cut here is copied, not re-encoded)", | ||
| 124 | ActionId::Export => "Export", | 133 | ActionId::Export => "Export", |
| 125 | ActionId::Save => "Save", | 134 | ActionId::Save => "Save", |
| 126 | ActionId::Copy => "Copy", | 135 | ActionId::Copy => "Copy", |
| @@ -175,6 +184,8 @@ impl ActionId { | |||
| 175 | ActionId::JumpForward => "jump-forward", | 184 | ActionId::JumpForward => "jump-forward", |
| 176 | ActionId::GoStart => "go-start", | 185 | ActionId::GoStart => "go-start", |
| 177 | ActionId::GoEnd => "go-end", | 186 | ActionId::GoEnd => "go-end", |
| 187 | + ActionId::PrevSyncPoint => "prev-sync-point", | ||
| 188 | + ActionId::NextSyncPoint => "next-sync-point", | ||
| 178 | ActionId::Export => "export", | 189 | ActionId::Export => "export", |
| 179 | ActionId::Save => "save", | 190 | ActionId::Save => "save", |
| 180 | ActionId::Copy => "copy", | 191 | ActionId::Copy => "copy", |
| @@ -230,7 +241,9 @@ impl ActionId { | |||
| 230 | | ActionId::JumpBack | 241 | | ActionId::JumpBack |
| 231 | | ActionId::JumpForward | 242 | | ActionId::JumpForward |
| 232 | | ActionId::GoStart | 243 | | ActionId::GoStart |
| 233 | - | ActionId::GoEnd => Category::Playback, | 244 | + | ActionId::GoEnd |
| 245 | + | ActionId::PrevSyncPoint | ||
| 246 | + | ActionId::NextSyncPoint => Category::Playback, | ||
| 234 | ActionId::Copy | 247 | ActionId::Copy |
| 235 | | ActionId::Paste | 248 | | ActionId::Paste |
| 236 | | ActionId::Select | 249 | | ActionId::Select |
| @@ -677,6 +690,12 @@ impl Keymap { | |||
| 677 | b(ActionId::JumpForward, "right", true), | 690 | b(ActionId::JumpForward, "right", true), |
| 678 | b(ActionId::GoStart, "home", false), | 691 | b(ActionId::GoStart, "home", false), |
| 679 | b(ActionId::GoEnd, "end", false), | 692 | b(ActionId::GoEnd, "end", false), |
| 693 | + // The sync-point pair, on the brackets that already mean "the | ||
| 694 | + // one before / the one after" here (they select the clip either | ||
| 695 | + // side) -- with ctrl, which was free on both, because these | ||
| 696 | + // step through the same timeline by the source's own grid. | ||
| 697 | + b(ActionId::PrevSyncPoint, "[", true), | ||
| 698 | + b(ActionId::NextSyncPoint, "]", true), | ||
| 680 | b(ActionId::Export, "e", false), | 699 | b(ActionId::Export, "e", false), |
| 681 | b(ActionId::Save, "s", true), | 700 | b(ActionId::Save, "s", true), |
| 682 | b(ActionId::Copy, "c", true), | 701 | b(ActionId::Copy, "c", true), |
| @@ -1042,7 +1061,7 @@ mod tests { | |||
| 1042 | #[test] | 1061 | #[test] |
| 1043 | fn every_default_stroke_reaches_its_action() { | 1062 | fn every_default_stroke_reaches_its_action() { |
| 1044 | let k = Keymap::defaults(); | 1063 | let k = Keymap::defaults(); |
| 1045 | - assert_eq!(k.entries().len(), 46); | 1064 | + assert_eq!(k.entries().len(), 48); |
| 1046 | assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); | 1065 | assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); |
| 1047 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); | 1066 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); |
| 1048 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two | 1067 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two |
| @@ -1053,6 +1072,13 @@ mod tests { | |||
| 1053 | assert_eq!(k.lookup("right", true), Some(ActionId::JumpForward)); | 1072 | assert_eq!(k.lookup("right", true), Some(ActionId::JumpForward)); |
| 1054 | assert_eq!(k.lookup("home", false), Some(ActionId::GoStart)); | 1073 | assert_eq!(k.lookup("home", false), Some(ActionId::GoStart)); |
| 1055 | assert_eq!(k.lookup("end", false), Some(ActionId::GoEnd)); | 1074 | assert_eq!(k.lookup("end", false), Some(ActionId::GoEnd)); |
| 1075 | + // ...and the source's own grid, which is neither a frame nor a second: | ||
| 1076 | + // the brackets bare select the clip either side, with ctrl they step | ||
| 1077 | + // the sync points a cut has to land on to be copied. | ||
| 1078 | + assert_eq!(k.lookup("[", true), Some(ActionId::PrevSyncPoint)); | ||
| 1079 | + assert_eq!(k.lookup("]", true), Some(ActionId::NextSyncPoint)); | ||
| 1080 | + assert_eq!(k.lookup("[", false), Some(ActionId::SelectPrev)); | ||
| 1081 | + assert_eq!(k.lookup("]", false), Some(ActionId::SelectNext)); | ||
| 1056 | assert_eq!(k.lookup("e", false), Some(ActionId::Export)); | 1082 | assert_eq!(k.lookup("e", false), Some(ActionId::Export)); |
| 1057 | assert_eq!(k.lookup("s", true), Some(ActionId::Save)); | 1083 | assert_eq!(k.lookup("s", true), Some(ActionId::Save)); |
| 1058 | assert_eq!(k.lookup("c", true), Some(ActionId::Copy)); | 1084 | assert_eq!(k.lookup("c", true), Some(ActionId::Copy)); |
crates/app/src/main.rsmodified+211 -22
| @@ -1189,6 +1189,14 @@ struct Player { | |||
| 1189 | /// `None` is a file with no picture to report (every source that is not an | 1189 | /// `None` is a file with no picture to report (every source that is not an |
| 1190 | /// image, and one whose header would not read). | 1190 | /// image, and one whose header would not read). |
| 1191 | sizes: HashMap<PathBuf, Option<(u32, u32)>>, | 1191 | sizes: HashMap<PathBuf, Option<(u32, u32)>>, |
| 1192 | + /// Every frame of each source a decoder may be started from -- its sync | ||
| 1193 | + /// points ([`engine::demux::sync_points`]), which are the frames a cut may | ||
| 1194 | + /// be placed on for an export to *copy* the film instead of coding all of | ||
| 1195 | + /// it again. Filled like `bitrates` and off the render thread for the same | ||
| 1196 | + /// reason, and more so: the answer is that Matroska cluster walk. An empty | ||
| 1197 | + /// list is a source with no grid to offer (an mp4, a still, a song), which | ||
| 1198 | + /// must stay in the map or every repaint would ask again. | ||
| 1199 | + syncs: HashMap<PathBuf, Vec<u32>>, | ||
| 1192 | /// Which decoder each source will run on, probed once at import and kept: | 1200 | /// Which decoder each source will run on, probed once at import and kept: |
| 1193 | /// the codec (`None` for a still) and the seat the engine picked for it. | 1201 | /// the codec (`None` for a still) and the seat the engine picked for it. |
| 1194 | /// What a library row says *before* anything plays; the running answer is | 1202 | /// What a library row says *before* anything plays; the running answer is |
| @@ -1197,11 +1205,19 @@ struct Player { | |||
| 1197 | /// `None` is a source with no decoder to name -- a song, or one the probe | 1205 | /// `None` is a source with no decoder to name -- a song, or one the probe |
| 1198 | /// refused -- which must stay in the map or every repaint would ask again. | 1206 | /// refused -- which must stay in the map or every repaint would ask again. |
| 1199 | decoders: HashMap<PathBuf, Option<(Option<Codec>, Backend)>>, | 1207 | decoders: HashMap<PathBuf, Option<(Option<Codec>, Backend)>>, |
| 1200 | - /// Which encoder an export of the picked settings would open, and what it | 1208 | + /// What an export of the picked settings would open -- the picture's seat |
| 1201 | - /// was asked about: the probe opens a real VA-API encoder (~100 ms), so it | 1209 | + /// or the copy that means it opens none, and the sound's -- and what it was |
| 1202 | - /// runs off the render thread and only while the export card is up. The | 1210 | + /// asked about: the settings, the canvas and the *cuts*, since where they |
| 1203 | - /// inner `None` is "asked, not answered yet". | 1211 | + /// land is what decides whether the picture is copied at all. The probe |
| 1204 | - export_seat: Option<(ExportSettings, (u32, u32), Option<&'static str>)>, | 1212 | + /// opens a real VA-API encoder (~100 ms) and reads every source's header, |
| 1213 | + /// so it runs off the render thread and only while the export card is up. | ||
| 1214 | + /// The inner `None` is "asked, not answered yet". | ||
| 1215 | + export_seat: Option<( | ||
| 1216 | + ExportSettings, | ||
| 1217 | + (u32, u32), | ||
| 1218 | + Vec<Clip>, | ||
| 1219 | + Option<(Option<&'static str>, &'static str)>, | ||
| 1220 | + )>, | ||
| 1205 | /// What this machine's GPU decodes and encodes, as the plugin answered it: | 1221 | /// What this machine's GPU decodes and encodes, as the plugin answered it: |
| 1206 | /// asked once, off the render thread like `export_seat` and for the same | 1222 | /// asked once, off the render thread like `export_seat` and for the same |
| 1207 | /// reason (a VA-API init), and kept for the life of the process because the | 1223 | /// reason (a VA-API init), and kept for the life of the process because the |
| @@ -1655,6 +1671,10 @@ impl Player { | |||
| 1655 | // The ends, as a step nothing can be far enough from. | 1671 | // The ends, as a step nothing can be far enough from. |
| 1656 | ActionId::GoStart => self.step(i64::MIN, cx), | 1672 | ActionId::GoStart => self.step(i64::MIN, cx), |
| 1657 | ActionId::GoEnd => self.step(i64::MAX, cx), | 1673 | ActionId::GoEnd => self.step(i64::MAX, cx), |
| 1674 | + // Not a step at all: the grid these land on is the *source's*, and | ||
| 1675 | + // where the next one is depends on the file rather than on the rate. | ||
| 1676 | + ActionId::PrevSyncPoint => self.jump_sync(false, cx), | ||
| 1677 | + ActionId::NextSyncPoint => self.jump_sync(true, cx), | ||
| 1658 | ActionId::Export => self.open_export(cx), | 1678 | ActionId::Export => self.open_export(cx), |
| 1659 | ActionId::Save => self.save_project(cx), | 1679 | ActionId::Save => self.save_project(cx), |
| 1660 | ActionId::Copy => self.copy_selected(), | 1680 | ActionId::Copy => self.copy_selected(), |
| @@ -3131,8 +3151,22 @@ impl Player { | |||
| 3131 | if self.exporting().is_some() { | 3151 | if self.exporting().is_some() { |
| 3132 | return; | 3152 | return; |
| 3133 | } | 3153 | } |
| 3154 | + // Snapped to the source's own grid where one is within reach | ||
| 3155 | + // ([`Player::cut_frame`]): a cut a third of a second off a sync point | ||
| 3156 | + // looks identical on the bed and turns an export that copies its | ||
| 3157 | + // picture in minutes into one that codes every frame of it for hours. | ||
| 3158 | + // The playhead goes with it -- what was cut has to be where the line | ||
| 3159 | + // is, or the next stroke acts a few frames from where it looks. | ||
| 3160 | + let Some(session) = &self.session else { | ||
| 3161 | + return; | ||
| 3162 | + }; | ||
| 3163 | + let now = frame_at(session.now(), self.fps); | ||
| 3164 | + let at = self.cut_frame(now); | ||
| 3165 | + if at != now { | ||
| 3166 | + self.seek(f64::from(at) / self.fps, cx); | ||
| 3167 | + } | ||
| 3134 | if let Some(session) = &mut self.session { | 3168 | if let Some(session) = &mut self.session { |
| 3135 | - session.cut_at(session.now()); | 3169 | + session.cut_at(f64::from(at) / self.fps); |
| 3136 | } | 3170 | } |
| 3137 | self.selected = None; | 3171 | self.selected = None; |
| 3138 | cx.notify(); | 3172 | cx.notify(); |
| @@ -3350,6 +3384,27 @@ impl Player { | |||
| 3350 | }) | 3384 | }) |
| 3351 | .detach(); | 3385 | .detach(); |
| 3352 | } | 3386 | } |
| 3387 | + // Where this file's own groups of pictures begin, for the cut that | ||
| 3388 | + // wants to land on one ([`Player::sync_frames`]). The heaviest probe | ||
| 3389 | + // here -- a Matroska's whole cluster walk, seconds on a film -- and the | ||
| 3390 | + // one nothing waits for: until it answers, the snap is the clip-edge | ||
| 3391 | + // snap it always was. | ||
| 3392 | + for path in unseen_paths(session.sources(), &self.syncs) { | ||
| 3393 | + self.syncs.insert(path.clone(), Vec::new()); | ||
| 3394 | + let probed = cx.background_executor().spawn({ | ||
| 3395 | + let path = path.clone(); | ||
| 3396 | + async move { engine::demux::sync_points(&path) } | ||
| 3397 | + }); | ||
| 3398 | + cx.spawn(async move |this, cx| { | ||
| 3399 | + let probed = probed.await; | ||
| 3400 | + this.update(cx, |this, cx| { | ||
| 3401 | + this.syncs.insert(path, probed); | ||
| 3402 | + cx.notify(); | ||
| 3403 | + }) | ||
| 3404 | + .ok(); | ||
| 3405 | + }) | ||
| 3406 | + .detach(); | ||
| 3407 | + } | ||
| 3353 | // Which decoder each file will run on, for the row that says so before | 3408 | // Which decoder each file will run on, for the row that says so before |
| 3354 | // a frame of it plays. Off the render thread like the streams above: a | 3409 | // a frame of it plays. Off the render thread like the streams above: a |
| 3355 | // stream the plugin takes costs one VA-API init (~90 ms) to answer. | 3410 | // stream the plugin takes costs one VA-API init (~90 ms) to answer. |
| @@ -3406,12 +3461,18 @@ impl Player { | |||
| 3406 | } | 3461 | } |
| 3407 | } | 3462 | } |
| 3408 | 3463 | ||
| 3409 | - /// Probes the encoder an export would open, once per (settings, | 3464 | + /// Probes what an export would open, once per (settings, resolution, cuts) |
| 3410 | - /// resolution) and only while the export card is up -- it opens the very | 3465 | + /// and only while the export card is up -- it opens the very VA-API encoder |
| 3411 | - /// VA-API encoder the export would, which is what makes the card's line a | 3466 | + /// the export would and asks [`engine::export::planned_seats`] the very |
| 3467 | + /// question the export asks itself, which is what makes the card's line a | ||
| 3412 | /// measurement instead of a promise, and also what makes it too slow for | 3468 | /// measurement instead of a promise, and also what makes it too slow for |
| 3413 | /// the render thread. Written before the spawn, like the probes above, so | 3469 | /// the render thread. Written before the spawn, like the probes above, so |
| 3414 | /// the repaints during it start no second one. | 3470 | /// the repaints during it start no second one. |
| 3471 | + /// | ||
| 3472 | + /// The cuts are in the key because they are in the answer: moving one onto | ||
| 3473 | + /// a sync point is exactly what turns "SW encode" into "copy", and a card | ||
| 3474 | + /// that kept the old line would be lying about the file it is about to | ||
| 3475 | + /// write. | ||
| 3415 | fn cache_export_seat(&mut self, cx: &mut Context<Self>) { | 3476 | fn cache_export_seat(&mut self, cx: &mut Context<Self>) { |
| 3416 | let Some(session) = &self.session else { | 3477 | let Some(session) = &self.session else { |
| 3417 | return; | 3478 | return; |
| @@ -3429,32 +3490,38 @@ impl Player { | |||
| 3429 | self.export_seat = None; | 3490 | self.export_seat = None; |
| 3430 | return; | 3491 | return; |
| 3431 | } | 3492 | } |
| 3432 | - let meta = *session.meta(); | 3493 | + // The timeline an export would be started with, owned so the probe can |
| 3494 | + // run on a worker -- and the clips beside it, which are what tells this | ||
| 3495 | + // that the question has changed. | ||
| 3496 | + let (project, meta) = session.export_snapshot(); | ||
| 3497 | + let clips: Vec<Clip> = session | ||
| 3498 | + .lanes() | ||
| 3499 | + .into_iter() | ||
| 3500 | + .flat_map(|lane| session.lane_clips(lane).to_vec()) | ||
| 3501 | + .collect(); | ||
| 3433 | // Cloned rather than copied: the settings carry the picked subtitle | 3502 | // Cloned rather than copied: the settings carry the picked subtitle |
| 3434 | // rows, which is a `Vec` ([`engine::export::ExportSettings`]). | 3503 | // rows, which is a `Vec` ([`engine::export::ExportSettings`]). |
| 3435 | - let key = (settings.clone(), (meta.width, meta.height)); | 3504 | + let key = (settings.clone(), (meta.width, meta.height), clips); |
| 3436 | if self | 3505 | if self |
| 3437 | .export_seat | 3506 | .export_seat |
| 3438 | .as_ref() | 3507 | .as_ref() |
| 3439 | - .is_some_and(|(asked, size, _)| (asked, size) == (&key.0, &key.1)) | 3508 | + .is_some_and(|(asked, size, cuts, _)| (asked, size, cuts) == (&key.0, &key.1, &key.2)) |
| 3440 | { | 3509 | { |
| 3441 | return; | 3510 | return; |
| 3442 | } | 3511 | } |
| 3443 | - self.export_seat = Some((key.0.clone(), key.1, None)); | 3512 | + self.export_seat = Some((key.0.clone(), key.1, key.2.clone(), None)); |
| 3444 | - let probed = cx | 3513 | + let probed = cx.background_executor().spawn(async move { |
| 3445 | - .background_executor() | 3514 | + engine::export::planned_seats(&project, &meta, &settings) |
| 3446 | - .spawn(async move { engine::export::planned_video(&meta, &settings) }); | 3515 | + }); |
| 3447 | cx.spawn(async move |this, cx| { | 3516 | cx.spawn(async move |this, cx| { |
| 3448 | let probed = probed.await; | 3517 | let probed = probed.await; |
| 3449 | this.update(cx, |this, cx| { | 3518 | this.update(cx, |this, cx| { |
| 3450 | // Only if the card is still asking the same question: a format | 3519 | // Only if the card is still asking the same question: a format |
| 3451 | // changed while the plugin opened has a probe of its own. | 3520 | // changed while the plugin opened has a probe of its own. |
| 3452 | - if let Some(seat) = this | 3521 | + if let Some(seat) = this.export_seat.as_mut().filter(|(asked, size, cuts, _)| { |
| 3453 | - .export_seat | 3522 | + (asked, size, cuts) == (&key.0, &key.1, &key.2) |
| 3454 | - .as_mut() | 3523 | + }) { |
| 3455 | - .filter(|(asked, size, _)| (asked, size) == (&key.0, &key.1)) | 3524 | + seat.3 = Some(probed); |
| 3456 | - { | ||
| 3457 | - seat.2 = probed; | ||
| 3458 | } | 3525 | } |
| 3459 | cx.notify(); | 3526 | cx.notify(); |
| 3460 | }) | 3527 | }) |
| @@ -3740,6 +3807,126 @@ impl Player { | |||
| 3740 | snap_cue(self.snap, raw, len, self.snap_frames(), marks) | 3807 | snap_cue(self.snap, raw, len, self.snap_frames(), marks) |
| 3741 | } | 3808 | } |
| 3742 | 3809 | ||
| 3810 | + /// Every timeline frame that is a *source* sync point: each clip's own | ||
| 3811 | + /// grid ([`Player::syncs`]), moved onto the frames the clip plays it at. | ||
| 3812 | + /// Ascending, because the clips are and each grid is. | ||
| 3813 | + /// | ||
| 3814 | + /// This is the difference between an export that copies its picture and one | ||
| 3815 | + /// that decodes and re-codes every frame of a feature film. A cut anywhere | ||
| 3816 | + /// else leaves the copy path with a region that begins between two sync | ||
| 3817 | + /// points -- pictures whose references are not in the file -- and the whole | ||
| 3818 | + /// export falls back to the encoder ([`engine::export`] states the rule). | ||
| 3819 | + /// | ||
| 3820 | + /// Only clips at their own speed, and only video lanes: a re-timed clip is | ||
| 3821 | + /// resampled pictures, which is not a copy at any cut, and a sound lane has | ||
| 3822 | + /// no groups of pictures to begin with. | ||
| 3823 | + fn sync_frames(&self) -> Vec<u32> { | ||
| 3824 | + let Some(session) = &self.session else { | ||
| 3825 | + return Vec::new(); | ||
| 3826 | + }; | ||
| 3827 | + let sources = session.sources(); | ||
| 3828 | + let mut marks = Vec::new(); | ||
| 3829 | + for lane in session.lanes() { | ||
| 3830 | + if lane.kind != LaneKind::Video { | ||
| 3831 | + continue; | ||
| 3832 | + } | ||
| 3833 | + for clip in session.lane_clips(lane) { | ||
| 3834 | + let Some(keys) = sources | ||
| 3835 | + .get(clip.source) | ||
| 3836 | + .and_then(|entry| self.syncs.get(&entry.path)) | ||
| 3837 | + .filter(|_| clip.speed.is_normal()) | ||
| 3838 | + else { | ||
| 3839 | + continue; | ||
| 3840 | + }; | ||
| 3841 | + marks.extend( | ||
| 3842 | + keys.iter() | ||
| 3843 | + .filter(|&&key| key >= clip.in_frame && key < clip.out_frame) | ||
| 3844 | + .map(|&key| clip.start + (key - clip.in_frame)), | ||
| 3845 | + ); | ||
| 3846 | + } | ||
| 3847 | + } | ||
| 3848 | + marks.sort_unstable(); | ||
| 3849 | + marks | ||
| 3850 | + } | ||
| 3851 | + | ||
| 3852 | + /// The frame a cut asked for at `raw` really lands on: the nearest source | ||
| 3853 | + /// sync point within the snap's own tolerance, or `raw` itself where the | ||
| 3854 | + /// magnet is off, where nothing is near enough, or where the source has no | ||
| 3855 | + /// grid to offer (the walk has not answered yet, or the file is not one | ||
| 3856 | + /// this project can copy at all). | ||
| 3857 | + /// | ||
| 3858 | + /// The same tolerance the clip-edge snap uses, so one switch and one | ||
| 3859 | + /// distance govern every landing on this timeline. | ||
| 3860 | + fn cut_frame(&self, raw: u32) -> u32 { | ||
| 3861 | + if !self.snap { | ||
| 3862 | + return raw; | ||
| 3863 | + } | ||
| 3864 | + let tol = self.snap_frames(); | ||
| 3865 | + self.sync_frames() | ||
| 3866 | + .into_iter() | ||
| 3867 | + .filter(|mark| mark.abs_diff(raw) <= tol) | ||
| 3868 | + .min_by_key(|mark| mark.abs_diff(raw)) | ||
| 3869 | + .unwrap_or(raw) | ||
| 3870 | + } | ||
| 3871 | + | ||
| 3872 | + /// Whether the playhead is standing exactly on one: what the timeline's own | ||
| 3873 | + /// line says out loud, so "a cut here is copied" is on screen before the cut | ||
| 3874 | + /// rather than discovered in the export card afterwards. | ||
| 3875 | + /// | ||
| 3876 | + /// Asked every repaint, so it walks the *playhead* into each clip's source | ||
| 3877 | + /// and looks it up in that source's own sorted grid -- where | ||
| 3878 | + /// [`Player::sync_frames`] builds the whole list, which is a film's worth of | ||
| 3879 | + /// marks to allocate and sort sixty times a second. | ||
| 3880 | + fn on_sync_point(&self) -> bool { | ||
| 3881 | + let Some(session) = &self.session else { | ||
| 3882 | + return false; | ||
| 3883 | + }; | ||
| 3884 | + let now = frame_at(session.now(), self.fps); | ||
| 3885 | + let sources = session.sources(); | ||
| 3886 | + session.lanes().into_iter().any(|lane| { | ||
| 3887 | + lane.kind == LaneKind::Video | ||
| 3888 | + && session.lane_clips(lane).iter().any(|clip| { | ||
| 3889 | + clip.speed.is_normal() | ||
| 3890 | + && (clip.start..clip.start + (clip.out_frame - clip.in_frame)) | ||
| 3891 | + .contains(&now) | ||
| 3892 | + && sources | ||
| 3893 | + .get(clip.source) | ||
| 3894 | + .and_then(|entry| self.syncs.get(&entry.path)) | ||
| 3895 | + .is_some_and(|keys| { | ||
| 3896 | + keys.binary_search(&(clip.in_frame + (now - clip.start))).is_ok() | ||
| 3897 | + }) | ||
| 3898 | + }) | ||
| 3899 | + }) | ||
| 3900 | + } | ||
| 3901 | + | ||
| 3902 | + /// Puts the playhead on the sync point before or after it -- the keyboard's | ||
| 3903 | + /// half of placing a cut where the export can copy it, and the only way to | ||
| 3904 | + /// reach one exactly on a timeline zoomed out to a whole film, where one | ||
| 3905 | + /// pixel is seconds. | ||
| 3906 | + fn jump_sync(&mut self, forward: bool, cx: &mut Context<Self>) { | ||
| 3907 | + let Some(session) = &self.session else { | ||
| 3908 | + return; | ||
| 3909 | + }; | ||
| 3910 | + let now = frame_at(session.now(), self.fps); | ||
| 3911 | + let marks = self.sync_frames(); | ||
| 3912 | + let mark = match forward { | ||
| 3913 | + true => marks.iter().find(|&&mark| mark > now).copied(), | ||
| 3914 | + false => marks.iter().rev().find(|&&mark| mark < now).copied(), | ||
| 3915 | + }; | ||
| 3916 | + match mark { | ||
| 3917 | + Some(mark) => self.seek(f64::from(mark) / self.fps, cx), | ||
| 3918 | + // Said rather than swallowed: the two most likely reasons are a walk | ||
| 3919 | + // that has not answered yet and a source with no grid at all, and a | ||
| 3920 | + // key that does nothing looks broken either way. | ||
| 3921 | + None => self.notify_user(match marks.is_empty() { | ||
| 3922 | + true => "NO SYNC POINTS — this source has no keyframe grid to jump by (or it is \ | ||
| 3923 | + still being read)" | ||
| 3924 | + .into(), | ||
| 3925 | + false => "NO SYNC POINT THAT WAY — the playhead is past the last one".into(), | ||
| 3926 | + }), | ||
| 3927 | + } | ||
| 3928 | + } | ||
| 3929 | + | ||
| 3743 | /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's | 3930 | /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's |
| 3744 | /// own width drops out of it, since a pixel is now worth the same stretch of | 3931 | /// own width drops out of it, since a pixel is now worth the same stretch of |
| 3745 | /// timeline wherever the view sits. | 3932 | /// timeline wherever the view sits. |
| @@ -4069,6 +4256,7 @@ impl Player { | |||
| 4069 | self.streams.clear(); | 4256 | self.streams.clear(); |
| 4070 | self.bitrates.clear(); | 4257 | self.bitrates.clear(); |
| 4071 | self.sizes.clear(); | 4258 | self.sizes.clear(); |
| 4259 | + self.syncs.clear(); | ||
| 4072 | // Scanned off sources that are not in the library any more. | 4260 | // Scanned off sources that are not in the library any more. |
| 4073 | self.silence_levels.clear(); | 4261 | self.silence_levels.clear(); |
| 4074 | // Every gesture in flight, dropped for `reset_after_reseek`'s reason | 4262 | // Every gesture in flight, dropped for `reset_after_reseek`'s reason |
| @@ -15472,6 +15660,7 @@ fn main() { | |||
| 15472 | streams: HashMap::new(), | 15660 | streams: HashMap::new(), |
| 15473 | bitrates: HashMap::new(), | 15661 | bitrates: HashMap::new(), |
| 15474 | sizes: HashMap::new(), | 15662 | sizes: HashMap::new(), |
| 15663 | + syncs: HashMap::new(), | ||
| 15475 | decoders: HashMap::new(), | 15664 | decoders: HashMap::new(), |
| 15476 | export_seat: None, | 15665 | export_seat: None, |
| 15477 | hw_caps: None, | 15666 | hw_caps: None, |
crates/app/src/ui/cards.rsmodified+14 -5
| @@ -403,10 +403,19 @@ impl Player { | |||
| 403 | .session | 403 | .session |
| 404 | .as_ref() | 404 | .as_ref() |
| 405 | .map(|s| (s.resolution(), s.meta().frame_rate)); | 405 | .map(|s| (s.resolution(), s.meta().frame_rate)); |
| 406 | - let audio = self | 406 | + // The probe's answer where it has one -- the export's own decision, |
| 407 | - .session | 407 | + // sound included ([`engine::export::planned_seats`]) -- and the pure |
| 408 | - .as_ref() | 408 | + // prediction from the format alone until it lands, which is the same |
| 409 | - .map_or("", |s| s.planned_audio(self.format)); | 409 | + // line this card always showed. |
| 410 | + let seats = self.export_seat.as_ref().and_then(|(.., seats)| *seats); | ||
| 411 | + let audio = seats.map_or_else( | ||
| 412 | + || { | ||
| 413 | + self.session | ||
| 414 | + .as_ref() | ||
| 415 | + .map_or("", |s| s.planned_audio(self.format)) | ||
| 416 | + }, | ||
| 417 | + |(_, audio)| audio, | ||
| 418 | + ); | ||
| 410 | let settings = | 419 | let settings = |
| 411 | export_settings(self.quality, self.custom_mbps, self.format, self.audio_kbps); | 420 | export_settings(self.quality, self.custom_mbps, self.format, self.audio_kbps); |
| 412 | let size = estimated_bytes( | 421 | let size = estimated_bytes( |
| @@ -419,7 +428,7 @@ impl Player { | |||
| 419 | let tail = summary_tail( | 428 | let tail = summary_tail( |
| 420 | &self.export_path, | 429 | &self.export_path, |
| 421 | size, | 430 | size, |
| 422 | - self.export_seat.as_ref().and_then(|(.., seat)| *seat), | 431 | + seats.and_then(|(video, _)| video), |
| 423 | self.format.has_video(), | 432 | self.format.has_video(), |
| 424 | ); | 433 | ); |
| 425 | // The button says the refusal *before* it is pressed: the picked codec | 434 | // The button says the refusal *before* it is pressed: the picked codec |
crates/app/src/ui/timeline.rsmodified+18 -7
| @@ -85,15 +85,26 @@ impl Player { | |||
| 85 | // While it plays, what is decoding it goes first: it is the | 85 | // While it plays, what is decoding it goes first: it is the |
| 86 | // answer that changes as the playhead crosses a cut, and the tail | 86 | // answer that changes as the playhead crosses a cut, and the tail |
| 87 | // of this line is what a narrow window truncates. | 87 | // of this line is what a narrow window truncates. |
| 88 | + // ...and ahead of even that, where the playhead is standing when | ||
| 89 | + // that is a frame a cut is free at: it decides whether an export of | ||
| 90 | + // this film is minutes of copying or hours of encoding, which is | ||
| 91 | + // the one thing on this line worth interrupting the hints for. | ||
| 92 | + let sync = match self.on_sync_point() { | ||
| 93 | + true => "SYNC POINT — a cut here is copied, not re-encoded", | ||
| 94 | + false => "", | ||
| 95 | + }; | ||
| 88 | ( | 96 | ( |
| 89 | join_detail( | 97 | join_detail( |
| 90 | - &self.live_decode(position, state.is_playing()), | 98 | + sync, |
| 91 | - &format!( | 99 | + &join_detail( |
| 92 | - "{} copy · {} paste · {} undo · click the bar to seek · drop a file to \ | 100 | + &self.live_decode(position, state.is_playing()), |
| 93 | - import", | 101 | + &format!( |
| 94 | - key(ActionId::Copy), | 102 | + "{} copy · {} paste · {} undo · click the bar to seek · drop a file \ |
| 95 | - key(ActionId::Paste), | 103 | + to import", |
| 96 | - key(ActionId::Undo) | 104 | + key(ActionId::Copy), |
| 105 | + key(ActionId::Paste), | ||
| 106 | + key(ActionId::Undo) | ||
| 107 | + ), | ||
| 97 | ), | 108 | ), |
| 98 | ), | 109 | ), |
| 99 | filled, | 110 | filled, |