this repo has no description
at main 80 lines 2.1 kB view raw
1use std::path::PathBuf; 2 3use browser_stream::encoder::{EncoderSettings, build_ffmpeg_args}; 4 5#[test] 6fn derives_keyint_from_fps_and_seconds() { 7 let settings = EncoderSettings { 8 width: 1280, 9 height: 720, 10 fps: 30, 11 bitrate_kbps: 2500, 12 keyint_sec: 2, 13 x264_opts: "bframes=0".to_string(), 14 output: "rtmp://live.example.com/app/key".to_string(), 15 include_silent_audio: true, 16 ffmpeg_path: PathBuf::from("/tmp/ffmpeg"), 17 }; 18 19 let args = build_ffmpeg_args(&settings); 20 21 assert_pair(&args, "-g", "60"); 22 assert_pair(&args, "-keyint_min", "60"); 23} 24 25#[test] 26fn includes_cbr_like_flags() { 27 let settings = EncoderSettings { 28 width: 1920, 29 height: 1080, 30 fps: 60, 31 bitrate_kbps: 4500, 32 keyint_sec: 1, 33 x264_opts: "bframes=0".to_string(), 34 output: "rtmps://live.example.com/app/key".to_string(), 35 include_silent_audio: true, 36 ffmpeg_path: PathBuf::from("/tmp/ffmpeg"), 37 }; 38 39 let args = build_ffmpeg_args(&settings); 40 41 assert_pair(&args, "-b:v", "4500k"); 42 assert_pair(&args, "-maxrate", "4500k"); 43 assert_pair(&args, "-bufsize", "9000k"); 44} 45 46#[test] 47fn passes_x264_opts_and_output() { 48 let settings = EncoderSettings { 49 width: 1920, 50 height: 1080, 51 fps: 30, 52 bitrate_kbps: 3000, 53 keyint_sec: 1, 54 x264_opts: "bframes=0:scenecut=0".to_string(), 55 output: "rtmp://live.example.com/app/key".to_string(), 56 include_silent_audio: true, 57 ffmpeg_path: PathBuf::from("/tmp/ffmpeg"), 58 }; 59 60 let args = build_ffmpeg_args(&settings); 61 62 assert_pair(&args, "-x264-params", "bframes=0:scenecut=0"); 63 assert_eq!( 64 args.last().expect("args should not be empty"), 65 "rtmp://live.example.com/app/key" 66 ); 67} 68 69fn assert_pair(args: &[String], flag: &str, value: &str) { 70 let index = args 71 .iter() 72 .position(|item| item == flag) 73 .expect("flag should exist in arg list"); 74 75 let next = args 76 .get(index + 1) 77 .expect("flag should have a following value"); 78 79 assert_eq!(next, value); 80}