Set seq_params.film_grain_params_present when noise modeling
Allow frame grain_params_present to vary per-frame based on results of
the modeling.
This fixes an issue where no grain is found on first frame, causing
sequence parameters to have film_grain_params_present=0 despite the
second frame having film_grain_params_present=1.
Change-Id: I00f937a30f0f8e6c1665048be89e539de6e86fbb
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index dc07880..8108109 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -1163,13 +1163,13 @@
cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
if (cpi->film_grain_table) {
- cm->seq_params.film_grain_params_present = aom_film_grain_table_lookup(
+ cm->cur_frame->film_grain_params_present = aom_film_grain_table_lookup(
cpi->film_grain_table, *time_stamp, *time_end, 0 /* =erase */,
&cm->film_grain_params);
+ } else {
+ cm->cur_frame->film_grain_params_present =
+ cm->seq_params.film_grain_params_present;
}
- cm->cur_frame->film_grain_params_present =
- cm->seq_params.film_grain_params_present;
-
// only one operating point supported now
const int64_t pts64 = ticks_to_timebase_units(timebase, *time_stamp);
if (pts64 < 0 || pts64 > UINT32_MAX) return AOM_CODEC_ERROR;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 5a7ab46..03464cd 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -506,13 +506,19 @@
}
}
} else if (oxcf->film_grain_table_filename) {
+ cm->seq_params.film_grain_params_present = 1;
+
cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table));
memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t));
aom_film_grain_table_read(cpi->film_grain_table,
oxcf->film_grain_table_filename, &cm->error);
} else {
+#if CONFIG_DENOISE
+ cm->seq_params.film_grain_params_present = (cpi->oxcf.noise_level > 0);
+#else
cm->seq_params.film_grain_params_present = 0;
+#endif
memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params));
}
}