zmwangx / rust-ffmpeg

Safe FFmpeg wrapper.
Do What The F*ck You Want To Public License
1.3k stars 203 forks source link

Unable To Get Multithreading To Work #188

Open TheDarkula opened 4 months ago

TheDarkula commented 4 months ago

I am working on decoding a video into individual frames, and I have most everything working properly, but ffmpeg-next is only running on a single thread.

Here is the relevant part of the code:

ffmpeg::init().unwrap();

let input_path = Path::new("/path/to/video.mp4");
let mut input_context = ffmpeg::format::input(&input_path).expect("Cannot open file.");

let input_video = input_context
    .streams()
    .best(Type::Video)
    .expect("No video stream found");

let mut video_context_decoder = ffmpeg::codec::context::Context::from_parameters(input_video.parameters())
.expect("Failed to create decoder context");

let mut video_threading_config = video_context_decoder.threading();
video_threading_config.count = 32;
video_threading_config.kind = ffmpeg::codec::threading::Type::Frame;

video_context_decoder.set_threading(video_threading_config);

debug!("Threading: {:?}", video_context_decoder.threading());

let mut video_decoder = video_context_decoder.decoder().video().expect("Failed to create video decoder");

Here is the output of the debug line:

Config { kind: None, count: 32 }

The kind being set to Frame is never set, and even though I have the thread count set to 32, it always runs single-threaded.

I have also tried setting it on the video_decoder variable, but that does not change anything.

Am I missing something here?