Judge proxy candidacy on the coded pair, not the displayed one
Browse files at this commit6924a196cb0ae074b7fbbfee0325fdea80770e8bParent: 0c9d76c- fix
- judge proxy candidacy on the coded pair, not the displayed one
1 changed file +71 -8
- crates/engine/src/proxy.rs +71 -8
crates/engine/src/proxy.rsmodified+71 -8
| @@ -32,8 +32,8 @@ | ||
| 32 | 32 | //! cancel a file export has ([`Job`]). |
| 33 | 33 | |
| 34 | 34 | use std::path::{Path, PathBuf}; |
| 35 | -use std::sync::atomic::AtomicBool; | |
| 36 | 35 | use std::sync::Arc; |
| 36 | +use std::sync::atomic::AtomicBool; | |
| 37 | 37 | use std::time::UNIX_EPOCH; |
| 38 | 38 | |
| 39 | 39 | use crate::demux::{Codec, Demuxer, NoVideoTrack, VideoMeta}; |
| @@ -93,8 +93,20 @@ const BITS_PER_PIXEL: f64 = 0.3; | ||
| 93 | 93 | /// Whether this is a file worth standing in for: bigger than 1080p, or coded in |
| 94 | 94 | /// something this machine decodes slowly even at 1080p. H.264 at or under 1080p |
| 95 | 95 | /// plays natively and a proxy of it would cost time and buy nothing. |
| 96 | +/// | |
| 97 | +/// The size test reads the **coded** pair, not the displayed one | |
| 98 | +/// ([`VideoMeta::coded_width`]): those differ wherever the file carries a | |
| 99 | +/// display matrix or a non-square pixel, and a 1920x1080 H.264 phone clip with | |
| 100 | +/// a 90-degree turn *displays* as 1080x1920 -- so judging the displayed pair | |
| 101 | +/// called a clip that plays natively proxy-worthy and put a whole film through | |
| 102 | +/// a decoder and an encoder to stand in for something already at speed. What a | |
| 103 | +/// decoder is asked to chew through is the stored raster, so the stored raster | |
| 104 | +/// is what this is about; the codec test is not a size question and is | |
| 105 | +/// unchanged. | |
| 96 | 106 | pub fn wanted(meta: &VideoMeta) -> bool { |
| 97 | - meta.width > 1920 || meta.height > 1080 || matches!(meta.codec, Codec::Hevc | Codec::Av1) | |
| 107 | + meta.coded_width > 1920 | |
| 108 | + || meta.coded_height > 1080 | |
| 109 | + || matches!(meta.codec, Codec::Hevc | Codec::Av1) | |
| 98 | 110 | } |
| 99 | 111 | |
| 100 | 112 | /// The picture a proxy of `meta` is coded at: aspect kept, long edge at most |
| @@ -628,7 +640,27 @@ mod tests { | ||
| 628 | 640 | Arc::new(AtomicBool::new(false)) |
| 629 | 641 | } |
| 630 | 642 | |
| 631 | - fn meta(width: u32, height: u32, codec: Codec) -> VideoMeta { | |
| 643 | + /// A meta as no container wrote it: square pixels, no turn, the displayed | |
| 644 | + /// pair the same pair the samples are stored at. | |
| 645 | + fn meta(coded_width: u32, coded_height: u32, codec: Codec) -> VideoMeta { | |
| 646 | + turned_meta(coded_width, coded_height, Rotation::None, codec) | |
| 647 | + } | |
| 648 | + | |
| 649 | + /// The same, but with the display pair built the way `demux` builds it for | |
| 650 | + /// a file carrying a display matrix: the stored pair with its axes swapped | |
| 651 | + /// where the turn says they are. A phone clip shot 1920x1080 and turned to | |
| 652 | + /// portrait is the case that matters -- it *displays* 1080x1920, and a | |
| 653 | + /// predicate that reads the displayed pair calls it a tall 1080p film. | |
| 654 | + fn turned_meta( | |
| 655 | + coded_width: u32, | |
| 656 | + coded_height: u32, | |
| 657 | + rotation: Rotation, | |
| 658 | + codec: Codec, | |
| 659 | + ) -> VideoMeta { | |
| 660 | + let (width, height) = match rotation.swaps_axes() { | |
| 661 | + true => (coded_height, coded_width), | |
| 662 | + false => (coded_width, coded_height), | |
| 663 | + }; | |
| 632 | 664 | VideoMeta { |
| 633 | 665 | width, |
| 634 | 666 | height, |
| @@ -636,11 +668,9 @@ mod tests { | ||
| 636 | 668 | frame_count: 240, |
| 637 | 669 | codec, |
| 638 | 670 | color: ColorDescription::default(), |
| 639 | - rotation: Rotation::None, | |
| 640 | - // Square pixels, coded where they are declared: a meta no | |
| 641 | - // container wrote, so nothing was read to disagree with it. | |
| 642 | - coded_width: width, | |
| 643 | - coded_height: height, | |
| 671 | + rotation, | |
| 672 | + coded_width, | |
| 673 | + coded_height, | |
| 644 | 674 | pixel_aspect: crate::demux::PixelAspect::SQUARE, |
| 645 | 675 | } |
| 646 | 676 | } |
| @@ -657,6 +687,39 @@ mod tests { | ||
| 657 | 687 | "1080p H.264 plays natively" |
| 658 | 688 | ); |
| 659 | 689 | assert!(!wanted(&meta(1280, 720, Codec::H264)), "720p H.264"); |
| 690 | + | |
| 691 | + // A turn must not turn a native file into a proxy job. What a decoder | |
| 692 | + // is handed is the stored raster -- 1920x1080 of H.264 -- and that is | |
| 693 | + // what plays at speed; the 1080x1920 the file *displays* is a metadata | |
| 694 | + // turn, not a bigger picture. Judged on the displayed pair this file | |
| 695 | + // was handed to a background decoder and an encoder to be stood in for, | |
| 696 | + // which is a whole film of CPU and cache for a clip already at rate. | |
| 697 | + let phone = turned_meta(1920, 1080, Rotation::Cw90, Codec::H264); | |
| 698 | + assert_eq!( | |
| 699 | + (phone.coded_width, phone.coded_height), | |
| 700 | + (1920, 1080), | |
| 701 | + "the samples are stored landscape" | |
| 702 | + ); | |
| 703 | + assert_eq!( | |
| 704 | + (phone.width, phone.height), | |
| 705 | + (1080, 1920), | |
| 706 | + "and the file only claims to display portrait" | |
| 707 | + ); | |
| 708 | + assert!( | |
| 709 | + !wanted(&phone), | |
| 710 | + "a rotated 1080p H.264 clip plays natively: the turn is not height" | |
| 711 | + ); | |
| 712 | + // ...while the same turn on a codec this machine decodes slowly is | |
| 713 | + // still wanted, and so is a genuinely tall stored raster: the two | |
| 714 | + // tests are about the stored pair, not about `rotation` itself. | |
| 715 | + assert!( | |
| 716 | + wanted(&turned_meta(1920, 1080, Rotation::Cw90, Codec::Hevc)), | |
| 717 | + "1080p HEVC is wanted whatever turn it carries" | |
| 718 | + ); | |
| 719 | + assert!( | |
| 720 | + wanted(&turned_meta(1080, 1920, Rotation::None, Codec::H264)), | |
| 721 | + "a stored 1080x1920 raster is a big one, turn or not" | |
| 722 | + ); | |
| 660 | 723 | } |
| 661 | 724 | |
| 662 | 725 | /// Aspect kept, long edge capped, both axes even -- and a small source left |