Browse code

timecode: move dropframe code and doxycomment it.

This is based on the original work by Baptiste Coudurier.

Clément Bœsch authored on 2011/07/06 21:55:06
Showing 3 changed files
... ...
@@ -299,13 +299,8 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
299 299
             time_code = s->current_picture_ptr->f.coded_picture_number + s->avctx->timecode_frame_start;
300 300
 
301 301
             s->gop_picture_number = s->current_picture_ptr->f.coded_picture_number;
302
-            if (s->tc.drop) {
303
-                /* only works for NTSC 29.97 */
304
-                int d = time_code / 17982;
305
-                int m = time_code % 17982;
306
-                //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
307
-                time_code += 18 * d + 2 * ((m - 2) / 1798);
308
-            }
302
+            if (s->tc.drop)
303
+                time_code = ff_framenum_to_drop_timecode(time_code);
309 304
             put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
310 305
             put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
311 306
             put_bits(&s->pb, 1, 1);
... ...
@@ -28,6 +28,15 @@
28 28
 #include "timecode.h"
29 29
 #include "libavutil/log.h"
30 30
 
31
+int ff_framenum_to_drop_timecode(int frame_num)
32
+{
33
+    /* only works for NTSC 29.97 */
34
+    int d = frame_num / 17982;
35
+    int m = frame_num % 17982;
36
+    //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
37
+    return frame_num + 18 * d + 2 * ((m - 2) / 1798);
38
+}
39
+
31 40
 int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
32 41
 {
33 42
     int hh, mm, ss, ff, fps;
... ...
@@ -44,6 +44,14 @@ struct ff_timecode {
44 44
 };
45 45
 
46 46
 /**
47
+ * @brief           Adjust frame number for NTSC drop frame time code
48
+ * @param frame_num Actual frame number to adjust
49
+ * @return          Adjusted frame number
50
+ * @warning         Adjustment is only valid in NTSC 29.97
51
+ */
52
+int ff_framenum_to_drop_timecode(int frame_num);
53
+
54
+/**
47 55
  * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
48 56
  * from tc struct must be set.
49 57
  *