avcodec/hevcdec: create AVFrame side data from HEVC timecodes like H.264
authorLimin Wang <lance.lmwang@gmail.com>
Wed, 24 Jun 2020 06:29:32 +0000 (14:29 +0800)
committerLimin Wang <lance.lmwang@gmail.com>
Sun, 28 Jun 2020 13:00:52 +0000 (21:00 +0800)
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
libavcodec/hevcdec.c

index b63cba6..e363e68 100644 (file)
@@ -32,6 +32,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/stereo3d.h"
+#include "libavutil/timecode.h"
 
 #include "bswapdsp.h"
 #include "bytestream.h"
@@ -2817,6 +2818,29 @@ static int set_side_data(HEVCContext *s)
     }
     s->sei.unregistered.nb_buf_ref = 0;
 
+    if (s->sei.timecode.present) {
+        uint32_t *tc_sd;
+        AVFrameSideData *tcside = av_frame_new_side_data(out, AV_FRAME_DATA_S12M_TIMECODE,
+                                                         sizeof(uint32_t) * 4);
+        if (!tcside)
+            return AVERROR(ENOMEM);
+
+        tc_sd = (uint32_t*)tcside->data;
+        tc_sd[0] = s->sei.timecode.num_clock_ts;
+
+        for (int i = 0; i < tc_sd[0]; i++) {
+            int drop = s->sei.timecode.cnt_dropped_flag[i];
+            int   hh = s->sei.timecode.hours_value[i];
+            int   mm = s->sei.timecode.minutes_value[i];
+            int   ss = s->sei.timecode.seconds_value[i];
+            int   ff = s->sei.timecode.n_frames[i];
+
+            tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
+        }
+
+        s->sei.timecode.num_clock_ts = 0;
+    }
+
     return 0;
 }