[FFmpeg-devel] [PATCH 2/3] timecode: add ff_timecode_to_string().

Clément Bœsch ubitux at gmail.com
Tue Dec 6 11:37:38 CET 2011


From: Clément Bœsch <clement.boesch at smartjog.com>

---
 libavcodec/timecode.c |   16 ++++++++++++++++
 libavcodec/timecode.h |   11 +++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
index 4148f32..4bfb529 100644
--- a/libavcodec/timecode.c
+++ b/libavcodec/timecode.c
@@ -78,6 +78,22 @@ static int ff_check_timecode_rate(void *avcl, AVRational rate, int drop)
     }
 }
 
+char *ff_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame)
+{
+    int frame_num = tc->start + frame;
+    int fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
+    int ff  = frame_num % fps;
+    int ss  = frame_num / fps        % 60;
+    int mm  = frame_num / (fps*60)   % 60;
+    int hh  = frame_num / (fps*3600) % 24;
+
+    if (tc->drop)
+        frame_num = ff_framenum_to_drop_timecode(frame_num);
+    snprintf(buf, sizeof("hh:mm:ss.ff"), "%02d:%02d:%02d%c%02d",
+             hh, mm, ss, tc->drop ? ';' : ':', ff);
+    return buf;
+}
+
 int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
 {
     int hh, mm, ss, ff, fps, ret;
diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h
index 5646199..b1bb5c7 100644
--- a/libavcodec/timecode.h
+++ b/libavcodec/timecode.h
@@ -61,6 +61,17 @@ int ff_framenum_to_drop_timecode(int frame_num);
 uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
 
 /**
+ * @brief       Load timecode string in buf
+ * @param buf   Destination buffer
+ * @param tc    Timecode struct pointer
+ * @param frame Frame id (timecode frame is computed with tc->start+frame)
+ * @return a pointer to the buf parameter
+ * @note  buf must have enough space to store the timecode representation
+ *        (sizeof("hh:mm:ss.ff"))
+ */
+char *ff_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame);
+
+/**
  * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
  * from tc struct must be set.
  *
-- 
1.7.7.3



More information about the ffmpeg-devel mailing list