[FFmpeg-cvslog] lavu: add av_rescale_delta()

Michael Niedermayer git at videolan.org
Sat Oct 27 00:30:56 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Oct 26 21:23:19 2012 +0200| [8766ad9eb1b0b498ec5db824c8c34385e3d6d713] | committer: Michael Niedermayer

lavu: add av_rescale_delta()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavutil/mathematics.c |   23 +++++++++++++++++++++++
 libavutil/mathematics.h |    5 +++++
 2 files changed, 28 insertions(+)

diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index c334aa1..6c2f6c0 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -142,3 +142,26 @@ int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){
         c-= mod;
     return c;
 }
+
+int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts,  AVRational fs_tb, int duration, int64_t *last, AVRational out_tb){
+    int64_t a, b, this;
+
+    av_assert0(in_ts != AV_NOPTS_VALUE);
+    av_assert0(duration >= 0);
+
+    if (*last == AV_NOPTS_VALUE || !duration || in_tb.num*(int64_t)out_tb.den <= out_tb.num*(int64_t)in_tb.den) {
+simple_round:
+        *last = av_rescale_q(in_ts, in_tb, fs_tb) + duration;
+        return av_rescale_q(in_ts, in_tb, out_tb);
+    }
+
+    a =  av_rescale_q_rnd(2*in_ts-1, in_tb, fs_tb, AV_ROUND_DOWN)   >>1;
+    b = (av_rescale_q_rnd(2*in_ts+1, in_tb, fs_tb, AV_ROUND_UP  )+1)>>1;
+    if (*last < 2*a - b || *last > 2*b - a)
+        goto simple_round;
+
+    this = av_clip64(*last, a, b);
+    *last = this + duration;
+
+    return av_rescale_q(this, fs_tb, out_tb);
+}
diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h
index 113286c..81b14fd 100644
--- a/libavutil/mathematics.h
+++ b/libavutil/mathematics.h
@@ -123,6 +123,11 @@ int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
 int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod);
 
 /**
+ * Rescale a timestamp while preserving known durations.
+ */
+int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts,  AVRational fs_tb, int duration, int64_t *last, AVRational out_tb);
+
+/**
  * @}
  */
 



More information about the ffmpeg-cvslog mailing list