Skip to content
Snippets Groups Projects
Select Git revision
  • 45b9173c56aeee752d88a80de07a86a9ca8a2cf1
  • main default protected
  • overlay_vaapi
  • graph2dot
  • 240926-1
  • 240926
  • 240701-2
  • 240701-3
  • 240701-4
  • 240701-5
  • 240701-6
  • 240701-7
  • 240701-8
  • 240702
  • 240624
  • 240527
  • 240517
  • 231212
  • 231114
  • 231031
  • 231030
21 results

ffmpeg.rs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ffmpeg.rs 3.81 KiB
    use super::{cmd, filter::Filter};
    use crate::{
    	render::filter::channel,
    	time::{format_time, Time}
    };
    use anyhow::bail;
    use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf};
    use rational::Rational;
    use std::{borrow::Cow, process::Command};
    
    pub(crate) struct FfmpegInput {
    	pub(crate) concat: bool,
    	pub(crate) loop_input: bool,
    	pub(crate) fps: Option<Rational>,
    	pub(crate) start: Option<Time>,
    	pub(crate) duration: Option<Time>,
    	pub(crate) path: PathBuf
    }
    
    impl FfmpegInput {
    	pub(crate) fn new(path: PathBuf) -> Self {
    		Self {
    			concat: false,
    			loop_input: false,
    			fps: None,
    			start: None,
    			duration: None,
    			path
    		}
    	}
    
    	fn append_to_cmd(self, cmd: &mut Command) {
    		if self.concat {
    			cmd.arg("-f").arg("concat").arg("-safe").arg("0");
    		}
    		if self.loop_input {
    			cmd.arg("-loop").arg("1");
    		}
    		if let Some(fps) = self.fps {
    			cmd.arg("-r").arg(fps.to_string());
    		}
    		if let Some(start) = self.start {
    			cmd.arg("-ss").arg(format_time(start));
    		}
    		if let Some(duration) = self.duration {
    			cmd.arg("-t").arg(format_time(duration));
    		}
    		cmd.arg("-i").arg(self.path);
    	}
    }
    
    pub(crate) struct Ffmpeg {
    	inputs: Vec<FfmpegInput>,
    	filters: Vec<Filter>,
    	filters_output: Cow<'static, str>,
    	loudnorm: bool,
    	output: PathBuf,
    
    	filter_idx: usize
    }
    
    impl Ffmpeg {
    	pub fn new(output: PathBuf) -> Self {
    		Self {
    			inputs: Vec::new(),
    			filters: Vec::new(),
    			filters_output: "0".into(),
    			loudnorm: false,
    			output,