diff mbox series

[FFmpeg-devel,5/6] avformat/movenc: use the stream s12m side data for tmcd track if available

Message ID 1594769402-22526-5-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/6] avcodec: add AV_CODEC_EXPORT_DATA_S12M_TC flag to export S12M timecode
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 July 14, 2020, 11:30 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

 Please test with below command:
 ./ffmpeg -export_side_data s12m_tc -i ../fate-suite/h264/crew_cif_timecode-2.h264 out.mp4

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/movenc.c | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7db2e28..ca2c8a1 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6402,12 +6402,25 @@  static int mov_init(AVFormatContext *s)
         for (i = 0; i < s->nb_streams; i++) {
             AVStream *st = s->streams[i];
             AVDictionaryEntry *t = global_tcr;
+            AVTimecode tc;
+            uint32_t *tc_sd = (uint32_t *)av_stream_get_side_data(st, AV_PKT_DATA_S12M_TIMECODE,
+                                                                  NULL);
+
             if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
                 (t || (t=av_dict_get(st->metadata, "timecode", NULL, 0)))) {
-                AVTimecode tc;
                 ret = mov_check_timecode_track(s, &tc, i, t->value);
                 if (ret >= 0)
                     mov->nb_meta_tmcd++;
+            } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && tc_sd) {
+                char tcbuf[AV_TIMECODE_STR_SIZE];
+                int m = tc_sd[0] & 3;
+                if ( m > 0) {
+                    /* use the first timecode if more than one TC */
+                    av_timecode_make_smpte_tc_string(tcbuf, tc_sd[1], 0);
+                    ret = mov_check_timecode_track(s, &tc, i, tcbuf);
+                    if (ret >= 0)
+                        mov->nb_meta_tmcd++;
+                }
             }
         }
 
@@ -6724,12 +6737,27 @@  static int mov_write_header(AVFormatContext *s)
 
             if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
                 AVTimecode tc;
+                uint32_t *tc_sd = (uint32_t *)av_stream_get_side_data(st, AV_PKT_DATA_S12M_TIMECODE,
+                                                                      NULL);
                 if (!t)
                     t = av_dict_get(st->metadata, "timecode", NULL, 0);
-                if (!t)
-                    continue;
-                if (mov_check_timecode_track(s, &tc, i, t->value) < 0)
+                if (t) {
+                    if (mov_check_timecode_track(s, &tc, i, t->value) < 0)
+                        continue;
+                } else if (tc_sd) {
+                    char tcbuf[AV_TIMECODE_STR_SIZE];
+                    int m = tc_sd[0] & 3;
+                    if ( m < 1)
+                        continue;
+
+                    /* use the first timecode if more than one */
+                    av_timecode_make_smpte_tc_string(tcbuf, tc_sd[1], 0);
+                    ret = mov_check_timecode_track(s, &tc, i, tcbuf);
+                    if (ret < 0)
+                        continue;
+                } else
                     continue;
+
                 if ((ret = mov_create_timecode_track(s, tmcd_track, i, tc)) < 0)
                     return ret;
                 tmcd_track++;