2 * Dynamic Audio Normalizer
3 * Copyright (c) 2015 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * Dynamic Audio Normalizer
29 #include "libavutil/avassert.h"
30 #include "libavutil/opt.h"
32 #define FF_BUFQUEUE_SIZE 302
33 #include "libavfilter/bufferqueue.h"
40 typedef struct cqueue {
47 typedef struct DynamicAudioNormalizerContext {
50 struct FFBufQueue queue;
57 int alt_boundary_mode;
60 double max_amplification;
62 double compress_factor;
63 double *prev_amplification_factor;
64 double *dc_correction_value;
65 double *compress_threshold;
66 double *fade_factors[2];
74 cqueue **gain_history_original;
75 cqueue **gain_history_minimum;
76 cqueue **gain_history_smoothed;
79 } DynamicAudioNormalizerContext;
81 #define OFFSET(x) offsetof(DynamicAudioNormalizerContext, x)
82 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
84 static const AVOption dynaudnorm_options[] = {
85 { "f", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS },
86 { "g", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS },
87 { "p", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS },
88 { "m", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS },
89 { "r", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
90 { "n", "set channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
91 { "c", "set DC correction", OFFSET(dc_correction), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
92 { "b", "set alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
93 { "s", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS },
97 AVFILTER_DEFINE_CLASS(dynaudnorm);
99 static av_cold int init(AVFilterContext *ctx)
101 DynamicAudioNormalizerContext *s = ctx->priv;
103 if (!(s->filter_size & 1)) {
104 av_log(ctx, AV_LOG_ERROR, "filter size %d is invalid. Must be an odd value.\n", s->filter_size);
105 return AVERROR(EINVAL);
111 static int query_formats(AVFilterContext *ctx)
113 AVFilterFormats *formats;
114 AVFilterChannelLayouts *layouts;
115 static const enum AVSampleFormat sample_fmts[] = {
121 layouts = ff_all_channel_counts();
123 return AVERROR(ENOMEM);
124 ret = ff_set_common_channel_layouts(ctx, layouts);
128 formats = ff_make_format_list(sample_fmts);
130 return AVERROR(ENOMEM);
131 ret = ff_set_common_formats(ctx, formats);
135 formats = ff_all_samplerates();
137 return AVERROR(ENOMEM);
138 return ff_set_common_samplerates(ctx, formats);
141 static inline int frame_size(int sample_rate, int frame_len_msec)
143 const int frame_size = lrint((double)sample_rate * (frame_len_msec / 1000.0));
144 return frame_size + (frame_size % 2);
147 static void precalculate_fade_factors(double *fade_factors[2], int frame_len)
149 const double step_size = 1.0 / frame_len;
152 for (pos = 0; pos < frame_len; pos++) {
153 fade_factors[0][pos] = 1.0 - (step_size * (pos + 1.0));
154 fade_factors[1][pos] = 1.0 - fade_factors[0][pos];
158 static cqueue *cqueue_create(int size)
162 q = av_malloc(sizeof(cqueue));
170 q->elements = av_malloc_array(size, sizeof(double));
179 static void cqueue_free(cqueue *q)
182 av_free(q->elements);
186 static int cqueue_size(cqueue *q)
188 return q->nb_elements;
191 static int cqueue_empty(cqueue *q)
193 return !q->nb_elements;
196 static int cqueue_enqueue(cqueue *q, double element)
200 av_assert2(q->nb_elements != q->size);
202 i = (q->first + q->nb_elements) % q->size;
203 q->elements[i] = element;
209 static double cqueue_peek(cqueue *q, int index)
211 av_assert2(index < q->nb_elements);
212 return q->elements[(q->first + index) % q->size];
215 static int cqueue_dequeue(cqueue *q, double *element)
217 av_assert2(!cqueue_empty(q));
219 *element = q->elements[q->first];
220 q->first = (q->first + 1) % q->size;
226 static int cqueue_pop(cqueue *q)
228 av_assert2(!cqueue_empty(q));
230 q->first = (q->first + 1) % q->size;
236 static void init_gaussian_filter(DynamicAudioNormalizerContext *s)
238 double total_weight = 0.0;
239 const double sigma = (((s->filter_size / 2.0) - 1.0) / 3.0) + (1.0 / 3.0);
243 // Pre-compute constants
244 const int offset = s->filter_size / 2;
245 const double c1 = 1.0 / (sigma * sqrt(2.0 * M_PI));
246 const double c2 = 2.0 * sigma * sigma;
249 for (i = 0; i < s->filter_size; i++) {
250 const int x = i - offset;
252 s->weights[i] = c1 * exp(-x * x / c2);
253 total_weight += s->weights[i];
257 adjust = 1.0 / total_weight;
258 for (i = 0; i < s->filter_size; i++) {
259 s->weights[i] *= adjust;
263 static av_cold void uninit(AVFilterContext *ctx)
265 DynamicAudioNormalizerContext *s = ctx->priv;
268 av_freep(&s->prev_amplification_factor);
269 av_freep(&s->dc_correction_value);
270 av_freep(&s->compress_threshold);
271 av_freep(&s->fade_factors[0]);
272 av_freep(&s->fade_factors[1]);
274 for (c = 0; c < s->channels; c++) {
275 if (s->gain_history_original)
276 cqueue_free(s->gain_history_original[c]);
277 if (s->gain_history_minimum)
278 cqueue_free(s->gain_history_minimum[c]);
279 if (s->gain_history_smoothed)
280 cqueue_free(s->gain_history_smoothed[c]);
283 av_freep(&s->gain_history_original);
284 av_freep(&s->gain_history_minimum);
285 av_freep(&s->gain_history_smoothed);
287 cqueue_free(s->is_enabled);
288 s->is_enabled = NULL;
290 av_freep(&s->weights);
292 ff_bufqueue_discard_all(&s->queue);
295 static int config_input(AVFilterLink *inlink)
297 AVFilterContext *ctx = inlink->dst;
298 DynamicAudioNormalizerContext *s = ctx->priv;
303 s->frame_len = frame_size(inlink->sample_rate, s->frame_len_msec);
304 av_log(ctx, AV_LOG_DEBUG, "frame len %d\n", s->frame_len);
306 s->fade_factors[0] = av_malloc_array(s->frame_len, sizeof(*s->fade_factors[0]));
307 s->fade_factors[1] = av_malloc_array(s->frame_len, sizeof(*s->fade_factors[1]));
309 s->prev_amplification_factor = av_malloc_array(inlink->channels, sizeof(*s->prev_amplification_factor));
310 s->dc_correction_value = av_calloc(inlink->channels, sizeof(*s->dc_correction_value));
311 s->compress_threshold = av_calloc(inlink->channels, sizeof(*s->compress_threshold));
312 s->gain_history_original = av_calloc(inlink->channels, sizeof(*s->gain_history_original));
313 s->gain_history_minimum = av_calloc(inlink->channels, sizeof(*s->gain_history_minimum));
314 s->gain_history_smoothed = av_calloc(inlink->channels, sizeof(*s->gain_history_smoothed));
315 s->weights = av_malloc_array(s->filter_size, sizeof(*s->weights));
316 s->is_enabled = cqueue_create(s->filter_size);
317 if (!s->prev_amplification_factor || !s->dc_correction_value ||
318 !s->compress_threshold || !s->fade_factors[0] || !s->fade_factors[1] ||
319 !s->gain_history_original || !s->gain_history_minimum ||
320 !s->gain_history_smoothed || !s->is_enabled || !s->weights)
321 return AVERROR(ENOMEM);
323 for (c = 0; c < inlink->channels; c++) {
324 s->prev_amplification_factor[c] = 1.0;
326 s->gain_history_original[c] = cqueue_create(s->filter_size);
327 s->gain_history_minimum[c] = cqueue_create(s->filter_size);
328 s->gain_history_smoothed[c] = cqueue_create(s->filter_size);
330 if (!s->gain_history_original[c] || !s->gain_history_minimum[c] ||
331 !s->gain_history_smoothed[c])
332 return AVERROR(ENOMEM);
335 precalculate_fade_factors(s->fade_factors, s->frame_len);
336 init_gaussian_filter(s);
338 s->channels = inlink->channels;
339 s->delay = s->filter_size;
344 static inline double fade(double prev, double next, int pos,
345 double *fade_factors[2])
347 return fade_factors[0][pos] * prev + fade_factors[1][pos] * next;
350 static inline double pow_2(const double value)
352 return value * value;
355 static inline double bound(const double threshold, const double val)
357 const double CONST = 0.8862269254527580136490837416705725913987747280611935; //sqrt(PI) / 2.0
358 return erf(CONST * (val / threshold)) * threshold;
361 static double find_peak_magnitude(AVFrame *frame, int channel)
363 double max = DBL_EPSILON;
367 for (c = 0; c < frame->channels; c++) {
368 double *data_ptr = (double *)frame->extended_data[c];
370 for (i = 0; i < frame->nb_samples; i++)
371 max = FFMAX(max, fabs(data_ptr[i]));
374 double *data_ptr = (double *)frame->extended_data[channel];
376 for (i = 0; i < frame->nb_samples; i++)
377 max = FFMAX(max, fabs(data_ptr[i]));
383 static double compute_frame_rms(AVFrame *frame, int channel)
385 double rms_value = 0.0;
389 for (c = 0; c < frame->channels; c++) {
390 const double *data_ptr = (double *)frame->extended_data[c];
392 for (i = 0; i < frame->nb_samples; i++) {
393 rms_value += pow_2(data_ptr[i]);
397 rms_value /= frame->nb_samples * frame->channels;
399 const double *data_ptr = (double *)frame->extended_data[channel];
400 for (i = 0; i < frame->nb_samples; i++) {
401 rms_value += pow_2(data_ptr[i]);
404 rms_value /= frame->nb_samples;
407 return FFMAX(sqrt(rms_value), DBL_EPSILON);
410 static double get_max_local_gain(DynamicAudioNormalizerContext *s, AVFrame *frame,
413 const double maximum_gain = s->peak_value / find_peak_magnitude(frame, channel);
414 const double rms_gain = s->target_rms > DBL_EPSILON ? (s->target_rms / compute_frame_rms(frame, channel)) : DBL_MAX;
415 return bound(s->max_amplification, FFMIN(maximum_gain, rms_gain));
418 static double minimum_filter(cqueue *q)
420 double min = DBL_MAX;
423 for (i = 0; i < cqueue_size(q); i++) {
424 min = FFMIN(min, cqueue_peek(q, i));
430 static double gaussian_filter(DynamicAudioNormalizerContext *s, cqueue *q)
435 for (i = 0; i < cqueue_size(q); i++) {
436 result += cqueue_peek(q, i) * s->weights[i];
442 static void update_gain_history(DynamicAudioNormalizerContext *s, int channel,
443 double current_gain_factor)
445 if (cqueue_empty(s->gain_history_original[channel]) ||
446 cqueue_empty(s->gain_history_minimum[channel])) {
447 const int pre_fill_size = s->filter_size / 2;
448 const double initial_value = s->alt_boundary_mode ? current_gain_factor : 1.0;
450 s->prev_amplification_factor[channel] = initial_value;
452 while (cqueue_size(s->gain_history_original[channel]) < pre_fill_size) {
453 cqueue_enqueue(s->gain_history_original[channel], initial_value);
457 cqueue_enqueue(s->gain_history_original[channel], current_gain_factor);
459 while (cqueue_size(s->gain_history_original[channel]) >= s->filter_size) {
461 av_assert0(cqueue_size(s->gain_history_original[channel]) == s->filter_size);
463 if (cqueue_empty(s->gain_history_minimum[channel])) {
464 const int pre_fill_size = s->filter_size / 2;
465 double initial_value = s->alt_boundary_mode ? cqueue_peek(s->gain_history_original[channel], 0) : 1.0;
466 int input = pre_fill_size;
468 while (cqueue_size(s->gain_history_minimum[channel]) < pre_fill_size) {
470 initial_value = FFMIN(initial_value, cqueue_peek(s->gain_history_original[channel], input));
471 cqueue_enqueue(s->gain_history_minimum[channel], initial_value);
475 minimum = minimum_filter(s->gain_history_original[channel]);
477 cqueue_enqueue(s->gain_history_minimum[channel], minimum);
479 cqueue_pop(s->gain_history_original[channel]);
482 while (cqueue_size(s->gain_history_minimum[channel]) >= s->filter_size) {
484 av_assert0(cqueue_size(s->gain_history_minimum[channel]) == s->filter_size);
485 smoothed = gaussian_filter(s, s->gain_history_minimum[channel]);
487 cqueue_enqueue(s->gain_history_smoothed[channel], smoothed);
489 cqueue_pop(s->gain_history_minimum[channel]);
493 static inline double update_value(double new, double old, double aggressiveness)
495 av_assert0((aggressiveness >= 0.0) && (aggressiveness <= 1.0));
496 return aggressiveness * new + (1.0 - aggressiveness) * old;
499 static void perform_dc_correction(DynamicAudioNormalizerContext *s, AVFrame *frame)
501 const double diff = 1.0 / frame->nb_samples;
502 int is_first_frame = cqueue_empty(s->gain_history_original[0]);
505 for (c = 0; c < s->channels; c++) {
506 double *dst_ptr = (double *)frame->extended_data[c];
507 double current_average_value = 0.0;
510 for (i = 0; i < frame->nb_samples; i++)
511 current_average_value += dst_ptr[i] * diff;
513 prev_value = is_first_frame ? current_average_value : s->dc_correction_value[c];
514 s->dc_correction_value[c] = is_first_frame ? current_average_value : update_value(current_average_value, s->dc_correction_value[c], 0.1);
516 for (i = 0; i < frame->nb_samples; i++) {
517 dst_ptr[i] -= fade(prev_value, s->dc_correction_value[c], i, s->fade_factors);
522 static double setup_compress_thresh(double threshold)
524 if ((threshold > DBL_EPSILON) && (threshold < (1.0 - DBL_EPSILON))) {
525 double current_threshold = threshold;
526 double step_size = 1.0;
528 while (step_size > DBL_EPSILON) {
529 while ((llrint((current_threshold + step_size) * (UINT64_C(1) << 63)) >
530 llrint(current_threshold * (UINT64_C(1) << 63))) &&
531 (bound(current_threshold + step_size, 1.0) <= threshold)) {
532 current_threshold += step_size;
538 return current_threshold;
544 static double compute_frame_std_dev(DynamicAudioNormalizerContext *s,
545 AVFrame *frame, int channel)
547 double variance = 0.0;
551 for (c = 0; c < s->channels; c++) {
552 const double *data_ptr = (double *)frame->extended_data[c];
554 for (i = 0; i < frame->nb_samples; i++) {
555 variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero*
558 variance /= (s->channels * frame->nb_samples) - 1;
560 const double *data_ptr = (double *)frame->extended_data[channel];
562 for (i = 0; i < frame->nb_samples; i++) {
563 variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero*
565 variance /= frame->nb_samples - 1;
568 return FFMAX(sqrt(variance), DBL_EPSILON);
571 static void perform_compression(DynamicAudioNormalizerContext *s, AVFrame *frame)
573 int is_first_frame = cqueue_empty(s->gain_history_original[0]);
576 if (s->channels_coupled) {
577 const double standard_deviation = compute_frame_std_dev(s, frame, -1);
578 const double current_threshold = FFMIN(1.0, s->compress_factor * standard_deviation);
580 const double prev_value = is_first_frame ? current_threshold : s->compress_threshold[0];
581 double prev_actual_thresh, curr_actual_thresh;
582 s->compress_threshold[0] = is_first_frame ? current_threshold : update_value(current_threshold, s->compress_threshold[0], (1.0/3.0));
584 prev_actual_thresh = setup_compress_thresh(prev_value);
585 curr_actual_thresh = setup_compress_thresh(s->compress_threshold[0]);
587 for (c = 0; c < s->channels; c++) {
588 double *const dst_ptr = (double *)frame->extended_data[c];
589 for (i = 0; i < frame->nb_samples; i++) {
590 const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, s->fade_factors);
591 dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]);
595 for (c = 0; c < s->channels; c++) {
596 const double standard_deviation = compute_frame_std_dev(s, frame, c);
597 const double current_threshold = setup_compress_thresh(FFMIN(1.0, s->compress_factor * standard_deviation));
599 const double prev_value = is_first_frame ? current_threshold : s->compress_threshold[c];
600 double prev_actual_thresh, curr_actual_thresh;
602 s->compress_threshold[c] = is_first_frame ? current_threshold : update_value(current_threshold, s->compress_threshold[c], 1.0/3.0);
604 prev_actual_thresh = setup_compress_thresh(prev_value);
605 curr_actual_thresh = setup_compress_thresh(s->compress_threshold[c]);
607 dst_ptr = (double *)frame->extended_data[c];
608 for (i = 0; i < frame->nb_samples; i++) {
609 const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, s->fade_factors);
610 dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]);
616 static void analyze_frame(DynamicAudioNormalizerContext *s, AVFrame *frame)
618 if (s->dc_correction) {
619 perform_dc_correction(s, frame);
622 if (s->compress_factor > DBL_EPSILON) {
623 perform_compression(s, frame);
626 if (s->channels_coupled) {
627 const double current_gain_factor = get_max_local_gain(s, frame, -1);
630 for (c = 0; c < s->channels; c++)
631 update_gain_history(s, c, current_gain_factor);
635 for (c = 0; c < s->channels; c++)
636 update_gain_history(s, c, get_max_local_gain(s, frame, c));
640 static void amplify_frame(DynamicAudioNormalizerContext *s, AVFrame *frame, int enabled)
644 for (c = 0; c < s->channels; c++) {
645 double *dst_ptr = (double *)frame->extended_data[c];
646 double current_amplification_factor;
648 cqueue_dequeue(s->gain_history_smoothed[c], ¤t_amplification_factor);
650 for (i = 0; i < frame->nb_samples && enabled; i++) {
651 const double amplification_factor = fade(s->prev_amplification_factor[c],
652 current_amplification_factor, i,
655 dst_ptr[i] *= amplification_factor;
657 if (fabs(dst_ptr[i]) > s->peak_value)
658 dst_ptr[i] = copysign(s->peak_value, dst_ptr[i]);
661 s->prev_amplification_factor[c] = current_amplification_factor;
665 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
667 AVFilterContext *ctx = inlink->dst;
668 DynamicAudioNormalizerContext *s = ctx->priv;
669 AVFilterLink *outlink = inlink->dst->outputs[0];
672 if (!cqueue_empty(s->gain_history_smoothed[0])) {
674 AVFrame *out = ff_bufqueue_get(&s->queue);
676 cqueue_dequeue(s->is_enabled, &is_enabled);
678 amplify_frame(s, out, is_enabled > 0.);
679 ret = ff_filter_frame(outlink, out);
682 av_frame_make_writable(in);
683 cqueue_enqueue(s->is_enabled, !ctx->is_disabled);
684 analyze_frame(s, in);
685 ff_bufqueue_add(ctx, &s->queue, in);
690 static int flush_buffer(DynamicAudioNormalizerContext *s, AVFilterLink *inlink,
691 AVFilterLink *outlink)
693 AVFrame *out = ff_get_audio_buffer(outlink, s->frame_len);
697 return AVERROR(ENOMEM);
699 for (c = 0; c < s->channels; c++) {
700 double *dst_ptr = (double *)out->extended_data[c];
702 for (i = 0; i < out->nb_samples; i++) {
703 dst_ptr[i] = s->alt_boundary_mode ? DBL_EPSILON : ((s->target_rms > DBL_EPSILON) ? FFMIN(s->peak_value, s->target_rms) : s->peak_value);
704 if (s->dc_correction) {
705 dst_ptr[i] *= ((i % 2) == 1) ? -1 : 1;
706 dst_ptr[i] += s->dc_correction_value[c];
712 return filter_frame(inlink, out);
715 static int flush(AVFilterLink *outlink)
717 AVFilterContext *ctx = outlink->src;
718 DynamicAudioNormalizerContext *s = ctx->priv;
721 if (!cqueue_empty(s->gain_history_smoothed[0])) {
722 ret = flush_buffer(s, ctx->inputs[0], outlink);
723 } else if (s->queue.available) {
724 AVFrame *out = ff_bufqueue_get(&s->queue);
727 ret = ff_filter_frame(outlink, out);
728 s->delay = s->queue.available;
734 static int activate(AVFilterContext *ctx)
736 AVFilterLink *inlink = ctx->inputs[0];
737 AVFilterLink *outlink = ctx->outputs[0];
738 DynamicAudioNormalizerContext *s = ctx->priv;
743 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
746 ret = ff_inlink_consume_samples(inlink, s->frame_len, s->frame_len, &in);
750 ret = filter_frame(inlink, in);
755 if (ff_inlink_queued_samples(inlink) >= s->frame_len) {
756 ff_filter_set_ready(ctx, 10);
761 if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
762 if (status == AVERROR_EOF)
766 if (s->eof && s->delay > 0)
767 return flush(outlink);
769 if (s->eof && s->delay <= 0) {
770 ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
775 FF_FILTER_FORWARD_WANTED(outlink, inlink);
777 return FFERROR_NOT_READY;
780 static const AVFilterPad avfilter_af_dynaudnorm_inputs[] = {
783 .type = AVMEDIA_TYPE_AUDIO,
784 .config_props = config_input,
789 static const AVFilterPad avfilter_af_dynaudnorm_outputs[] = {
792 .type = AVMEDIA_TYPE_AUDIO,
797 AVFilter ff_af_dynaudnorm = {
798 .name = "dynaudnorm",
799 .description = NULL_IF_CONFIG_SMALL("Dynamic Audio Normalizer."),
800 .query_formats = query_formats,
801 .priv_size = sizeof(DynamicAudioNormalizerContext),
804 .activate = activate,
805 .inputs = avfilter_af_dynaudnorm_inputs,
806 .outputs = avfilter_af_dynaudnorm_outputs,
807 .priv_class = &dynaudnorm_class,
808 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,