rust-shell-script / rust_cmd_lib

Common rust command-line macros and utilities, to write shell-script like tasks in a clean, natural and rusty way
https://docs.rs/cmd_lib/
Apache License 2.0
1.05k stars 37 forks source link

Command never ends when being executed in cmd_lib::spawn_with_output #35

Closed 0x7FFFFFFFFFFFFFFF closed 3 years ago

0x7FFFFFFFFFFFFFFF commented 3 years ago

I have a ffmpeg command to process a video file.

ffmpeg -i 4.mp4 -i a2.png -ss 00:00:00 -to 00:01:00 -y -filter_complex "overlay=x=263:y=752" -c:a copy -max_muxing_queue_size 9999 -nostdin testtttt.mp4

It runs very well when being executed in a terminal. But when I run it with cmd_lib::spawn_with_output, it never ends and the program just stuck there. This is my program.

fn main() -> eyre::Result<()>{
    std::env::set_current_dir(r##"f:\temp"##);

    println!("{:?}", "Starting......");
    let output = cmd_lib::spawn_with_output!(
ffmpeg -i 4.mp4 -i a2.png -ss 00:00:00 -to 00:01:00 -y -filter_complex "overlay=x=263:y=752"  -c:a copy -max_muxing_queue_size 9999 -nostdin testtttt.mp4
    )?.wait_fun_result()?;
    println!("{:?}", "Done!");
    println!("{:?}", output);
    println!("{:?}", output.trim());
    Ok(())
}

Is there something I'm doing wrong? Thanks.

rust-shell-script commented 3 years ago

Seems like the same issue as this one: https://stackoverflow.com/questions/34611742/how-do-i-read-the-output-of-a-child-process-without-blocking-in-rust. If the final output is larger than default kernel pipe size, it will block.

0x7FFFFFFFFFFFFFFF commented 3 years ago

Thanks for the link. I've read it but still now sure how to handle the issue. Do you have any suggestions?

Btw, I just tried the stdlib Command and it completes without any issue. I use the following command.

let output = Command::new(r##"ffmpeg"##)
        .arg(r##"-i"##)
        .arg(r##"input.mp4"##)
        .arg(r##"-i"##)
        .arg(r##"a2.png"##)
        .arg(r##"-ss"##)
        .arg(r##"00:00:00"##)
        .arg(r##"-to"##)
        .arg(r##"00:01:00"##)
        .arg(r##"-y"##)
        .arg(r##"-filter_complex"##)
        .arg(r##"overlay=x=263:y=752"##)
        .arg(r##"-c:a"##)
        .arg(r##"copy"##)
        .arg(r##"-max_muxing_queue_size"##)
        .arg(r##"9999"##)
        .arg(r##"-nostdin"##)
        .arg(r##"testtttt.mp4"##)
        .output()?;

Since cmd_lib is a wrapper around stdlib Command, it is possible there is something wrong with cmd_lib's logic?

tao-guo commented 3 years ago

Yes, the fix should be in cmd_lib. After adding logging support, the generated code will a little different than your above code. I just made some changes, you can check if it fixes your problem. thanks.

0x7FFFFFFFFFFFFFFF commented 3 years ago

Yes, the fix should be in cmd_lib. After adding logging support, the generated code will a little different than your above code. I just made some changes, you can check if it fixes your problem. thanks.

Thanks, it works now. Sorry for the late response. I can't find the issues tab the other day.