Skip to content

Commit 2cd338a

Browse files
authored
fix(encode): order ffmpeg inputs ahead of output options (#143)
* fix(encode): order ffmpeg inputs ahead of output options FFmpeg parses argv positionally: an option applies to the next `-i` that follows it. The audio input was emitted after the codec block, so `-c:v`, `-crf`, `-profile:v` and `-pix_fmt` were read as *input* options for audio.raw and ffmpeg refused to start with "Option profile:v cannot be applied to input url". Every scenario carrying an audio track — or an embedded video with a soundtrack — failed to encode, on all four codecs, through the default path. Move the audio input next to the video input and keep `-c:a`/`-b:a` with the output description. The argv assembly moves into `ffmpeg_args`, a pure function, so the ordering invariant is unit-testable without an ffmpeg binary on the machine. A broken pipe here almost always means ffmpeg already died on its own arguments, so `FfmpegWrite` now carries the tail of ffmpeg's stderr. It used to be printed only outside `--quiet`, which left the diagnosis of this very bug reading "Failed to write to FFmpeg pipe: Broken pipe". * style(encode): apply rustfmt to the ffmpeg argv builder
1 parent e442799 commit 2cd338a

2 files changed

Lines changed: 241 additions & 117 deletions

File tree

crates/rustmotion-core/src/error.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,14 @@ pub enum RustmotionError {
161161
#[error("Failed to open FFmpeg stdin pipe")]
162162
FfmpegPipe,
163163

164-
#[error("Failed to write to FFmpeg pipe: {reason}")]
165-
FfmpegWrite { reason: String },
164+
// A broken pipe here nearly always means ffmpeg already died on its own
165+
// arguments, so the useful diagnostic is ffmpeg's stderr rather than our
166+
// write error. Carry it in the error so it survives `--quiet`.
167+
#[error("Failed to write to FFmpeg pipe: {reason}{}", .stderr.as_ref().map(|s| format!("\nffmpeg reported:\n{}", s)).unwrap_or_default())]
168+
FfmpegWrite {
169+
reason: String,
170+
stderr: Option<String>,
171+
},
166172

167173
#[error("Failed to wait for FFmpeg: {reason}")]
168174
FfmpegWait { reason: String },

0 commit comments

Comments
 (0)