0

I'm writing app to use on PCs with more than one GPU, I'm trying to get a list of GPU indexes that can decode stream in h264 to assign all new video source equally between all available GPU.

I've fount how to do it in command prompt but i need to write line belong it in c++

ffmpeg -vsync 0 -i input.mp4 -c:v h264_nvenc -gpu list -f null –

I need it to dynamically pass it to av_hwdevice_ctx_create(AVBufferRef**,char *int)

Does anyone know how to do this?

siuks24
  • 9
  • 3

1 Answers1

0

As far as I know you don't need to pass the device explicitly to

av_hwdevice_ctx_create  (   
        AVBufferRef **  device_ctx,
        enum AVHWDeviceType     type,
        const char *    device,
        AVDictionary *  opts,
        int     flags 
)   

the device_ctx can be NULL, because it gets created here. You only need to know the type you desire. e.g. AV_HWDEVICE_TYPE_CUDA . The remaining parameters can be NULL or 0. At least that's how it's done in the hw_decode example:

static AVBufferRef *hw_device_ctx = NULL;
//...
static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type)
{
    int err = 0;
    if ((err = av_hwdevice_ctx_create(&hw_device_ctx, type,
                                  NULL, NULL, 0)) < 0) {
        fprintf(stderr, "Failed to create specified HW device.\n");
        return err;
    }
    ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
    return err;
}

(Note: I haven't used the function myself. I'm just basing my answer on the how it's done in the example.)

Ramtin Nouri
  • 310
  • 1
  • 8
  • Hi, thanks for the answer. The point is that I'm writing app to use on PC with more than one GPU and I want to use all of them(one of them for every new stream to decode). The proposition you wrote above cause that decoding will be started on the first GPU every time. In ffmpeg examples I've found that I can do it by set proper GPU by calling av_hwdevice_ctx_create() with proper arguments. That's why I need to know list of GPUs that support Hardware decoding. – siuks24 Jun 07 '20 at 20:31
  • Oh ok I see. Unfortunately the documentation doesn't give any information about the device parameter. My first guess would be using "0" and "1" and so on. But I'm sorry I can't really help you. Maybe [this](https://ffmpeg.org/doxygen/trunk/hwdevice_8c_source.html#l00146) can be helpful. – Ramtin Nouri Jun 08 '20 at 09:12