forge
Explore
Log in

Don't you dare go Hollow

⏪ demux: keep the turn, drop the display size; widen the block walk's ticks

Browse files at this commit

9b42f9f179c23748658d786dee3ffac18de4808fAhmet Kaan GümüşParent: 30b435d
The display-size adoption is reverted: `VideoMeta.width/height` mean exactly
what they meant at base again -- the coded size with the turn applied -- and
nothing reads `pasp`, `DisplayWidth`, `DisplayHeight` or `DisplayUnit` any more.
Reading them without applying the pixel aspect anywhere in the pixel pipeline
made an anamorphic source *worse* rather than better: the canvas of a freshly
opened file is built from `meta.width/height`, while `Render::frame` only rotates
and placement is an aspect-preserving `Fit` of the coded frame, so a 1440x1080
source became a 1440-wide pillarboxed picture inside a 1920x1080 canvas with the
bars baked into the preview and the export; and `CopyPlan::of` hands those two
numbers to `CopyParams`, so an exact Matroska copy declared PixelWidth 1920 while
copying 1440x1080 blocks and dropped the source's display elements -- a file that
plays right nowhere. Anamorphic support is a feature slice (the stretch stage in
`export::place_picture` and in the decode funnel), not a container-reader fix, so
it leaves together with its fixtures and the test that asserted it.

Kept, because they are the defect this lane was chartered for: the Matroska
`Projection` roll is read as the turn it is (`rotation_of_roll`,
`projection_rotation`, with the same refusal by name for anything that is not a
quarter turn) -- now asserted for the mkv twin too, which was generated but read
by nothing before.

And the multiply the subtitle walk had is widened for the block walk a copy
reads: `coded_block`'s `ts_ns` was `block.ts * timestamp_scale` in `i64`, where a
crafted cluster timestamp overflows -- a panic in debug and a negative block time
in release, silently. One `ticks_scaled` now serves both walks, and the unit test
covers both (microseconds at `per_tick` 1_000, nanoseconds at 1).

cargo check -p engine --all-targets: 0 warnings. cargo test -p engine --test
rotation --test subtitles: 4 passed + 22 passed. cargo test -p engine --lib: 392
passed, 0 failed.
crates/engine/src/demux.rsmodified+52 -137
@@ -813,7 +813,7 @@ impl Mp4Demuxer {
813 // hev1 in that the parameter sets may not repeat in-band, which costs813 // hev1 in that the parameter sets may not repeat in-band, which costs
814 // nothing: they are re-injected out of `hvcC` ahead of every sync sample814 // nothing: they are re-injected out of `hvcC` ahead of every sync sample
815 // either way, exactly as an AV1 sequence header is out of `av1C`.815 // either way, exactly as an AV1 sequence header is out of `av1C`.
816- let (track, codec, entry) = reader816+ let (track, codec) = reader
817 .moov817 .moov
818 .traks818 .traks
819 .iter()819 .iter()
@@ -822,8 +822,8 @@ impl Mp4Demuxer {
822 matches!(t.track_type(), Ok(TrackType::Video))822 matches!(t.track_type(), Ok(TrackType::Video))
823 .then(|| sample_entry(path, t.track_id()).ok())823 .then(|| sample_entry(path, t.track_id()).ok())
824 .flatten()824 .flatten()
825- .and_then(|(kind, entry)| mp4_codec(&kind).map(|codec| (codec, entry)))825+ .and_then(|(kind, _)| mp4_codec(&kind))
826- .map(|(codec, entry)| (t, codec, entry))826+ .map(|codec| (t, codec))
827 })827 })
828 // Named, for the same reason the Matroska door names it: "no video828 // Named, for the same reason the Matroska door names it: "no video
829 // track" is a lie about a file that has one in a codec this does not829 // track" is a lie about a file that has one in a codec this does not
@@ -852,14 +852,9 @@ impl Mp4Demuxer {
852 None => Rotation::None,852 None => Rotation::None,
853 };853 };
854 let (coded_w, coded_h) = (u32::from(track.width()), u32::from(track.height()));854 let (coded_w, coded_h) = (u32::from(track.width()), u32::from(track.height()));
855- // The picture's displayed shape, in the same two steps the Matroska door
856- // resolves its `Display*` elements in: the aspect the sample entry
857- // states, then the turn. A `pasp`-carrying file and the mkv remux of it
858- // report one size.
859- let shown = pasp_size(&entry, coded_w, coded_h).unwrap_or((coded_w, coded_h));
860 let (width, height) = match rotation.swaps_axes() {855 let (width, height) = match rotation.swaps_axes() {
861- true => (shown.1, shown.0),856+ true => (coded_h, coded_w),
862- false => shown,857+ false => (coded_w, coded_h),
863 };858 };
864 let meta = VideoMeta {859 let meta = VideoMeta {
865 width,860 width,
@@ -1314,18 +1309,13 @@ impl MkvDemuxer {
1314 }1309 }
1315 }1310 }
1316 };1311 };
1317- // The picture's *displayed* shape, resolved exactly as the mp4 door1312+ // The coded size, swapped where the turn is a quarter one: a portrait
1318- // resolves it: the size the file states its pictures are shown at1313+ // `.mkv` stores a landscape picture plus the turn, so the displayed
1319- // ([`display_size`] -- an anamorphic track's `DisplayWidth`, which is1314+ // shape is the coded one turned -- the same two numbers the mp4 door
1320- // the shape the coded pixels are stretched to and the shape a player1315+ // swaps, off the same kind of turn.
1321- // shows), then swapped where the turn is a quarter one. The file states
1322- // that size in the *coded* orientation -- it is a property of the
1323- // picture, not of the screen -- so the turn comes second, here and
1324- // there.
1325- let shown = video.display.unwrap_or((video.width, video.height));
1326 let (width, height) = match video.rotation.swaps_axes() {1316 let (width, height) = match video.rotation.swaps_axes() {
1327- true => (shown.1, shown.0),1317+ true => (video.height, video.width),
1328- false => shown,1318+ false => (video.width, video.height),
1329 };1319 };
1330 let meta = VideoMeta {1320 let meta = VideoMeta {
1331 width,1321 width,
@@ -1801,7 +1791,11 @@ impl MkvDemuxer {
1801 Ok(Some(CodedBlock {1791 Ok(Some(CodedBlock {
1802 bytes: &self.scratch,1792 bytes: &self.scratch,
1803 key: block.key,1793 key: block.key,
1804- ts_ns: block.ts * self.timestamp_scale as i64,1794+ // Widened and fallible, exactly as the subtitle walk's tick scale
1795+ // is ([`ticks_scaled`]): `block.ts` is whatever the file says, so the
1796+ // multiply overflows an `i64` on a crafted cluster and a copy would
1797+ // write a block time that wrapped negative.
1798+ ts_ns: ticks_scaled(block.ts, self.timestamp_scale, 1)?,
1805 }))1799 }))
1806 }1800 }
1807 }1801 }
@@ -2011,10 +2005,6 @@ struct MkvVideo {
2011 number: u64,2005 number: u64,
2012 width: u32,2006 width: u32,
2013 height: u32,2007 height: u32,
2014- /// The size the file displays its pictures at (`DisplayWidth`/
2015- /// `DisplayHeight`, stated in the pixel unit), or `None` -- which is every
2016- /// square-pixel file, and falls back to the pixel dims above.
2017- display: Option<(u32, u32)>,
2018 /// The quarter turn the track's `Projection` asks for;2008 /// The quarter turn the track's `Projection` asks for;
2019 /// [`Rotation::None`] where it states none.2009 /// [`Rotation::None`] where it states none.
2020 rotation: Rotation,2010 rotation: Rotation,
@@ -2165,16 +2155,6 @@ const DEFAULT_DURATION: u32 = 0x23E383;
2165 const VIDEO: u32 = 0xE0;2155 const VIDEO: u32 = 0xE0;
2166 const PIXEL_WIDTH: u32 = 0xB0;2156 const PIXEL_WIDTH: u32 = 0xB0;
2167 const PIXEL_HEIGHT: u32 = 0xBA;2157 const PIXEL_HEIGHT: u32 = 0xBA;
2168-// ...and the size the track's pictures are *shown* at, which a square-pixel
2169-// file -- the common case -- states none of, so absence falls back to the pixel
2170-// dims above. IDs checked against RFC 9559 and byte-verified against an
2171-// ffmpeg-written fixture before the test that reads them was trusted.
2172-const DISPLAY_WIDTH: u32 = 0x54B0;
2173-const DISPLAY_HEIGHT: u32 = 0x54BA;
2174-/// The unit `DisplayWidth`/`DisplayHeight` are counted in: 0 pixels, then
2175-/// centimetres, inches, a bare aspect, unknown. Only the pixel unit resolves
2176-/// without a physical screen, so any other unit keeps the pixel dims.
2177-const DISPLAY_UNIT: u32 = 0x54B2;
2178 // The track's projection: how the flat picture sits in space. A roll on the2158 // The track's projection: how the flat picture sits in space. A roll on the
2179 // rectangular projection (type 0) is how a Matroska muxer states what an mp42159 // rectangular projection (type 0) is how a Matroska muxer states what an mp4
2180 // states with its `tkhd` matrix -- mkvmerge has translated display matrices2160 // states with its `tkhd` matrix -- mkvmerge has translated display matrices
@@ -2182,7 +2162,8 @@ const DISPLAY_UNIT: u32 = 0x54B2;
2182 // rotated input -- so the same quarter turns are read off it. Anything else (a2162 // rotated input -- so the same quarter turns are read off it. Anything else (a
2183 // spherical or mesh projection, a yaw/pitch pose) is not a turn this engine can2163 // spherical or mesh projection, a yaw/pitch pose) is not a turn this engine can
2184 // make, and is refused by name like the mp4 door refuses a matrix that is not a2164 // make, and is refused by name like the mp4 door refuses a matrix that is not a
2185-// quarter turn.2165+// quarter turn; a spherical one's pose is the sphere's orientation rather than
2166+// the picture's and is left alone ([`projection_rotation`]).
2186 const PROJECTION: u32 = 0x7670;2167 const PROJECTION: u32 = 0x7670;
2187 const PROJECTION_TYPE: u32 = 0x7671;2168 const PROJECTION_TYPE: u32 = 0x7671;
2188 const PROJECTION_POSE_YAW: u32 = 0x7673;2169 const PROJECTION_POSE_YAW: u32 = 0x7673;
@@ -2438,7 +2419,6 @@ fn mkv_track_entry(
2438 ) -> crate::Result<MkvEntry> {2419 ) -> crate::Result<MkvEntry> {
2439 let (mut number, mut kind, mut codec, mut default_duration) = (0, 0, String::new(), None);2420 let (mut number, mut kind, mut codec, mut default_duration) = (0, 0, String::new(), None);
2440 let (mut width, mut height, mut config) = (0, 0, Vec::new());2421 let (mut width, mut height, mut config) = (0, 0, Vec::new());
2441- let mut display = None;
2442 let mut rotation = Rotation::None;2422 let mut rotation = Rotation::None;
2443 let (mut language, mut name, mut bcp47) = (String::new(), String::new(), String::new());2423 let (mut language, mut name, mut bcp47) = (String::new(), String::new(), String::new());
2444 let mut tags = Tags::default();2424 let mut tags = Tags::default();
@@ -2462,14 +2442,10 @@ fn mkv_track_entry(
2462 CODEC_PRIVATE => config = ebml_bytes(file, body, stop)?,2442 CODEC_PRIVATE => config = ebml_bytes(file, body, stop)?,
2463 VIDEO => {2443 VIDEO => {
2464 let mut at = body;2444 let mut at = body;
2465- let (mut display_width, mut display_height, mut display_unit) = (None, None, None);
2466 while let Some(e) = ebml_element(file, at, stop)? {2445 while let Some(e) = ebml_element(file, at, stop)? {
2467 match e.0 {2446 match e.0 {
2468 PIXEL_WIDTH => width = ebml_uint(file, e.1, e.2)? as u32,2447 PIXEL_WIDTH => width = ebml_uint(file, e.1, e.2)? as u32,
2469 PIXEL_HEIGHT => height = ebml_uint(file, e.1, e.2)? as u32,2448 PIXEL_HEIGHT => height = ebml_uint(file, e.1, e.2)? as u32,
2470- DISPLAY_WIDTH => display_width = Some(ebml_uint(file, e.1, e.2)?),
2471- DISPLAY_HEIGHT => display_height = Some(ebml_uint(file, e.1, e.2)?),
2472- DISPLAY_UNIT => display_unit = Some(ebml_uint(file, e.1, e.2)?),
2473 PROJECTION => {2449 PROJECTION => {
2474 let (mut kind, mut yaw, mut pitch, mut roll) =2450 let (mut kind, mut yaw, mut pitch, mut roll) =
2475 (0u64, 0.0f64, 0.0f64, 0.0f64);2451 (0u64, 0.0f64, 0.0f64, 0.0f64);
@@ -2542,11 +2518,6 @@ fn mkv_track_entry(
2542 }2518 }
2543 at = e.2;2519 at = e.2;
2544 }2520 }
2545- // Resolved here rather than per element: `DisplayWidth` and
2546- // `DisplayHeight` can come in either order and their unit is a
2547- // *ratio*, so neither half means anything until the pixel dims
2548- // and the unit are all in hand.
2549- display = display_size(height, display_width, display_height, display_unit);
2550 }2521 }
2551 _ => {}2522 _ => {}
2552 }2523 }
@@ -2619,7 +2590,6 @@ fn mkv_track_entry(
2619 number,2590 number,
2620 width,2591 width,
2621 height,2592 height,
2622- display,
2623 rotation,2593 rotation,
2624 tags,2594 tags,
2625 light,2595 light,
@@ -2832,70 +2802,6 @@ fn projection_rotation(kind: u64, yaw: f64, pitch: f64, roll: f64) -> crate::Res
2832 }2802 }
2833 }2803 }
2834 2804
2835-/// The size a track's `Display*` elements say its pictures are shown at, or
2836-/// `None` for a file that states none -- or states one in a unit nothing here can
2837-/// resolve, which falls back to the pixel dims for the same reason.
2838-///
2839-/// The mkv spelling of what an mp4 keeps in its sample entry's `pasp` box, and
2840-/// resolved the same way round: the **coded height is kept** and the width is
2841-/// the one the file's own numbers make it. That is what anamorphic video is:
2842-/// HDV's 1440x1080 is 1920x1080 wide when shown, DVD's 720x576 is 1024x576 -- never
2843-/// 1440x810 or 720x405, which is the vertical resolution thrown away.
2844-///
2845-/// Only two of the five units can be resolved without a screen to show the
2846-/// picture on: **pixels** (0, the spec's default where the file states no unit)
2847-/// is the size itself, and the **display aspect ratio** (3) is the shape the
2848-/// size is derived from. Centimetres, inches and "unknown" are left to the pixel
2849-/// dims -- a physical size says nothing about how many pixels to show, and a DPI
2850-/// guessed here would be this engine's invention rather than the file's word.
2851-fn display_size(
2852- pixel_height: u32,
2853- display_width: Option<u64>,
2854- display_height: Option<u64>,
2855- display_unit: Option<u64>,
2856-) -> Option<(u32, u32)> {
2857- let (across, down) = match (display_width, display_height) {
2858- (Some(across), Some(down)) if across > 0 && down > 0 => (across, down),
2859- _ => return None,
2860- };
2861- match display_unit.unwrap_or(0) {
2862- 0 => Some((u32::try_from(across).ok()?, u32::try_from(down).ok()?)),
2863- 3 => Some((
2864- u32::try_from((u64::from(pixel_height) * across + down / 2) / down).ok()?,
2865- pixel_height,
2866- )),
2867- _ => None,
2868- }
2869-}
2870-
2871-/// The size a sample entry's `pasp` box says the pictures are shown at -- an
2872-/// mp4's spelling of [`display_size`], read the same way: the box is a *sample*
2873-/// aspect ratio, so the coded height is kept and the width is the one the ratio
2874-/// makes it (1440x1080 at `pasp` 4:3 is the 1920x1080 an HDV file is meant to be
2875-/// shown at).
2876-///
2877-/// The box is one of the sample entry's *children*, so the walk starts after the
2878-/// entry's own fixed fields rather than at its first byte: a `boxes` pass over a
2879-/// whole `avc1` payload reads a length out of its `data_reference_index` and
2880-/// finds nothing.
2881-fn pasp_size(entry: &[u8], coded_w: u32, coded_h: u32) -> Option<(u32, u32)> {
2882- let payload = child(entry.get(VISUAL_SAMPLE_ENTRY..)?, b"pasp")?;
2883- let across = u32::from_be_bytes(payload.get(..4)?.try_into().ok()?);
2884- let down = u32::from_be_bytes(payload.get(4..8)?.try_into().ok()?);
2885- if across == 0 || down == 0 {
2886- return None;
2887- }
2888- let width = (u64::from(coded_w) * u64::from(across) + u64::from(down) / 2) / u64::from(down);
2889- Some((u32::try_from(width).ok()?, coded_h))
2890-}
2891-
2892-/// What a `VisualSampleEntry` states before its child boxes: the reserved word
2893-/// and `data_reference_index` (8), the pre-defined and reserved words (16), the
2894-/// coded width and height (4), the two fixed-point resolutions (8), a reserved
2895-/// word (4), the frame count (2), the 32-byte compressor name, the depth (2) and
2896-/// one more reserved word (2).
2897-const VISUAL_SAMPLE_ENTRY: usize = 78;
2898-
2899 /// Why an mp4 came back with no picture, by the fourcc of the video track it2805 /// Why an mp4 came back with no picture, by the fourcc of the video track it
2900 /// does carry: `avc3` and `mp4v` are files with video in them, and telling their2806 /// does carry: `avc3` and `mp4v` are files with video in them, and telling their
2901 /// owner there is none sends them looking for a fault that is not in the file.2807 /// owner there is none sends them looking for a fault that is not in the file.
@@ -4524,10 +4430,10 @@ fn mkv_subtitle_blocks(
4524 const BLOCK_DURATION: u32 = 0x9B;4430 const BLOCK_DURATION: u32 = 0x9B;
4525 // Ticks to microseconds, the unit `MkvCue` keeps. `TimestampScale` is4431 // Ticks to microseconds, the unit `MkvCue` keeps. `TimestampScale` is
4526 // nanoseconds per tick and is a millisecond in every file anything writes.4432 // nanoseconds per tick and is a millisecond in every file anything writes.
4527- // [`ticks_to_us`] does the arithmetic: it is widened and fallible, and a4433+ // [`ticks_scaled`] does the arithmetic: it is widened and fallible, and a
4528 // corrupt cluster timestamp is refused rather than wrapped into a negative4434 // corrupt cluster timestamp is refused rather than wrapped into a negative
4529 // cue time -- see the test beside it.4435 // cue time -- see the test beside it.
4530- let us = |ticks: i64| ticks_to_us(ticks, timestamp_scale);4436+ let us = |ticks: i64| ticks_scaled(ticks, timestamp_scale, 1_000);
4531 let mut at = segment.0;4437 let mut at = segment.0;
4532 while let Some((id, body, stop)) = ebml_element(file, at, segment.1)? {4438 while let Some((id, body, stop)) = ebml_element(file, at, segment.1)? {
4533 // The import's second walk, stopped by the same Cancel as its first.4439 // The import's second walk, stopped by the same Cancel as its first.
@@ -4607,20 +4513,23 @@ fn mkv_subtitle_blocks(
4607 Ok(())4513 Ok(())
4608 }4514 }
4609 4515
4610-/// A tick count as the microseconds [`MkvCue`] keeps, or the refusal a corrupt4516+/// A tick count scaled out of the file's own clock, or the refusal a corrupt one
4611-/// one earns.4517+/// earns: `ticks * TimestampScale / per_tick`, which is microseconds for the
4518+/// subtitle walk (`per_tick` 1_000) and nanoseconds for the block walk a copy
4519+/// reads (`per_tick` 1).
4612 ///4520 ///
4613 /// The multiply is widened to `i128` rather than done in `i64`, and a result that4521 /// The multiply is widened to `i128` rather than done in `i64`, and a result that
4614 /// does not fit is refused rather than saturated: both numbers are the file's --4522 /// does not fit is refused rather than saturated: both numbers are the file's --
4615-/// a cluster timestamp is an EBML uint nothing bounds and `TimestampScale` is a4523+/// a cluster or block timestamp is an EBML uint nothing bounds, and
4616-/// scale it chooses -- so `ticks * timestamp_scale` overflows on a crafted file,4524+/// `TimestampScale` is a scale it chooses -- so `ticks * timestamp_scale`
4617-/// which is a panic in debug and a *negative* cue time in release, silently.4525+/// overflows on a crafted file, which is a panic in debug and a *negative*
4618-/// Widened, no product can overflow; a timestamp that then does not fit the4526+/// timestamp in release, silently. Widened no product can overflow; a timestamp
4619-/// answer is the same class of corrupt as the oversized block refused above, and4527+/// that then does not fit its unit is the same class of corrupt as the oversized
4620-/// gets the same loud refusal rather than a cue at a time no clock can hold.4528+/// block refused above, and gets the same loud refusal rather than a time no
4621-fn ticks_to_us(ticks: i64, timestamp_scale: u64) -> crate::Result<i64> {4529+/// clock can hold.
4622- i64::try_from(i128::from(ticks) * i128::from(timestamp_scale) / 1_000)4530+fn ticks_scaled(ticks: i64, timestamp_scale: u64, per_tick: u64) -> crate::Result<i64> {
4623- .map_err(|_| "a Matroska subtitle timestamp no clock can hold".into())4531+ i64::try_from(i128::from(ticks) * i128::from(timestamp_scale) / i128::from(per_tick))
4532+ .map_err(|_| "a Matroska timestamp no clock can hold".into())
4624 }4533 }
4625 4534
4626 /// A string element, without the trailing NULs a `Name` may be padded with.4535 /// A string element, without the trailing NULs a `Name` may be padded with.
@@ -4635,23 +4544,29 @@ fn string_of(file: &mut File, body: u64, stop: u64) -> crate::Result<String> {
4635 mod tests {4544 mod tests {
4636 use super::*;4545 use super::*;
4637 4546
4638- /// A corrupt cluster timestamp is refused, not wrapped: the product is where4547+ /// Both walks that scale a file's own clock: the subtitle one
4639- /// an `i64` overflows, so this is the assertion that fails (as a panic in4548+ /// (microseconds, `per_tick` 1_000) and the block one a copy reads
4640- /// debug, as a negative cue time in release) without the widening -- the4549+ /// (nanoseconds, `per_tick` 1). The product is where an `i64` overflows, so
4641- /// shape a hostile `.mkv` reaches through `mkv_subtitle_blocks`.4550+ /// these are the assertions that fail -- a panic in debug, a negative
4551+ /// timestamp in release -- without the widening.
4642 #[test]4552 #[test]
4643- fn a_subtitle_timestamp_no_clock_can_hold_is_refused() {4553+ fn a_timestamp_no_clock_can_hold_is_refused() {
4644 // A millisecond scale, which is every file anything writes: 1000 ticks4554 // A millisecond scale, which is every file anything writes: 1000 ticks
4645- // is one second.4555+ // is one second, in either unit.
4646- assert_eq!(ticks_to_us(1_000, 1_000_000).unwrap(), 1_000_000);4556+ assert_eq!(ticks_scaled(1_000, 1_000_000, 1_000).unwrap(), 1_000_000);
4647- assert_eq!(ticks_to_us(0, 1_000_000).unwrap(), 0);4557+ assert_eq!(ticks_scaled(0, 1_000_000, 1_000).unwrap(), 0);
4558+ assert_eq!(ticks_scaled(1_000, 1_000_000, 1).unwrap(), 1_000_000_000);
4648 // A nanosecond scale and the largest tick count an EBML uint can cast4559 // A nanosecond scale and the largest tick count an EBML uint can cast
4649- // to: 600 million years of microseconds, which no `i64` holds.4560+ // to: tens of thousands of years of nanoseconds, which no `i64` holds.
4561+ assert!(
4562+ ticks_scaled(i64::MAX, 1_000_000_000, 1).is_err(),
4563+ "the block walk's product must not wrap into a negative time"
4564+ );
4650 assert!(4565 assert!(
4651- ticks_to_us(i64::MAX, 1_000_000_000).is_err(),4566+ ticks_scaled(i64::MAX, 1_000_000_000, 1_000).is_err(),
4652- "the product must not wrap into a negative cue time"4567+ "the subtitle walk's product must not wrap into a negative cue time"
4653 );4568 );
4654- assert!(ticks_to_us(i64::MIN, 1_000_000_000).is_err());4569+ assert!(ticks_scaled(i64::MIN, 1_000_000_000, 1_000).is_err());
4655 }4570 }
4656 4571
4657 fn asset(name: &str) -> std::path::PathBuf {4572 fn asset(name: &str) -> std::path::PathBuf {
crates/engine/tests/rotation.rsmodified+24 -45
@@ -253,54 +253,33 @@ fn an_export_of_a_turned_file_is_upright_and_portrait() {
253 );253 );
254 }254 }
255 255
256-/// A matrix that is not a quarter turn is refused by name at the door, with the256+/// A turn that is not a quarter turn is refused by name at the door, with the
257-/// angle in the sentence -- the honest answer to a picture this engine has no257+/// angle in the sentence -- the honest answer to a picture this engine has no way
258-/// way to show right. The capability really is absent: nothing here turns by an258+/// to show right. The capability really is absent: nothing here turns by an
259-/// arbitrary angle ([`engine::scale::rotate_i420_90s`] takes whole quarters),259+/// arbitrary angle ([`engine::scale::rotate_i420_90s`] takes whole quarters), and
260-/// and the refusal is what says so instead of a sideways picture.260+/// the refusal is what says so instead of a sideways picture.
261-#[test]
262-fn a_matrix_that_is_not_a_quarter_turn_is_refused_by_name() {
263- let error = match engine::demux::Demuxer::open(&asset("test_rotation45.mp4")) {
264- Ok(_) => panic!("45 degrees is not a quarter turn, and opening it must not succeed"),
265- Err(error) => error,
266- };
267- assert!(
268- engine::UnsupportedRotation::is_it(&error),
269- "the refusal is the named one, not a generic failure: {error}"
270- );
271- let said = error.to_string();
272- assert!(
273- said.contains("45.0°") && said.contains("quarter turn"),
274- "the refusal names the angle it cannot make: {said}"
275- );
276-}
277-
278-/// An anamorphic file's own numbers decide the shape the engine reports: the
279-/// pixels are 1440x1080 and the file says they are shown 1920x1080 wide, which is
280-/// what a player shows -- so that is the shape this engine reports, and the shape
281-/// the preview and the export must therefore place the coded pixels at. A
282-/// squashed picture in a 4:3 frame is the same class of wrong as a portrait file
283-/// on its side, and both are the file's own numbers being ignored.
284 ///261 ///
285-/// **Both spellings**, because they are what the two doors read and a file262+/// **Both doors**, because they are two spellings of one question: an mp4 states
286-/// remuxed from one to the other must not change shape: Matroska states the263+/// the turn in a `tkhd` matrix and an mkv in a `Projection` roll, and a file
287-/// *display aspect ratio* in `DisplayWidth`/`DisplayHeight` -- ffmpeg writes the264+/// whose picture is 45 degrees off is the same missing capability either way --
288-/// ratio unit, so `16x9` and not `1920x1080` (`DisplayUnit` 3) -- while an mp4265+/// the mkv twin exists for exactly this assertion.
289-/// states the *sample* aspect ratio in a `pasp` box beside its `avc1` (`4:3`).
290-/// Both resolve to the coded height at that aspect.
291 #[test]266 #[test]
292-fn an_anamorphic_file_reports_the_shape_it_is_shown_at() {267+fn a_turn_that_is_not_a_quarter_turn_is_refused_by_name() {
293- for file in ["test_anamorphic.mp4", "test_anamorphic.mkv"] {268+ for file in ["test_rotation45.mp4", "test_rotation45.mkv"] {
294- let (meta, _) = engine::demux::Demuxer::open(&asset(file)).expect("open a fixture");269+ let error = match engine::demux::Demuxer::open(&asset(file)) {
295- assert_eq!(270+ Ok(_) => {
296- [meta.width, meta.height],271+ panic!("45 degrees is not a quarter turn, and opening {file} must not succeed")
297- [1920, 1080],272+ }
298- "{file}: the displayed shape, not the 1440x1080 the samples are stored at"273+ Err(error) => error,
274+ };
275+ assert!(
276+ engine::UnsupportedRotation::is_it(&error),
277+ "{file}: the refusal is the named one, not a generic failure: {error}"
299 );278 );
300- assert_eq!(279+ let said = error.to_string();
301- meta.rotation,280+ assert!(
302- Rotation::None,281+ said.contains("45.0°") && said.contains("quarter turn"),
303- "{file}: no turn is asked for, and a non-square sample is not one"282+ "{file}: the refusal names the angle it cannot make: {said}"
304 );283 );
305 }284 }
306 }285 }
scripts/gen_fixtures.shmodified+0 -24
@@ -750,29 +750,5 @@ for deg in 90 180 270 45; do
750 done750 done
751 rm -f assets/.rotation_src.mp4751 rm -f assets/.rotation_src.mp4
752 752
753-# Anamorphic: the same four coloured quadrants in a frame whose samples are not
754-# square, so the file's own numbers say the picture is 1920x1080 while the pixels
755-# it carries are 1440x1080 -- exactly HDV, and the shape `tests/rotation.rs`
756-# asserts the engine reports and places the pixels at. Both containers state it
757-# and neither door used to read either spelling, so an anamorphic source probed,
758-# previewed and exported squashed.
759-#
760-# The two spellings, byte-verified the same way: Matroska in `DisplayWidth`
761-# (`0x54B0`) / `DisplayHeight` (`0x54BA`) / `DisplayUnit` (`0x54B2`), where ffmpeg
762-# writes the *display aspect ratio* unit (3) and therefore `16x9` rather than
763-# `1920x1080`; mp4 in a `pasp` box beside the `avc1` sample entry, holding the
764-# *sample* aspect ratio (`4:3`). Read the same way round out of both: the coded
765-# height is kept and the width is the one the file's ratio makes it.
766-ffmpeg -y -f lavfi -i "color=c=red:s=720x540:d=1:r=30,format=yuv420p" \
767- -f lavfi -i "color=c=green:s=720x540:d=1:r=30,format=yuv420p" \
768- -f lavfi -i "color=c=blue:s=720x540:d=1:r=30,format=yuv420p" \
769- -f lavfi -i "color=c=yellow:s=720x540:d=1:r=30,format=yuv420p" \
770- -filter_complex "[0:v][1:v]hstack[top];[2:v][3:v]hstack[bot];[top][bot]vstack[v]" \
771- -map "[v]" -frames:v 30 -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
772- assets/.anamorphic_src.mp4
773-ffmpeg -y -i assets/.anamorphic_src.mp4 -vf "setsar=4/3" -c:v libx264 \
774- -profile:v baseline -pix_fmt yuv420p assets/test_anamorphic.mp4
775-ffmpeg -y -i assets/test_anamorphic.mp4 -c copy assets/test_anamorphic.mkv
776-rm -f assets/.anamorphic_src.mp4
777 753
778 echo "fixtures written to assets/"754 echo "fixtures written to assets/"