mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-06 09:22:36 +08:00
qsvdec: add support for HW_DEVICE_CTX method
This allows user set hw_device_ctx instead of hw_frames_ctx for QSV decoders, hence we may remove the ad-hoc libmfx setup code from FFmpeg. "-hwaccel_output_format format" is applied to QSV decoders after removing the ad-hoc libmfx code. In order to keep compatibility with old commandlines, the default format is set to AV_PIX_FMT_QSV, but this behavior will be removed in the future. Please set "-hwaccel_output_format qsv" explicitly if AV_PIX_FMT_QSV is expected. The normal device stuff works for QSV decoders now, user may use "-init_hw_device args" to initialise device and "-hwaccel_device devicename" to select a device for QSV decoders. "-qsv_device device" which was added for workarounding device selection in the ad-hoc libmfx code still works For example: $> ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=/dev/dri/card0 -hwaccel qsv -c:v h264_qsv -i input.h264 -f null - /dev/dri/renderD128 is actually open for h264_qsv decoder in the above command without this patch. After applying this patch, /dev/dri/card0 is used. $> ffmpeg -init_hw_device vaapi=va:/dev/dri/card0 -init_hw_device qsv=hw@va -hwaccel_device hw -hwaccel qsv -c:v h264_qsv -i input.h264 -f null - device hw of type qsv is not usable in the above command without this patch. After applying this patch, this command works as expected. Reviewed-by: Soft Works <softworkz@hotmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:

committed by
James Almer

parent
35b1f46d79
commit
ecee3b07cd
@@ -137,9 +137,6 @@ static const char *const opt_name_enc_time_bases[] = {"enc_time_base"
|
||||
const HWAccel hwaccels[] = {
|
||||
#if CONFIG_VIDEOTOOLBOX
|
||||
{ "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX },
|
||||
#endif
|
||||
#if CONFIG_LIBMFX
|
||||
{ "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV },
|
||||
#endif
|
||||
{ 0 },
|
||||
};
|
||||
@@ -571,6 +568,23 @@ static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_QSV
|
||||
static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
|
||||
{
|
||||
const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
|
||||
int err;
|
||||
char *tmp = av_asprintf("%s%s", prefix, arg);
|
||||
|
||||
if (!tmp)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
err = hw_device_init_from_string(tmp, NULL);
|
||||
av_free(tmp);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
|
||||
{
|
||||
if (!strcmp(arg, "list")) {
|
||||
@@ -898,6 +912,12 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
|
||||
"with old commandlines. This behaviour is DEPRECATED and will be removed "
|
||||
"in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
|
||||
ist->hwaccel_output_format = AV_PIX_FMT_CUDA;
|
||||
} else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
|
||||
av_log(NULL, AV_LOG_WARNING,
|
||||
"WARNING: defaulting hwaccel_output_format to qsv for compatibility "
|
||||
"with old commandlines. This behaviour is DEPRECATED and will be removed "
|
||||
"in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
|
||||
ist->hwaccel_output_format = AV_PIX_FMT_QSV;
|
||||
} else if (hwaccel_output_format) {
|
||||
ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
|
||||
if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
|
||||
@@ -3848,7 +3868,7 @@ const OptionDef options[] = {
|
||||
#endif
|
||||
|
||||
#if CONFIG_QSV
|
||||
{ "qsv_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_device },
|
||||
{ "qsv_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_qsv_device },
|
||||
"set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user