Skip to content

How to set thread_count? #152

Description

@CodingOctocat

Can I make this kind of setting?

_pCodecContext->thread_count = threadCount <= 0 ? Environment.ProcessorCount : threadCount;
_pCodecContext->thread_type = ffmpeg.FF_THREAD_SLICE;

I noticed DecoderThreads, but this is ineffective because multithreading requires setting thread_type. Perhaps I could configure it in DecoderOptions, but this isn't intuitive. Additionally, I've tried the following code to detect supported thread_type, but it's unreliable. FF_THREAD_FRAME causes avcodec_open2 to crash without a catchable error, so I always use FF_THREAD_SLICE.

bool supportsFrameThreading = (codec->capabilities & ffmpeg.AV_CODEC_CAP_FRAME_THREADS) != 0;
bool supportsSliceThreading = (codec->capabilities & ffmpeg.AV_CODEC_CAP_SLICE_THREADS) != 0;
using var file = MediaFile.Open(@"D:\example\movie.mp4", new MediaOptions() {
    VideoPixelFormat = ImagePixelFormat.Rgba32,
    DecoderThreads = 16,
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions