diff options
author | Paul B Mahol <onemda@gmail.com> | 2017-05-15 14:05:17 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2017-05-15 14:29:18 +0200 |
commit | 7760ed7e9606203eea478fc3620665859c739dc0 (patch) | |
tree | 082c4ea63a1f1ed9fb307fc1efdd967b3a7436c1 | |
parent | 921bd9a2be4c1f4a0524346a694e2da814488d7f (diff) | |
download | ffmpeg-7760ed7e9606203eea478fc3620665859c739dc0.tar.gz |
avfilter/af_silenceremove: set output timestamps
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r-- | libavfilter/af_silenceremove.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/libavfilter/af_silenceremove.c b/libavfilter/af_silenceremove.c index f156d1883d..af50463059 100644 --- a/libavfilter/af_silenceremove.c +++ b/libavfilter/af_silenceremove.c @@ -217,11 +217,18 @@ static int config_input(AVFilterLink *inlink) return 0; } -static void flush(AVFrame *out, AVFilterLink *outlink, +static void flush(SilenceRemoveContext *s, + AVFrame *out, AVFilterLink *outlink, int *nb_samples_written, int *ret) { if (*nb_samples_written) { out->nb_samples = *nb_samples_written / outlink->channels; + + out->pts = s->next_pts; + s->next_pts += av_rescale_q(out->nb_samples, + (AVRational){1, outlink->sample_rate}, + outlink->time_base); + *ret = ff_filter_frame(outlink, out); *nb_samples_written = 0; } else { @@ -297,6 +304,12 @@ silence_trim_flush: memcpy(out->data[0], &s->start_holdoff[s->start_holdoff_offset], nbs * sizeof(double)); + + out->pts = s->next_pts; + s->next_pts += av_rescale_q(out->nb_samples, + (AVRational){1, outlink->sample_rate}, + outlink->time_base); + s->start_holdoff_offset += nbs; ret = ff_filter_frame(outlink, out); @@ -330,7 +343,7 @@ silence_copy: if (threshold && s->stop_holdoff_end && !s->leave_silence) { s->mode = SILENCE_COPY_FLUSH; - flush(out, outlink, &nb_samples_written, &ret); + flush(s, out, outlink, &nb_samples_written, &ret); goto silence_copy_flush; } else if (threshold) { for (j = 0; j < inlink->channels; j++) { @@ -358,7 +371,7 @@ silence_copy: if (!s->restart) { s->mode = SILENCE_STOP; - flush(out, outlink, &nb_samples_written, &ret); + flush(s, out, outlink, &nb_samples_written, &ret); goto silence_stop; } else { s->stop_found_periods = 0; @@ -367,19 +380,25 @@ silence_copy: s->start_holdoff_end = 0; clear_window(s); s->mode = SILENCE_TRIM; - flush(out, outlink, &nb_samples_written, &ret); + flush(s, out, outlink, &nb_samples_written, &ret); goto silence_trim; } } s->mode = SILENCE_COPY_FLUSH; - flush(out, outlink, &nb_samples_written, &ret); + flush(s, out, outlink, &nb_samples_written, &ret); goto silence_copy_flush; } } } - flush(out, outlink, &nb_samples_written, &ret); + flush(s, out, outlink, &nb_samples_written, &ret); } else { memcpy(obuf, ibuf, sizeof(double) * nbs * inlink->channels); + + out->pts = s->next_pts; + s->next_pts += av_rescale_q(out->nb_samples, + (AVRational){1, outlink->sample_rate}, + outlink->time_base); + ret = ff_filter_frame(outlink, out); } break; @@ -401,6 +420,11 @@ silence_copy_flush: nbs * sizeof(double)); s->stop_holdoff_offset += nbs; + out->pts = s->next_pts; + s->next_pts += av_rescale_q(out->nb_samples, + (AVRational){1, outlink->sample_rate}, + outlink->time_base); + ret = ff_filter_frame(outlink, out); if (s->stop_holdoff_offset == s->stop_holdoff_end) { @@ -439,6 +463,12 @@ static int request_frame(AVFilterLink *outlink) memcpy(frame->data[0], &s->stop_holdoff[s->stop_holdoff_offset], nbs * sizeof(double)); + + frame->pts = s->next_pts; + s->next_pts += av_rescale_q(frame->nb_samples, + (AVRational){1, outlink->sample_rate}, + outlink->time_base); + ret = ff_filter_frame(ctx->inputs[0], frame); } s->mode = SILENCE_STOP; |