From 85c8556eef9ccdb6b172f64a0016bc16f8a092fb Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 2 Mar 2017 11:33:05 +0100 Subject: [PATCH] hw_videotoolbox: allow using native decoder output format Depends on FFmpeg commit ade7c1a2326e2bb9b. It has yet to show whether it actually does what it should. Probably doesn't. --- DOCS/man/options.rst | 2 ++ options/options.c | 2 +- video/decode/hw_videotoolbox.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 3c2a404189..83ef901eed 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -779,6 +779,8 @@ Video the given hardware. ``nv12``, the default, works better on modern hardware, while ``uyvy422`` appears to be better for old hardware. ``yuv420p`` also works. + Since mpv 0.25.0, ``no`` is an accepted value, which lets the decoder pick + the format on newer FFmpeg versions (will use ``nv12`` on older versions). ``--panscan=<0.0-1.0>`` Enables pan-and-scan functionality (cropping the sides of e.g. a 16:9 diff --git a/options/options.c b/options/options.c index 7723ddec50..012707cb2c 100644 --- a/options/options.c +++ b/options/options.c @@ -448,7 +448,7 @@ const m_option_t mp_opts[] = { OPT_CHOICE_C("hwdec", hwdec_api, 0, mp_hwdec_names), OPT_STRING("hwdec-codecs", hwdec_codecs, 0), #if HAVE_VIDEOTOOLBOX_HWACCEL - OPT_IMAGEFORMAT("videotoolbox-format", videotoolbox_format, 0), + OPT_IMAGEFORMAT("videotoolbox-format", videotoolbox_format, 0, .min = -1), #endif // -1 means auto aspect (prefer container size until aspect change) diff --git a/video/decode/hw_videotoolbox.c b/video/decode/hw_videotoolbox.c index 8d8c165a84..b343b1de0e 100644 --- a/video/decode/hw_videotoolbox.c +++ b/video/decode/hw_videotoolbox.c @@ -105,8 +105,14 @@ static int init_decoder(struct lavc_ctx *ctx, int w, int h) if (!vtctx) return -1; - vtctx->cv_pix_fmt_type = - mp_imgfmt_to_cvpixelformat(ctx->opts->videotoolbox_format); + int imgfmt = ctx->opts->videotoolbox_format; +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 81, 103) + if (!imgfmt) + imgfmt = IMGFMT_NV12; +#endif + vtctx->cv_pix_fmt_type = mp_imgfmt_to_cvpixelformat(imgfmt); + MP_VERBOSE(ctx, "Requesting cv_pix_fmt_type=0x%x\n", + (unsigned)vtctx->cv_pix_fmt_type); int err = av_videotoolbox_default_init2(ctx->avctx, vtctx); if (err < 0) {