diff mbox series

[FFmpeg-devel,v4,5/7] avcodec/hevcdec: create AVFrame side data from HEVC timecodes like H.264

Message ID 1593006200-23911-5-git-send-email-lance.lmwang@gmail.com
State Accepted
Commit 5151f6d2953d75bd26898b2bd51fe095796c07ad
Headers show
Series [FFmpeg-devel,v4,1/7] FATE: add h264 timecode side data test | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Lance Wang June 24, 2020, 1:43 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/hevcdec.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index c9e28f5..3bdec12 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -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"
@@ -2808,6 +2809,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;
 }