edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! The duration `probe_media` reports for every audio and video file in `assets/`, |
| 2 | //! checked against ffprobe, and the language a probe states for an mp4/mov track. |
| 3 | //! |
| 4 | //! The oracle is `ffprobe`'s `format=duration`, with rules that follow what |
| 5 | //! ffprobe itself measures, or what a player plays: |
| 6 | //! |
| 7 | //! - An Ogg Opus stream's playable length is RFC 7845 section 4's: the last |
| 8 | //! granule position minus the `OpusHead` pre-skip, over 48 kHz. ffprobe does |
| 9 | //! not take the pre-skip off, so the oracle subtracts it from ffprobe's figure |
| 10 | //! (`test_tone.opus`: 3.0065 - 312/48000 = 3.000 s, the tone's length). |
| 11 | //! - A raw ADTS stream (`format_name=aac`) states no length. ffprobe's format |
| 12 | //! duration there is file size over an estimated bit rate, which is a guess |
| 13 | //! (3.126 s on `test_tone.aac`). Its own packet timeline is the measured length: |
| 14 | //! the last packet's start plus its duration, which is 131 frames of 1024 samples |
| 15 | //! (3.0418 s). The test compares against that for ADTS. |
| 16 | //! - A Matroska or WebM file with a picture is reported by the engine as its |
| 17 | //! picture length, the frame count over the frame rate (the timeline's contract, |
| 18 | //! see `MediaFacts::duration_secs`). ffprobe reports the Segment `Info` duration, |
| 19 | //! which runs past the last frame by part of a frame. The tolerance for those |
| 20 | //! files is one frame on top of the 2 ms. |
| 21 | //! |
| 22 | //! A file the engine refuses (no duration) is skipped, and so is anything ffprobe |
| 23 | //! finds no audio or video in (subtitles alone, a still). When ffprobe is not on |
| 24 | //! the path the whole test is skipped. |
| 25 | //! |
| 26 | //! ```text |
| 27 | //! cargo test --release -p engine --test probe_duration -- --nocapture |
| 28 | //! ``` |
| 29 | |
| 30 | use ; |
| 31 | use Command; |
| 32 | |
| 33 | use ; |
| 34 | |
| 35 | /// The allowed disagreement between the engine and ffprobe, in seconds. |
| 36 | const TOLERANCE: f64 = 0.002; |
| 37 | |
| 38 | /// Files that disagree for a reason outside the rules above, with the reason. |
| 39 | const ALLOWLIST: & = & |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | ; |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | /// The `OpusHead` pre-skip of an Ogg Opus file (RFC 7845 section 5.1: little-endian |
| 58 | /// u16 at byte 10 of the packet), `None` for a file that is not Ogg Opus. |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | /// `ffprobe` with the given `-show_entries` and `-of csv=p=0`, one line per row. |
| 73 | /// The csv writer ends a row with a comma and quotes a value that holds one |
| 74 | /// (`"matroska,webm"`); both are taken off. |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | /// ffprobe's `format=duration`, `None` where it states none (`N/A`). |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | /// End of the last packet on the first stream, in seconds: the measured length |
| 93 | /// of a stream with no stated duration. |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | /// Whether ffprobe finds an audio or video stream in the file. |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 |