summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-07-02 18:38:06 -0300
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-07-03 11:57:09 -0300
commitb8f556a566483758be82797421cb9593bba1ac43 (patch)
tree1d0107528e05f7c5d275ee66e17f7ef8d30fc3c5
parent2f6086e49589be3c7bc54c0e822c4f9e23161a46 (diff)
ffmpegenc: Fix timestamp resyncing
Properly convert bytes into time using sample size, sample rate and channels number, instead of sample rate only. This can cause huge timestamp discontinuities (even though the durations remain correct) and might cause problems to muxers. Fixes #623388
-rw-r--r--ext/ffmpeg/gstffmpegenc.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/ext/ffmpeg/gstffmpegenc.c b/ext/ffmpeg/gstffmpegenc.c
index 8c5763d..4454347 100644
--- a/ext/ffmpeg/gstffmpegenc.c
+++ b/ext/ffmpeg/gstffmpegenc.c
@@ -930,15 +930,18 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf)
ffmpegenc->adapter_consumed = 0;
} else {
GstClockTime upstream_time;
+ GstClockTime consumed_time;
guint64 bytes;
/* use timestamp at head of the adapter */
- GST_LOG_OBJECT (ffmpegenc, "taking adapter timestamp %" GST_TIME_FORMAT,
- GST_TIME_ARGS (ffmpegenc->adapter_ts));
- timestamp = ffmpegenc->adapter_ts;
- timestamp +=
+ consumed_time =
gst_util_uint64_scale (ffmpegenc->adapter_consumed, GST_SECOND,
ctx->sample_rate);
+ timestamp = ffmpegenc->adapter_ts + consumed_time;
+ GST_LOG_OBJECT (ffmpegenc, "taking adapter timestamp %" GST_TIME_FORMAT
+ " and adding consumed time %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (ffmpegenc->adapter_ts), GST_TIME_ARGS (consumed_time));
+
/* check with upstream timestamps, if too much deviation,
* forego some timestamp perfection in favour of upstream syncing
* (particularly in case these do not happen to come in multiple
@@ -948,7 +951,8 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf)
GstClockTimeDiff diff;
upstream_time +=
- gst_util_uint64_scale (bytes, GST_SECOND, ctx->sample_rate);
+ gst_util_uint64_scale (bytes, GST_SECOND,
+ ctx->sample_rate * osize * ctx->channels);
diff = upstream_time - timestamp;
/* relaxed difference, rather than half a sample or so ... */
if (diff > GST_SECOND / 10 || diff < -GST_SECOND / 10) {
@@ -978,6 +982,10 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf)
GST_LOG_OBJECT (ffmpegenc, "taking %u bytes from the adapter",
frame_bytes);
+ /* Note that we take frame_bytes and add frame_size.
+ * Makes sense when resyncing because you don't have to count channels
+ * or samplesize to divide by the samplerate */
+
/* take an audio buffer out of the adapter */
in_data = (guint8 *) gst_adapter_peek (ffmpegenc->adapter, frame_bytes);
ffmpegenc->adapter_consumed += frame_size;