Skip to content

Commit

Permalink
Omit data streams when outputting to matroska (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic authored Dec 23, 2024
1 parent 295faf0 commit 746a0b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased (0.8.1)
* Support negative `--preset` args.
* Add `--vmaf-fps`: Frame rate override used to analyse both reference & distorted videos.
* Omit data streams when outputting to matroska (.mkv or .webm).
* mpeg2video: map `--crf` to ffmpeg `-q` and set default crf range to 2-30.

# v0.8.0
Expand Down
5 changes: 3 additions & 2 deletions src/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ pub fn encode(
let output_ext = output.extension().and_then(|e| e.to_str());

let add_faststart = output_ext == Some("mp4") && !oargs.contains("-movflags");
let add_cues_to_front =
matches!(output_ext, Some("mkv") | Some("webm")) && !oargs.contains("-cues_to_front");
let matroska = matches!(output_ext, Some("mkv") | Some("webm"));
let add_cues_to_front = matroska && !oargs.contains("-cues_to_front");

let audio_codec = audio_codec.unwrap_or(if downmix_to_stereo && has_audio {
"libopus"
Expand Down Expand Up @@ -163,6 +163,7 @@ pub fn encode(
.arg2_opt("-vf", vfilter)
.arg2("-c:s", "copy")
.arg2("-c:a", audio_codec)
.arg_if(matroska, "-dn") // "Only audio, video, and subtitles are supported for Matroska"
.arg2_if(downmix_to_stereo, "-ac", 2)
.arg2_if(set_ba_128k, "-b:a", "128k")
.arg2_if(add_faststart, "-movflags", "+faststart")
Expand Down
10 changes: 10 additions & 0 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ pub trait CommandExt {
/// Adds two arguments if `condition` otherwise noop.
fn arg2_if(&mut self, condition: bool, a: impl ArgString, b: impl ArgString) -> &mut Self;

/// Adds an argument if `condition` otherwise noop.
fn arg_if(&mut self, condition: bool, a: impl ArgString) -> &mut Self;

/// Convert to readable shell-like string.
fn to_cmd_str(&self) -> String;
}
Expand All @@ -305,6 +308,13 @@ impl CommandExt for tokio::process::Command {
}
}

fn arg_if(&mut self, condition: bool, a: impl ArgString) -> &mut Self {
match condition {
true => self.arg(a.arg_string()),
false => self,
}
}

fn to_cmd_str(&self) -> String {
let cmd = self.as_std();
cmd.get_args().map(|a| a.to_string_lossy()).fold(
Expand Down

0 comments on commit 746a0b0

Please sign in to comment.