meh / rust-ffmpeg

Safe FFmpeg wrapper.
Do What The F*ck You Want To Public License
459 stars 97 forks source link

Example for mix audio and video? #166

Open niuhuan opened 2 years ago

niuhuan commented 2 years ago

I want the same effect as this command line, but I don't know how to make it

ffmpeg -i 1.video -i 1.audio -vcodec copy -acodec copy output.mp4
    let video_file = "1.video".to_owned();
    let audio_file = "1.audio".to_owned();
    let mix_file = "1.mp4".to_owned();
    let mut video_input = ffmpeg::format::input(&video_file).unwrap();
    let mut audio_input = ffmpeg::format::input(&audio_file).unwrap();
    let mut mix_output = ffmpeg::format::output(&mix_file).unwrap();
    video_input
        .streams()
        .best(ffmpeg::media::Type::Video)
        .map(|stream| {
            // ????
        });
    let best_audio_stream_index = audio_input
        .streams()
        .best(ffmpeg::media::Type::Audio)
        .map(|stream| stream.index());

mix_output.set_metadata()
mix_output.........