diff mbox series

[FFmpeg-devel,v2,2/2] avdevice/decklink_dec: export timecode with s12m side data

Message ID 1592663151-24180-2-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2,1/2] API: add AV_PKT_DATA_S12M_TIMECODE to AVPacketSideDataType
Related show

Checks

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

Commit Message

Limin Wang June 20, 2020, 2:25 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavdevice/decklink_dec.cpp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 82106aa..c8064ae 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -41,6 +41,7 @@  extern "C" {
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/time.h"
+#include "libavutil/timecode.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/reverse.h"
 #include "avdevice.h"
@@ -778,6 +779,21 @@  HRESULT decklink_input_callback::VideoInputFrameArrived(
                         AVDictionary* metadata_dict = NULL;
                         int metadata_len;
                         uint8_t* packed_metadata;
+                        AVTimecode tcr;
+                        uint32_t tc_data;
+                        uint8_t *sd;
+                        int size = sizeof(uint32_t) * 4;
+
+                        if (av_timecode_init_from_string(&tcr, ctx->video_st->r_frame_rate, tc, ctx) >= 0) {
+                            if ((tc_data = av_timecode_get_smpte_from_framenum(&tcr, 0)) > 0) {
+                                sd = av_packet_new_side_data(&pkt, AV_PKT_DATA_S12M_TIMECODE, size);
+                                if (sd) {
+                                    AV_WL32(sd, 1); // one TC ;
+                                    AV_WL32(sd + 4, tc_data); // TC;
+                                }
+                            }
+                        }
+
                         if (av_dict_set(&metadata_dict, "timecode", tc, AV_DICT_DONT_STRDUP_VAL) >= 0) {
                             packed_metadata = av_packet_pack_dictionary(metadata_dict, &metadata_len);
                             av_dict_free(&metadata_dict);