]> git.sesse.net Git - ffmpeg/commitdiff
avutil/timecode: add av_timecode_make_smpte_tc_string2
authorMarton Balint <cus@passwd.hu>
Fri, 24 Jul 2020 13:09:32 +0000 (15:09 +0200)
committerMarton Balint <cus@passwd.hu>
Sun, 13 Sep 2020 15:51:57 +0000 (17:51 +0200)
Signed-off-by: Marton Balint <cus@passwd.hu>
doc/APIchanges
libavutil/timecode.c
libavutil/timecode.h
libavutil/version.h

index 0054908e1e89df0acc360a3f2764616b7e3b2748..e2d7369c832d65a7e141618c7c55efbaaa561a0a 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2020-09-xx - xxxxxxxxxx - lavu 56.59.100 - timecode.h
+  Add av_timecode_make_smpte_tc_string2.
+
 2020-08-21 - xxxxxxxxxx - lavu 56.58.100 - avstring.h
   Deprecate av_d2str(). Use av_asprintf() instead.
 
index 806638ddfcefaf39ba6828f82c743c405851430b..f2db21c52caa7f0efefbf5b8ca1d74a9f2ba3cac 100644 (file)
@@ -136,16 +136,33 @@ static unsigned bcd2uint(uint8_t bcd)
    return low + 10*high;
 }
 
-char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
+char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
 {
     unsigned hh   = bcd2uint(tcsmpte     & 0x3f);    // 6-bit hours
     unsigned mm   = bcd2uint(tcsmpte>>8  & 0x7f);    // 7-bit minutes
     unsigned ss   = bcd2uint(tcsmpte>>16 & 0x7f);    // 7-bit seconds
     unsigned ff   = bcd2uint(tcsmpte>>24 & 0x3f);    // 6-bit frames
     unsigned drop = tcsmpte & 1<<30 && !prevent_df;  // 1-bit drop if not arbitrary bit
+
+    if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
+        ff <<= 1;
+        if (!skip_field) {
+            if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
+                ff += !!(tcsmpte & 1 << 7);
+            else
+                ff += !!(tcsmpte & 1 << 23);
+        }
+    }
+
     snprintf(buf, AV_TIMECODE_STR_SIZE, "%02u:%02u:%02u%c%02u",
              hh, mm, ss, drop ? ';' : ':', ff);
     return buf;
+
+}
+
+char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
+{
+    return av_timecode_make_smpte_tc_string2(buf, (AVRational){30, 1}, tcsmpte, prevent_df, 1);
 }
 
 char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit)
index e54b116e93b556b91c70bf6e6e05c782a5fd4262..f9471a6e38443425ec4865824afdd24ccdb0f459 100644 (file)
@@ -109,6 +109,23 @@ uint32_t av_timecode_get_smpte(AVRational rate, int drop, int hh, int mm, int ss
  */
 char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum);
 
+/**
+ * Get the timecode string from the SMPTE timecode format.
+ *
+ * In contrast to av_timecode_make_smpte_tc_string this function supports 50/60
+ * fps timecodes by using the field bit.
+ *
+ * @param buf        destination buffer, must be at least AV_TIMECODE_STR_SIZE long
+ * @param rate       frame rate of the timecode
+ * @param tcsmpte    the 32-bit SMPTE timecode
+ * @param prevent_df prevent the use of a drop flag when it is known the DF bit
+ *                   is arbitrary
+ * @param skip_field prevent the use of a field flag when it is known the field
+ *                   bit is arbitrary (e.g. because it is used as PC flag)
+ * @return           the buf parameter
+ */
+char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field);
+
 /**
  * Get the timecode string from the SMPTE timecode format.
  *
index 3f0a4a840250df587b4d916f07f6689a7c8fa1d6..7028bd2c88124c555157b2c2f7d9817d12ac13a6 100644 (file)
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  58
+#define LIBAVUTIL_VERSION_MINOR  59
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \