- // country code
- sei_data[0] = 181;
- sei_data[1] = 0;
- sei_data[2] = 49;
-
- /**
- * 'GA94' is standard in North America for ATSC, but hard coding
- * this style may not be the right thing to do -- other formats
- * do exist. This information is not available in the side_data
- * so we are going with this right now.
- */
- AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4'));
- sei_data[7] = 3;
- sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40;
- sei_data[9] = 0;
-
- memcpy(sei_data + 10, side_data->data, side_data->size);
-
- sei_data[side_data->size+10] = 255;
+ init_put_bits(&pb, sei_data, *sei_size);
+ put_bits(&pb, 2, m); // num_clock_ts
+
+ for (int j = 1; j <= m; j++) {
+ uint32_t tcsmpte = tc[j];
+ 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 && !0; // 1-bit drop if not arbitrary bit
+
+ /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
+ if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
+ unsigned pc;
+ ff *= 2;
+ if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
+ pc = !!(tcsmpte & 1 << 7);
+ else
+ pc = !!(tcsmpte & 1 << 23);
+ ff = (ff + pc) & 0x7f;
+ }
+
+ put_bits(&pb, 1, 1); // clock_timestamp_flag
+ put_bits(&pb, 1, 1); // units_field_based_flag
+ put_bits(&pb, 5, 0); // counting_type
+ put_bits(&pb, 1, 1); // full_timestamp_flag
+ put_bits(&pb, 1, 0); // discontinuity_flag
+ put_bits(&pb, 1, drop);
+ put_bits(&pb, 9, ff);
+ put_bits(&pb, 6, ss);
+ put_bits(&pb, 6, mm);
+ put_bits(&pb, 5, hh);
+ put_bits(&pb, 5, 0);
+ }
+ flush_put_bits(&pb);