[FFmpeg-devel] [PATCH 2/4] timecode: string representation can be negative.

Clément Bœsch ubitux at gmail.com
Thu Jan 5 21:03:43 CET 2012


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

Timecode can be specified with a negative value in MOV...
---
 libavcodec/timecode.c |    7 +++++--
 libavcodec/timecode.h |    3 ++-
 libavcodec/version.h  |    2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
index 420b276..a8b4242 100644
--- a/libavcodec/timecode.c
+++ b/libavcodec/timecode.c
@@ -83,7 +83,7 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
 {
     int frame_num = tc->start + frame;
     int fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
-    int hh, mm, ss, ff;
+    int hh, mm, ss, ff, neg = 0;
 
     if (tc->drop)
         frame_num = avpriv_framenum_to_drop_timecode(frame_num);
@@ -91,7 +91,10 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
     ss = frame_num / fps        % 60;
     mm = frame_num / (fps*60)   % 60;
     hh = frame_num / (fps*3600) % 24;
-    snprintf(buf, sizeof("hh:mm:ss.ff"), "%02d:%02d:%02d%c%02d",
+    if (ff < 0 || ss < 0 || mm < 0 || hh < 0)
+        neg = 1, ff = -ff, ss = -ss, mm = -mm, hh = -hh;
+    snprintf(buf, sizeof("-hh:mm:ss.ff"), "%s%02d:%02d:%02d%c%02d",
+             neg ? "-" : "",
              hh, mm, ss, tc->drop ? ';' : ':', ff);
     return buf;
 }
diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h
index 50ea313..263ca29 100644
--- a/libavcodec/timecode.h
+++ b/libavcodec/timecode.h
@@ -67,8 +67,9 @@ uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop);
  * @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  timecode representation can be a negative timecode
  * @note  buf must have enough space to store the timecode representation
- *        (sizeof("hh:mm:ss.ff"))
+ *        (sizeof("-hh:mm:ss.ff"))
  */
 char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame);
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index ce4259f..3cc2bc3 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -22,7 +22,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR 53
 #define LIBAVCODEC_VERSION_MINOR 54
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
1.7.8.1



More information about the ffmpeg-devel mailing list