Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable To Get Multithreading To Work #188

Open
TheDarkula opened this issue Jun 2, 2024 · 1 comment
Open

Unable To Get Multithreading To Work #188

TheDarkula opened this issue Jun 2, 2024 · 1 comment

Comments

@TheDarkula
Copy link

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?

@gcanat
Copy link

gcanat commented Oct 15, 2024

I set it like this on my side and it works:

use ffmpeg::codec::threading;

// ... more code in between ...

let mut context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
context_decoder.set_threading(threading::Config {
    kind: threading::Type::Frame,
    count: threads,
    // below might be needed for ffmpeg < 6.0
    // safe: true
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants