summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/man/options.rst11
-rw-r--r--video/decode/vd_lavc.c14
-rw-r--r--video/out/vo.h2
-rw-r--r--video/out/vo_gpu_next.c6
4 files changed, 32 insertions, 1 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index 717a58ccd2..85ab159f83 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -1679,6 +1679,17 @@ Video
the number of packets that could not be decoded. Values below an unspecified
count will not have this problem, because mpv retains the packets.
+``--vd-lavc-film-grain=<auto|cpu|gpu>``
+ Enables film grain application on the GPU. If video decoding is done on
+ the CPU, doing film grain application on the GPU can speed up decoding.
+ This option can also help hardware decoding, as it can reduce the number
+ of frame copies done.
+
+ By default, it's set to ``auto``, so if the VO supports film grain
+ application, then it will be treated as ``gpu``. If the VO does not
+ support this, then it will be treated as ``cpu``, regardless of the setting.
+ Currently, only ``gpu-next`` supports film grain application.
+
``--vd-lavc-dr=<yes|no>``
Enable direct rendering (default: yes). If this is set to ``yes``, the
video will be decoded directly to GPU video memory (or staging buffers).
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 13b0c26ddc..9fb7b7cd2a 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -72,6 +72,7 @@ static int hwdec_opt_help(struct mp_log *log, const m_option_t *opt,
struct vd_lavc_params {
int fast;
+ int film_grain;
int show_all;
int skip_loop_filter;
int skip_idct;
@@ -104,6 +105,8 @@ static const struct m_opt_choice_alternatives discard_names[] = {
const struct m_sub_options vd_lavc_conf = {
.opts = (const m_option_t[]){
{"vd-lavc-fast", OPT_FLAG(fast)},
+ {"vd-lavc-film-grain", OPT_CHOICE(film_grain,
+ {"auto", -1}, {"cpu", 0}, {"gpu", 1})},
{"vd-lavc-show-all", OPT_FLAG(show_all)},
{"vd-lavc-skiploopfilter", OPT_DISCARD(skip_loop_filter)},
{"vd-lavc-skipidct", OPT_DISCARD(skip_idct)},
@@ -127,6 +130,7 @@ const struct m_sub_options vd_lavc_conf = {
},
.size = sizeof(struct vd_lavc_params),
.defaults = &(const struct vd_lavc_params){
+ .film_grain = -1 /*auto*/,
.show_all = 0,
.check_hw_profile = 1,
.software_fallback = 3,
@@ -604,6 +608,7 @@ static void init_avctx(struct mp_filter *vd)
vd_ffmpeg_ctx *ctx = vd->priv;
struct vd_lavc_params *lavc_param = ctx->opts;
struct mp_codec_params *c = ctx->codec;
+ vd_ffmpeg_ctx *p = vd->priv;
m_config_cache_update(ctx->opts_cache);
@@ -694,6 +699,15 @@ static void init_avctx(struct mp_filter *vd)
if (lavc_codec->id == AV_CODEC_ID_H264 && lavc_param->old_x264)
av_opt_set(avctx, "x264_build", "150", AV_OPT_SEARCH_CHILDREN);
+ if (ctx->opts->film_grain != 0 /*CPU*/) {
+ if (p->vo->driver->caps & VO_CAP_FILM_GRAIN) {
+ avctx->export_side_data |= AV_CODEC_EXPORT_DATA_FILM_GRAIN;
+ } else if (ctx->opts->film_grain == 1 /*GPU*/) {
+ MP_WARN(vd, "GPU film grain requested, but VO does not support "
+ "applying film grain, disabling.\n");
+ }
+ }
+
mp_set_avopts(vd->log, avctx, lavc_param->avopts);
// Do this after the above avopt handling in case it changes values
diff --git a/video/out/vo.h b/video/out/vo.h
index 63d6c7caa7..8ccfe3ccfe 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -180,6 +180,8 @@ enum {
VO_CAP_FRAMEDROP = 1 << 1,
// VO does not allow frames to be retained (vo_mediacodec_embed).
VO_CAP_NORETAIN = 1 << 2,
+ // VO supports applying film grain
+ VO_CAP_FILM_GRAIN = 1 << 3,
};
#define VO_MAX_REQ_FRAMES 10
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c
index e6f6c8f415..d54305cf6e 100644
--- a/video/out/vo_gpu_next.c
+++ b/video/out/vo_gpu_next.c
@@ -1694,7 +1694,11 @@ const struct m_opt_choice_alternatives lut_types[] = {
const struct vo_driver video_out_gpu_next = {
.description = "Video output based on libplacebo",
.name = "gpu-next",
- .caps = VO_CAP_ROTATE90,
+ .caps = VO_CAP_ROTATE90 |
+#ifdef PL_HAVE_LAV_FILM_GRAIN
+ VO_CAP_FILM_GRAIN |
+#endif
+ 0x0,
.preinit = preinit,
.query_format = query_format,
.reconfig = reconfig,