History

avutil/timecode: add av_timecode_make_smpte_tc_string2

Marton Balint committed 6 years ago

Commit 837b6eb1 parent 53574014 files · +39 −2Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavutil/timecode.c +18 −1
  3. libavutil/timecode.h +17 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2017-10-21 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2020-09-xx - xxxxxxxxxx - lavu 56.59.100 - timecode.h
19+ Add av_timecode_make_smpte_tc_string2.
20+
1821 2020-08-21 - xxxxxxxxxx - lavu 56.58.100 - avstring.h
1922 Deprecate av_d2str(). Use av_asprintf() instead.
2023
libavutil/timecode.c+18−1
@@ -136,16 +136,33 @@ static unsigned bcd2uint(uint8_t bcd) · 135 unmodified lines
136136 return low + 10*high;
137137 }
138138
139−char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
139+char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
140140 {
141141 unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
142142 unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
143143 unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
144144 unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
145145 unsigned drop = tcsmpte & 1<<30 && !prevent_df; // 1-bit drop if not arbitrary bit
146+
147+ if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
148+ ff <<= 1;
149+ if (!skip_field) {
150+ if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
151+ ff += !!(tcsmpte & 1 << 7);
152+ else
153+ ff += !!(tcsmpte & 1 << 23);
154+ }
155+ }
156+
146157 snprintf(buf, AV_TIMECODE_STR_SIZE, "%02u:%02u:%02u%c%02u",
147158 hh, mm, ss, drop ? ';' : ':', ff);
148159 return buf;
160+
161+}
162+
163+char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
164+{
165+ return av_timecode_make_smpte_tc_string2(buf, (AVRational){30, 1}, tcsmpte, prevent_df, 1);
149166 }
150167
151168 char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit)
libavutil/timecode.h+17−0
@@ -109,6 +109,23 @@ uint32_t av_timecode_get_smpte(AVRational rate, int drop, int hh, int mm, int ss · 108 unmodified lines
109109 */
110110 char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum);
111111
112+/**
113+ * Get the timecode string from the SMPTE timecode format.
114+ *
115+ * In contrast to av_timecode_make_smpte_tc_string this function supports 50/60
116+ * fps timecodes by using the field bit.
117+ *
118+ * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long
119+ * @param rate frame rate of the timecode
120+ * @param tcsmpte the 32-bit SMPTE timecode
121+ * @param prevent_df prevent the use of a drop flag when it is known the DF bit
122+ * is arbitrary
123+ * @param skip_field prevent the use of a field flag when it is known the field
124+ * bit is arbitrary (e.g. because it is used as PC flag)
125+ * @return the buf parameter
126+ */
127+char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field);
128+
112129 /**
113130 * Get the timecode string from the SMPTE timecode format.
114131 *
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 56
82−#define LIBAVUTIL_VERSION_MINOR 58
82+#define LIBAVUTIL_VERSION_MINOR 59
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t