[FFmpeg-cvslog] timecode: move dropframe code and doxycomment it.

Clément Bœsch git at videolan.org
Wed Aug 10 16:22:47 CEST 2011


ffmpeg | branch: master | Clément Bœsch <clement.boesch at smartjog.com> | Wed Jul  6 14:55:06 2011 +0200| [51fb933dd0dda5f581d7489b32b8446767d33b97] | committer: Clément Bœsch

timecode: move dropframe code and doxycomment it.

This is based on the original work by Baptiste Coudurier.

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

 libavcodec/mpeg12enc.c |    9 ++-------
 libavcodec/timecode.c  |    9 +++++++++
 libavcodec/timecode.h  |    8 ++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index c9fa41b..b3ed367 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -299,13 +299,8 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
             time_code = s->current_picture_ptr->f.coded_picture_number + s->avctx->timecode_frame_start;
 
             s->gop_picture_number = s->current_picture_ptr->f.coded_picture_number;
-            if (s->tc.drop) {
-                /* only works for NTSC 29.97 */
-                int d = time_code / 17982;
-                int m = time_code % 17982;
-                //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
-                time_code += 18 * d + 2 * ((m - 2) / 1798);
-            }
+            if (s->tc.drop)
+                time_code = ff_framenum_to_drop_timecode(time_code);
             put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
             put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
             put_bits(&s->pb, 1, 1);
diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
index d9c3f7d..434b3cb 100644
--- a/libavcodec/timecode.c
+++ b/libavcodec/timecode.c
@@ -28,6 +28,15 @@
 #include "timecode.h"
 #include "libavutil/log.h"
 
+int ff_framenum_to_drop_timecode(int frame_num)
+{
+    /* only works for NTSC 29.97 */
+    int d = frame_num / 17982;
+    int m = frame_num % 17982;
+    //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
+    return frame_num + 18 * d + 2 * ((m - 2) / 1798);
+}
+
 int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
 {
     int hh, mm, ss, ff, fps;
diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h
index d2f6606..bf4116b 100644
--- a/libavcodec/timecode.h
+++ b/libavcodec/timecode.h
@@ -44,6 +44,14 @@ struct ff_timecode {
 };
 
 /**
+ * @brief           Adjust frame number for NTSC drop frame time code
+ * @param frame_num Actual frame number to adjust
+ * @return          Adjusted frame number
+ * @warning         Adjustment is only valid in NTSC 29.97
+ */
+int ff_framenum_to_drop_timecode(int frame_num);
+
+/**
  * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
  * from tc struct must be set.
  *



More information about the ffmpeg-cvslog mailing list