The canvas gate asks about the pair the encoder places
Browse files at this commit8d8aff1160b1f5241f6d78fe251fd01977630086Parent: 2d54df8- fix
- the canvas gate asks about the pair the encoder places
1 changed file +38 -17
- crates/engine/src/export.rs +38 -17
crates/engine/src/export.rsmodified+38 -17
| @@ -1855,11 +1855,16 @@ impl CopyPlan { | ||
| 1855 | 1855 | }; |
| 1856 | 1856 | let entries = project.sources(); |
| 1857 | 1857 | let mut sources: Vec<Option<MkvDemuxer>> = (0..entries.len()).map(|_| None).collect(); |
| 1858 | - // The coded pair each source is stored at, kept beside its demuxer: | |
| 1859 | - // the fit gate below asks what a clip's own policy does with *this* | |
| 1860 | - // source's picture on this canvas, and the picture it has is the coded | |
| 1861 | - // one, not the displayed one. | |
| 1862 | - let mut coded: Vec<Option<(u32, u32)>> = (0..entries.len()).map(|_| None).collect(); | |
| 1858 | + // The DRAWN pair each source is displayed at, kept beside its demuxer: | |
| 1859 | + // the fit gate below asks what a clip's policy does with this source's | |
| 1860 | + // picture on this canvas, and the picture the encoder places is the | |
| 1861 | + // drawn one ([`VideoMeta::width`]/`height`] -- the coded one with the | |
| 1862 | + // file's turn and its pixel aspect already applied), not the pair the | |
| 1863 | + // samples are stored at. A non-square source at its own displayed size | |
| 1864 | + // is therefore the identity again, which is what a copy of one is: the | |
| 1865 | + // aspect travels beside the track in the `Display*` elements rather | |
| 1866 | + // than being resampled into it. | |
| 1867 | + let mut drawn: Vec<Option<(u32, u32)>> = (0..entries.len()).map(|_| None).collect(); | |
| 1863 | 1868 | let mut declared: Option<(Vec<u8>, ColorDescription, crate::demux::PixelAspect)> = None; |
| 1864 | 1869 | let mut regions: Vec<CopyRegion> = Vec::new(); |
| 1865 | 1870 | let r_start = settings.range.map_or(0, |(s, _)| s); |
| @@ -1958,7 +1963,7 @@ impl CopyPlan { | ||
| 1958 | 1963 | return None; |
| 1959 | 1964 | } |
| 1960 | 1965 | sources[source] = Some(demuxer); |
| 1961 | - coded[source] = Some((source_meta.coded_width, source_meta.coded_height)); | |
| 1966 | + drawn[source] = Some((source_meta.width, source_meta.height)); | |
| 1962 | 1967 | } |
| 1963 | 1968 | let demuxer = sources.get_mut(source)?.as_mut()?; |
| 1964 | 1969 | // **The canvas gate** -- the condition this path was missing, and |
| @@ -1968,16 +1973,23 @@ impl CopyPlan { | ||
| 1968 | 1973 | // export writes has to be the size the *project* is, and those are |
| 1969 | 1974 | // two different pairs held in two different fields: |
| 1970 | 1975 | // |
| 1971 | - // * `meta.coded_width`/`coded_height` is what the demuxer wrote | |
| 1972 | - // and the check above compares against it. Only a *source* ever | |
| 1973 | - // moves it. | |
| 1976 | + // * `meta.coded_width`/`coded_height` is the pair a *copied* track | |
| 1977 | + // declares -- what the samples are stored at, and what the check | |
| 1978 | + // above compares every source against. Only a *source* ever moves | |
| 1979 | + // it. | |
| 1974 | 1980 | // * `meta.width`/`meta.height` is the canvas -- what a person chose |
| 1975 | 1981 | // with [`crate::playback::PlaybackSession::set_resolution`], |
| 1976 | - // which writes those two and leaves the coded pair exactly | |
| 1977 | - // where it was. The encode door sizes everything from it | |
| 1982 | + // which writes those two and leaves the coded pair exactly where | |
| 1983 | + // it was. The encode door sizes everything from it | |
| 1978 | 1984 | // ([`Composer`]), so this is the size the file must have. |
| 1979 | 1985 | // |
| 1980 | - // A canvas that differs from the source's coded pair means every | |
| 1986 | + // ...and the two meet in the *drawn* pair: what this span is | |
| 1987 | + // composed from is the source's picture as a decoder delivers it, | |
| 1988 | + // turn and pixel aspect already applied | |
| 1989 | + // ([`VideoMeta::width`]/`height`]), which is what the check below is | |
| 1990 | + // asked about. | |
| 1991 | + // | |
| 1992 | + // A canvas that differs from the source's drawn pair means every | |
| 1981 | 1993 | // span is a picture the export has to *place onto* that canvas, and |
| 1982 | 1994 | // there is no resampler on this path at all -- so a copy would ship |
| 1983 | 1995 | // the source's frame size under the project's name, with the seat |
| @@ -1989,13 +2001,13 @@ impl CopyPlan { | ||
| 1989 | 2001 | // is this clip's policy the identity for this source on this canvas |
| 1990 | 2002 | // -- because that is the one thing a condition has to mean here: |
| 1991 | 2003 | // [`fit_is_identity`] computes it from [`scale::fit_rect`] itself, |
| 1992 | - // so it holds for `Fill` on a canvas the size of the source's own | |
| 1993 | - // samples (there is nothing to crop there) and refuses a canvas of | |
| 1994 | - // another size under *every* policy, and a | |
| 2004 | + // so it holds for `Fill` on a canvas the size of the picture the | |
| 2005 | + // source draws at (there is nothing to crop there) and refuses a | |
| 2006 | + // canvas of another size under *every* policy, and a | |
| 1995 | 2007 | // [`crate::scale::FitPolicy`] added later is judged by what it |
| 1996 | 2008 | // places rather than by being absent from a list here. |
| 1997 | 2009 | if !fit_is_identity( |
| 1998 | - coded.get(source).copied().flatten()?, | |
| 2010 | + drawn.get(source).copied().flatten()?, | |
| 1999 | 2011 | (meta.width, meta.height), |
| 2000 | 2012 | project.composite_fit_at(span.start), |
| 2001 | 2013 | ) { |
| @@ -2114,13 +2126,22 @@ impl CopyPlan { | ||
| 2114 | 2126 | } |
| 2115 | 2127 | } |
| 2116 | 2128 | |
| 2117 | -/// Whether `policy` places a source stored at `source` onto this `canvas` | |
| 2129 | +/// Whether `policy` places the picture `source` is DRAWN at onto this `canvas` | |
| 2118 | 2130 | /// without touching a sample: the whole picture, at the whole canvas, 1:1. |
| 2119 | 2131 | /// |
| 2120 | 2132 | /// The 1:1 is the half the rects cannot state: a source scaled onto a canvas |
| 2121 | 2133 | /// of another aspect is placed whole and cropped nowhere, which is a resize |
| 2122 | 2134 | /// and not an identity -- so the pairs themselves are compared first. |
| 2123 | 2135 | /// |
| 2136 | +/// The pair asked about is the **drawn** one ([`VideoMeta::width`]/`height`]), | |
| 2137 | +/// never the coded one: what the fit is composed against is what a decoder | |
| 2138 | +/// hands the canvas after the file's turn and its pixel aspect have been | |
| 2139 | +/// applied, so a 1440x1080 file with a 4:3 sample aspect is a 1920x1080 | |
| 2140 | +/// picture, and a project at 1920x1080 is copying it exactly. The coded pair | |
| 2141 | +/// has its own question -- what a copied track *declares* -- and the coded-to- | |
| 2142 | +/// coded check in [`CopyPlan::of`] already asks that one; asking it twice, in | |
| 2143 | +/// the geometry's stead, refuses a copy main performs byte for byte. | |
| 2144 | +/// | |
| 2124 | 2145 | /// Asked from [`scale::fit_rect`] -- the one function that *is* a fit policy's |
| 2125 | 2146 | /// meaning -- rather than from the policy itself, which is what makes this |
| 2126 | 2147 | /// canvas-aware twice over: `Fill` on a canvas the size of the source's own |