Packet loss with process pipes #7263
-
Hello everyone, Basically, I create an ffmpeg process that runs endlessly and is supplied with data via stdin. In a loop, I then start new ffmpeg processes that read in video files and connect their stdout to the first ffmpeg process via pipes. In older versions of the program I did not handle this via tokio, but everything ran in different threads and with std processes. This always ran wonderfully stable for weeks. Now with tokio it happens again and again that the endless ffmpeg process gets broken packets and my program terminates the process due to error limits. As I said, it's difficult to debug, so I can't say exactly at what point the errors occur. I just have a strong suspicion that it happened during the transfer from stdout of one process to stdin of the other process. This is because if I write the wrong number of packets with write_all, I get exactly the same error messages in ffmpeg. Simplified, my code looks something like this, with output_proc normally running in a different task: let output_proc = Command::new("ffmpeg")
.args(["-re", "-i", "pipe:0", ".."])
.kill_on_drop(true)
.stdin(Stdio::piped())
.spawn()?;
let output_writer = BufWriter::with_capacity(65088, output_proc.stdin.take().unwrap());
let mut buffer = [0; 65088];
for file in files.next().await {
let mut input_proc = Command::new("ffmpeg")
.args(["-i", file, ".."])
.kill_on_drop(true)
.stdout(Stdio::piped())
.spawn()?;
let mut input = BufReader::with_capacity(65088, input_proc.stdout.take().unwrap());
loop {
let num = input.read(&mut buffer).await?;
if num == 0 {
break;
}
output_writer.write_all(&buffer[..num]).await?;
}
output_writer.flush().await?;
drop(input);
input_proc.wait().await;
} Does anyone here have any ideas what I could do to fix this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The only potential problem I can see is that because It is curious that you're using 65088 as the size everywhere. There's no guarantee that the data actually gets sent in chunks of that size, and ffmpeg should not expect it either. |
Beta Was this translation helpful? Give feedback.
Ok, I have to apologize for stealing your time. The problem was not with the Rust code, but simply with the way I put my ffmpeg commands together. Under certain circumstances the order of the audio and video mapping was swapped (once
-map “0:v” -map “0:a”
and once-map “0:a” -map “0:v”
), which the receiver instance didn't like.