- ist = input_streams[ost->source_index];
-
- /* check if the encoder supports CUVID */
- if (!ost->enc->pix_fmts)
- goto cancel;
- for (pix_fmt = ost->enc->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++)
- if (*pix_fmt == AV_PIX_FMT_CUDA)
- break;
- if (*pix_fmt == AV_PIX_FMT_NONE)
- goto cancel;
-
- /* check if the decoder supports CUVID */
- if (ist->hwaccel_id != HWACCEL_CUVID || !ist->dec || !ist->dec->pix_fmts)
- goto cancel;
- for (pix_fmt = ist->dec->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++)
- if (*pix_fmt == AV_PIX_FMT_CUDA)
- break;
- if (*pix_fmt == AV_PIX_FMT_NONE)
- goto cancel;
-
- av_log(NULL, AV_LOG_VERBOSE, "Setting up CUVID transcoding\n");
-
- if (ist->hwaccel_ctx) {
- ctx = ist->hwaccel_ctx;
- } else {
- ctx = av_mallocz(sizeof(*ctx));
- if (!ctx) {
- ret = AVERROR(ENOMEM);
- goto error;
+ if (!hw_device_ctx) {
+ ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_CUDA,
+ ist->hwaccel_device, NULL, 0);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA device\n");
+ return ret;