[FFmpeg-cvslog] avconv: Set audio filter time base to the sample rate

Martin Storsjö git at videolan.org
Thu Jul 5 21:58:36 CEST 2012


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Sat Jun 30 11:26:11 2012 +0300| [715129cdc409499245fc9519da3db1436b660d3d] | committer: Martin Storsjö

avconv: Set audio filter time base to the sample rate

If the output frame size is smaller than the input sample rate,
and the input stream time base corresponds exactly to the input
frame size (getting input packet timestamps like 0, 1, 2, 3, 4 etc),
the output timestamps from the filter will be like
0, 1, 2, 3, 4, 4, 5 ..., leadning to non-monotone timestamps later.

A concrete example is input mp3 data having frame sizes of 1152
samples, transcoded to aac with 1024 sample frames.

By setting the audio filter time base to the sample rate, we will
get sensible timestamps for all output packets, regardless of
the ratio between the input and output frame sizes.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=715129cdc409499245fc9519da3db1436b660d3d
---

 avconv.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/avconv.c b/avconv.c
index 3a7cebf..9613567 100644
--- a/avconv.c
+++ b/avconv.c
@@ -853,7 +853,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
 
     snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s"
              ":channel_layout=0x%"PRIx64,
-             ist->st->time_base.num, ist->st->time_base.den,
+             1, ist->st->codec->sample_rate,
              ist->st->codec->sample_rate,
              av_get_sample_fmt_name(ist->st->codec->sample_fmt),
              ist->st->codec->channel_layout);
@@ -2029,6 +2029,10 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
             }
     }
 
+    if (decoded_frame->pts != AV_NOPTS_VALUE)
+        decoded_frame->pts = av_rescale_q(decoded_frame->pts,
+                                          ist->st->time_base,
+                                          (AVRational){1, ist->st->codec->sample_rate});
     for (i = 0; i < ist->nb_filters; i++)
         av_buffersrc_write_frame(ist->filters[i]->filter, decoded_frame);
 



More information about the ffmpeg-cvslog mailing list