h265_transcode/
h265_transcode.rs1use std::{io::Write, path::Path, thread};
2
3use ffmpeg_sidecar::{
4 command::FfmpegCommand,
5 event::{FfmpegEvent, LogLevel},
6};
7
8fn main() {
17 let input_path = "output/h265.mp4";
19 if !Path::new(input_path).exists() {
20 create_h265_source(input_path);
21 }
22
23 let mut input = FfmpegCommand::new()
25 .input(input_path)
26 .rawvideo()
27 .spawn()
28 .unwrap();
29
30 let transformed_frames = input.iter().unwrap().filter_frames();
33
34 let mut output = FfmpegCommand::new()
44 .args([
45 "-f", "rawvideo", "-pix_fmt", "rgb24", "-s", "600x800", "-r", "30",
46 ]) .input("-")
48 .args(["-c:v", "libx265"])
49 .args(["-y", "output/h265_overlay.mp4"])
50 .spawn()
51 .unwrap();
52
53 let mut stdin = output.take_stdin().unwrap();
55 thread::spawn(move || {
56 transformed_frames.for_each(|f| {
59 stdin.write_all(&f.data).ok();
60 });
61 });
62
63 output.iter().unwrap().for_each(|e| match e {
65 FfmpegEvent::Log(LogLevel::Error, e) => println!("Error: {}", e),
66 FfmpegEvent::Progress(p) => println!("Progress: {} / 00:00:15", p.time),
67 _ => {}
68 });
69}
70
71fn create_h265_source(path_str: &str) {
73 println!("Creating H265 source video: {}", path_str);
74 FfmpegCommand::new()
75 .args("-f lavfi -i testsrc=size=600x800:rate=30:duration=15 -c:v libx265".split(' '))
76 .arg(path_str)
77 .spawn()
78 .unwrap()
79 .iter()
80 .unwrap()
81 .for_each(|e| match e {
82 FfmpegEvent::Log(LogLevel::Error, e) => println!("Error: {}", e),
83 FfmpegEvent::Progress(p) => println!("Progress: {} / 00:00:15", p.time),
84 _ => {}
85 });
86 println!("Created H265 source video: {}", path_str);
87}