termproof 0.3.4

Evidence-first verification for TUI and terminal applications: recipe model, schema, steps, assertions, orchestration, terminal sessions and the evidence pipeline
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
//! Video from a cast, rendered by the same code as the screenshots.
//!
//! [`AggFfmpegBackend`](crate::evidence::video::AggFfmpegBackend) shells out to `agg`,
//! which has its own fonts and its own colour handling. That works, but it
//! means a still and a frame of the same screen come from two unrelated
//! renderers and do not look alike.
//!
//! This backend replays the cast through the terminal emulator, samples the
//! grid at a fixed frame rate, and renders each frame with
//! [`screen_svg`](crate::terminal::attributed::screen_svg) — the same
//! function behind [`crate::evidence::screenshot`]. The video is literally the
//! screenshots in sequence. That holds for this backend only: `agg_ffmpeg` is
//! still the configured default, so choosing it is what buys the shared visual
//! language.
//!
//! It also drops a binary dependency: `rsvg-convert` and `ffmpeg`, no `agg`.
//!
//! # Why this one still uses `avt`
//!
//! The rest of the crate emulates with `vt100`. Cast *playback* — replaying
//! timed output events and sampling the grid between them — is what `avt`
//! exists for, and reimplementing it on `vt100` would be rebuilding a player to
//! avoid a dependency the format's own tooling uses. Stated here rather than
//! left for a reviewer to notice.

use std::fs;
use std::path::Path;
use std::process::Command;
use std::time::Duration;

use avt::Vt;

use crate::terminal::attributed::palette_color;
use crate::terminal::attributed::rgb_color;
use crate::terminal::attributed::screen_svg;
use crate::terminal::attributed::AttributedCell;
use crate::terminal::attributed::AttributedScreen;
use crate::terminal::attributed::SvgMetrics;
use crate::terminal::attributed::DEFAULT_CELL_H;
use crate::terminal::attributed::DEFAULT_CELL_W;
use crate::terminal::attributed::DEFAULT_COLUMNS;
use crate::terminal::attributed::DEFAULT_FONT_PX;
use crate::terminal::attributed::DEFAULT_PADDING;
use crate::terminal::attributed::DEFAULT_ROWS;
use crate::terminal::proc::combined_output;
use crate::terminal::proc::run_with_timeout;

const RSVG_CONVERT: &str = "/usr/bin/rsvg-convert";
const FFMPEG: &str = "/usr/local/bin/ffmpeg";
const RSVG_TIMEOUT: Duration = Duration::from_secs(30);
const FFMPEG_TIMEOUT: Duration = Duration::from_secs(120);

/// `(executable, args, timeout)` -> `Ok(())` or an error message.
pub type ToolRunner = Box<dyn Fn(&str, &[String], Duration) -> Result<(), String> + Send + Sync>;

/// Default runner: invoke the tool, error on non-zero exit.
pub fn default_runner() -> ToolRunner {
    Box::new(|executable, args, timeout| {
        let mut cmd = Command::new(executable);
        cmd.args(args);
        let output = run_with_timeout(cmd, timeout).map_err(|e| e.to_string())?;
        if !output.status.success() {
            return Err(format!(
                "{} exited {}: {}",
                executable,
                output.status.code().unwrap_or(-1),
                combined_output(&output),
            ));
        }
        Ok(())
    })
}

/// Renders an asciinema v2 cast file to an MP4.
pub struct CastVideoConverter {
    /// 2 fps sampled a 30s session 59 times and missed every transient state;
    /// the reference recording that reads well is 24.
    pub fps: u32,
    /// Longest gap, in seconds, that a pause in the cast is played back at
    /// before it is truncated. Keeps a session that sat idle for a minute from
    /// producing a minute of unchanging video.
    pub idle_time_limit: f64,
    /// Grid width, in cells.
    pub columns: usize,
    /// Grid height, in cells.
    pub rows: usize,
    /// Cell width, in SVG units.
    pub cell_w: f64,
    /// Cell height, in SVG units.
    pub cell_h: f64,
    /// Font size, in SVG units.
    pub font_px: u32,
    /// Margin around the grid, in SVG units.
    pub padding: u32,
    /// Frame size; derived from the grid when `None`.
    pub width: Option<usize>,
    /// Frame height; derived from the grid when `None`. See
    /// [`width`](Self::width).
    pub height: Option<usize>,
    runner: ToolRunner,
}

impl Default for CastVideoConverter {
    fn default() -> Self {
        CastVideoConverter {
            fps: 24,
            idle_time_limit: 1.0,
            columns: DEFAULT_COLUMNS,
            rows: DEFAULT_ROWS,
            cell_w: DEFAULT_CELL_W,
            cell_h: DEFAULT_CELL_H,
            font_px: DEFAULT_FONT_PX,
            padding: DEFAULT_PADDING,
            width: None,
            height: None,
            runner: default_runner(),
        }
    }
}

impl CastVideoConverter {
    /// A converter with the default frame rate, grid and encoding tool.
    pub fn new() -> Self {
        Self::default()
    }

    /// A default converter that shells out through `runner` instead of the
    /// real encoder. This is the seam the tests use.
    pub fn with_runner(runner: ToolRunner) -> Self {
        CastVideoConverter {
            runner,
            ..Self::default()
        }
    }

    /// Canvas geometry for each frame, honouring [`width`](Self::width) and
    /// [`height`](Self::height) if they are set.
    pub fn metrics(&self) -> SvgMetrics {
        let mut metrics = SvgMetrics {
            columns: self.columns,
            rows: self.rows,
            cell_w: self.cell_w,
            cell_h: self.cell_h,
            font_px: self.font_px,
            padding: self.padding,
            width: 0,
            height: 0,
        };
        metrics.width = self.width.unwrap_or_else(|| metrics.derived_width());
        metrics.height = self.height.unwrap_or_else(|| metrics.derived_height());
        metrics
    }

    /// Frame width, in pixels.
    pub fn frame_width(&self) -> usize {
        self.metrics().width
    }

    /// Frame height, in pixels.
    pub fn frame_height(&self) -> usize {
        self.metrics().height
    }

    /// The default output path for `cast_path`: the same path with an `.mp4`
    /// extension.
    pub fn output_path_for(&self, cast_path: &str) -> String {
        let p = Path::new(cast_path);
        p.with_extension("mp4").to_string_lossy().to_string()
    }

    /// Convert `cast_path` to MP4 and return the video path.
    pub fn convert(&self, cast_path: &str, video_path: Option<&str>) -> Result<String, String> {
        let output_path = video_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| self.output_path_for(cast_path));
        if let Some(parent) = Path::new(&output_path).parent() {
            if !parent.as_os_str().is_empty() {
                fs::create_dir_all(parent).map_err(|e| e.to_string())?;
            }
        }

        let frames = self.frames_from_cast(cast_path)?;
        let tmpdir = tempfile::Builder::new()
            .prefix("termproof_cast_frames_")
            .tempdir()
            .map_err(|e| e.to_string())?;

        let metrics = self.metrics();
        for (index, frame) in frames.iter().enumerate() {
            let svg_path = tmpdir.path().join(format!("frame-{:05}.svg", index));
            let png_path = tmpdir.path().join(format!("frame-{:05}.png", index));
            fs::write(&svg_path, screen_svg(frame, &metrics)).map_err(|e| e.to_string())?;
            (self.runner)(
                RSVG_CONVERT,
                &[
                    "--output".to_string(),
                    png_path.to_string_lossy().to_string(),
                    svg_path.to_string_lossy().to_string(),
                ],
                RSVG_TIMEOUT,
            )?;
        }

        let frame_glob = tmpdir.path().join("frame-%05d.png");
        (self.runner)(
            FFMPEG,
            &[
                "-y".to_string(),
                "-framerate".to_string(),
                self.fps.to_string(),
                "-i".to_string(),
                frame_glob.to_string_lossy().to_string(),
                "-c:v".to_string(),
                "libx264".to_string(),
                // yuv444p, not yuv420p: 4:2:0 subsamples chroma 2x2, which
                // smears the edges of coloured text. Terminal frames are almost
                // all text, so the extra bitrate is worth it.
                "-pix_fmt".to_string(),
                "yuv444p".to_string(),
                "-crf".to_string(),
                "15".to_string(),
                "-preset".to_string(),
                "slower".to_string(),
                "-tune".to_string(),
                "stillimage".to_string(),
                "-movflags".to_string(),
                "+faststart".to_string(),
                output_path.clone(),
            ],
            FFMPEG_TIMEOUT,
        )?;
        Ok(output_path)
    }

    fn frames_from_cast(&self, cast_path: &str) -> Result<Vec<AttributedScreen>, String> {
        let contents = fs::read_to_string(cast_path).map_err(|e| e.to_string())?;
        let mut lines = contents.lines();
        let header_line = lines.next().ok_or("empty cast file")?;
        let header: serde_json::Value =
            serde_json::from_str(header_line).map_err(|e| e.to_string())?;
        let width = header
            .get("width")
            .and_then(|v| v.as_u64())
            .map(|v| v as usize)
            .unwrap_or(self.columns);
        let height = header
            .get("height")
            .and_then(|v| v.as_u64())
            .map(|v| v as usize)
            .unwrap_or(self.rows);
        let mut vt = Vt::new(width.max(1), height.max(1));

        let mut frames: Vec<AttributedScreen> = Vec::new();
        let mut next_frame_at = 0.0_f64;
        let mut playback_time = 0.0_f64;
        let mut previous_cast_time = 0.0_f64;
        let frame_interval = 1.0 / self.fps as f64;

        for line in lines {
            if line.trim().is_empty() {
                continue;
            }
            let event: serde_json::Value = serde_json::from_str(line).map_err(|e| e.to_string())?;
            let arr = match event.as_array() {
                Some(a) if a.len() >= 3 => a,
                _ => continue,
            };
            let event_type = arr[1].as_str().unwrap_or("");
            if event_type != "o" {
                continue;
            }
            let timestamp = arr[0].as_f64().unwrap_or(0.0);
            let data = arr[2].as_str().unwrap_or("");
            let elapsed = (timestamp - previous_cast_time).max(0.0);
            // Collapse a long pause to idle_time_limit so a session that sat
            // waiting on the model does not become minutes of still frames.
            playback_time += elapsed.min(self.idle_time_limit);
            previous_cast_time = timestamp;
            vt.feed_str(data);
            while next_frame_at <= playback_time {
                frames.push(attributed_screen_from_avt(&vt));
                next_frame_at += frame_interval;
            }
        }

        let final_snapshot = attributed_screen_from_avt(&vt);
        if frames.is_empty() || frames.last() != Some(&final_snapshot) {
            frames.push(final_snapshot);
        }
        Ok(frames)
    }
}

/// Build an attributed screen from an `avt` grid.
///
/// Lives here rather than in [`crate::terminal`] so that module stays
/// `vt100`-only: cast playback is the one place `avt` earns its keep, and a
/// second emulator in the terminal layer would be a cost every consumer pays.
fn attributed_screen_from_avt(vt: &Vt) -> AttributedScreen {
    let rows = vt
        .view()
        .iter()
        .map(|line| line.cells().iter().map(cell_from_avt).collect())
        .collect();
    let cursor = vt.cursor();
    AttributedScreen {
        rows,
        cursor_row: cursor.row,
        cursor_column: cursor.col,
        cursor_hidden: !cursor.visible,
    }
}

/// Convert one `avt` cell, keeping `avt`'s own width.
///
/// # The one width table we do not control
///
/// Everywhere else, in-tree width decisions are pinned to the `unicode-width`
/// major `vt100` uses, so [`crate::terminal::attributed`]'s two paths agree
/// about which column a glyph occupies. `avt` brings its own `unicode-width`
/// 0.1, and as of `avt` 0.18 — the latest release — there is no version built
/// against 0.2, so this path cannot be brought onto that table.
///
/// We take `avt`'s width rather than recomputing it. `avt` already *placed*
/// the glyph and its filler using its own table; substituting a width from a
/// different table would leave the cell disagreeing with the grid it sits in,
/// and [`crate::terminal::attributed::screen_svg`] paints the background rect
/// from that width — a cell claiming two columns where `avt` allocated one
/// spills over its neighbour. A self-consistent frame measured by an older
/// table is better evidence than an incoherent one.
///
/// The practical effect is that a cast frame and a live `vt100` screen can
/// place the same code point in different columns; `cast_frames_use_avts_width_table`
/// pins a concrete case, and fails when `avt` catches up so this can be
/// revisited rather than quietly outliving the constraint.
fn cell_from_avt(cell: &avt::Cell) -> AttributedCell {
    let pen = cell.pen();
    let width = cell.width().min(2) as u8;
    AttributedCell {
        // A width-0 cell is the filler behind a wide glyph; it carries no text
        // of its own, matching what the SGR parser produces.
        text: if width == 0 {
            String::new()
        } else {
            cell.char().to_string()
        },
        fg: avt_color(pen.foreground()),
        bg: avt_color(pen.background()),
        bold: pen.is_bold(),
        dim: pen.is_faint(),
        italic: pen.is_italic(),
        underline: pen.is_underline(),
        strikethrough: pen.is_strikethrough(),
        reverse: pen.is_inverse(),
        width,
    }
}

fn avt_color(color: Option<avt::Color>) -> String {
    match color {
        None => "default".to_string(),
        Some(avt::Color::Indexed(index)) => palette_color(index as u16),
        Some(avt::Color::RGB(rgb)) => rgb_color(rgb.r, rgb.g, rgb.b),
    }
}

#[cfg(test)]
mod tests {
    use std::sync::Arc;
    use std::sync::Mutex;

    use super::*;

    fn cast_with(events: &str) -> (tempfile::TempDir, String) {
        let dir = tempfile::tempdir().unwrap();
        let cast = dir.path().join("r.cast");
        fs::write(
            &cast,
            format!("{{\"version\":2,\"width\":10,\"height\":3}}\n{}", events),
        )
        .unwrap();
        let path = cast.to_string_lossy().to_string();
        (dir, path)
    }

    fn frames(events: &str) -> Vec<AttributedScreen> {
        let (_dir, path) = cast_with(events);
        CastVideoConverter::new().frames_from_cast(&path).unwrap()
    }

    #[test]
    fn output_path_swaps_extension() {
        let conv = CastVideoConverter::new();
        assert_eq!(conv.output_path_for("/tmp/a/b.cast"), "/tmp/a/b.mp4");
    }

    #[test]
    fn frames_from_simple_cast() {
        let f = frames("[0.0, \"o\", \"hi\"]\n[0.5, \"o\", \"!\"]\n");
        assert!(!f.is_empty());
        assert_eq!(f.last().unwrap().text_lines(true)[0], "hi!");
    }

    #[test]
    fn non_output_events_are_ignored() {
        let f = frames("[0.0, \"i\", \"typed\"]\n[0.1, \"o\", \"ok\"]\n");
        assert_eq!(f.last().unwrap().text_lines(true)[0], "ok");
    }

    #[test]
    fn frame_count_follows_the_frame_rate() {
        // One second of playback at 24 fps, capped by idle_time_limit 1.0.
        let f = frames("[0.0, \"o\", \"a\"]\n[1.0, \"o\", \"b\"]\n");
        assert_eq!(f.len(), 25);
    }

    #[test]
    fn a_long_pause_is_collapsed_to_the_idle_limit() {
        // 60s of waiting must not become 60s of still frames.
        let f = frames("[0.0, \"o\", \"a\"]\n[60.0, \"o\", \"b\"]\n");
        assert_eq!(f.len(), 25);
    }

    #[test]
    fn cast_frames_use_avts_width_table() {
        // U+1FA89 is one column under `unicode-width` 0.1 and two under 0.2.
        // The rest of the crate is pinned to 0.2 to match `vt100`; `avt` is
        // built against 0.1 and cannot be moved, so a cast frame measures this
        // code point differently from a live screen. That is a real fidelity
        // gap, documented on `cell_from_avt` — this test is what stops it
        // being a silent one.
        //
        // When this fails because `avt` has moved to 0.2, the gap is closed:
        // delete the test and the caveat rather than adjusting the expectation.
        // Written as a surrogate pair because a `.cast` line is JSON, which
        // has no `\u{...}` form for an astral code point.
        let f = frames("[0.0, \"o\", \"\\ud83e\\ude89x\"]\n");
        let row = &f.last().unwrap().rows[0];
        assert_eq!(
            row[0].width, 1,
            "avt no longer measures U+1FA89 with the unicode-width 0.1 table; \
             re-check whether avt and vt100 can now share one table"
        );
        assert_eq!(row[1].text, "x", "x should sit in the adjacent column");

        // The same bytes through the vt100-backed path put `x` one column
        // further along. Asserted so the divergence is stated, not implied.
        let mut parser = vt100::Parser::new(3, 10, 0);
        parser.process("\u{1FA89}x".as_bytes());
        let live = crate::terminal::attributed::from_vt100(parser.screen());
        assert_eq!(live.rows[0][0].width, 2);
        assert_eq!(live.rows[0][2].text, "x");
    }

    // -- Cases the hand-rolled grid got wrong -------------------------------

    #[test]
    fn alternate_screen_repaints_are_captured() {
        // Ink repaints whole frames on the alternate screen. The old grid had
        // no concept of one, so these captures came back as noise.
        let f = frames(
            "[0.0, \"o\", \"scrollback\"]\n\
             [0.1, \"o\", \"\\u001b[?1049h\\u001b[H\\u001b[2Jalt\"]\n",
        );
        assert_eq!(f.last().unwrap().text_lines(true)[0], "alt");
    }

    #[test]
    fn scroll_region_is_honored() {
        // DECSTBM: a scroll confined to rows 1-2 must leave row 3 alone.
        let f = frames(
            "[0.0, \"o\", \"a\\r\\nb\\r\\nkeep\"]\n\
             [0.1, \"o\", \"\\u001b[1;2r\\u001b[2;1H\\n\\rc\"]\n",
        );
        let text = f.last().unwrap().text_lines(true);
        assert_eq!(text[0], "b");
        assert_eq!(text[1], "c");
        assert_eq!(text[2], "keep");
    }

    #[test]
    fn colors_survive_into_the_frame() {
        // The old grid stored plain chars, so every frame rendered monochrome.
        let f = frames("[0.0, \"o\", \"\\u001b[31mred\\u001b[0m\"]\n");
        let cell = &f.last().unwrap().rows[0][0];
        assert_eq!(cell.fg, "red");
        assert_eq!(f.last().unwrap().rows[0][3].fg, "default");
    }

    #[test]
    fn indexed_and_rgb_colors_map_to_hex() {
        let f = frames("[0.0, \"o\", \"\\u001b[38;5;196ma\\u001b[38;2;1;2;3mb\"]\n");
        let row = &f.last().unwrap().rows[0];
        assert_eq!(row[0].fg, "ff0000");
        assert_eq!(row[1].fg, "010203");
    }

    #[test]
    fn text_attributes_survive_into_the_frame() {
        let f = frames("[0.0, \"o\", \"\\u001b[1;3;4;9;7ma\"]\n");
        let cell = &f.last().unwrap().rows[0][0];
        assert!(cell.bold && cell.italic && cell.underline);
        assert!(cell.strikethrough && cell.reverse);
    }

    #[test]
    fn wide_glyph_keeps_its_filler_column() {
        let f = frames("[0.0, \"o\", \"\\u4f60x\"]\n");
        let row = &f.last().unwrap().rows[0];
        assert_eq!(row[0].width, 2);
        assert_eq!(row[1].width, 0);
        assert_eq!(row[2].text, "x");
    }

    #[test]
    fn frames_are_rendered_and_stitched() {
        let calls = Arc::new(Mutex::new(Vec::new()));
        let sink = calls.clone();
        let conv = CastVideoConverter::with_runner(Box::new(move |exe, args, _| {
            sink.lock()
                .expect("poisoned")
                .push((exe.to_string(), args.to_vec()));
            Ok(())
        }));
        let (dir, path) = cast_with("[0.0, \"o\", \"hi\"]\n");
        let out = dir.path().join("out.mp4").to_string_lossy().to_string();
        assert_eq!(conv.convert(&path, Some(&out)).unwrap(), out);

        let calls = calls.lock().unwrap();
        let (ffmpeg_exe, ffmpeg_args) = calls.last().unwrap();
        assert_eq!(ffmpeg_exe, FFMPEG);
        assert!(ffmpeg_args.contains(&"yuv444p".to_string()));
        assert!(ffmpeg_args.contains(&"stillimage".to_string()));
        assert!(ffmpeg_args.contains(&"24".to_string()));
        // Every earlier call rasterizes one frame.
        assert!(calls[..calls.len() - 1]
            .iter()
            .all(|(e, _)| e == RSVG_CONVERT));
    }

    #[test]
    fn a_frame_is_the_still_the_screenshot_renderer_would_draw() {
        // The module claims the video is the screenshots in sequence. Asserting
        // only that each frame goes to `rsvg-convert` would leave that claim
        // resting on the SVG being the right one, which nothing checked.
        let seen = Arc::new(Mutex::new(Vec::new()));
        let sink = seen.clone();
        let conv = CastVideoConverter::with_runner(Box::new(move |exe, args, _| {
            if exe == RSVG_CONVERT {
                sink.lock()
                    .expect("poisoned")
                    .push(fs::read_to_string(&args[2]).expect("frame written"));
            }
            Ok(())
        }));
        let (dir, path) = cast_with("[0.0, \"o\", \"hi\"]\n");
        let out = dir.path().join("out.mp4").to_string_lossy().to_string();
        conv.convert(&path, Some(&out)).unwrap();

        let expected = screen_svg(&frames("[0.0, \"o\", \"hi\"]\n")[0], &conv.metrics());
        let seen = seen.lock().expect("poisoned");
        assert_eq!(seen.first().map(String::as_str), Some(expected.as_str()));
    }

    #[test]
    fn frame_size_is_derived_but_overridable() {
        let conv = CastVideoConverter::new();
        assert_eq!(conv.frame_width(), 120 * 10 + 20);
        assert_eq!(conv.frame_height(), (40.0 * 22.0) as usize + 20);
        let conv = CastVideoConverter {
            width: Some(640),
            height: Some(480),
            ..Default::default()
        };
        assert_eq!(conv.frame_width(), 640);
        assert_eq!(conv.frame_height(), 480);
    }
}