From patchwork Tue Jul 14 23:30:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 21026 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 84F1044585D for ; Wed, 15 Jul 2020 02:36:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6CAC268B2B3; Wed, 15 Jul 2020 02:36:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1614E68B205 for ; Wed, 15 Jul 2020 02:36:30 +0300 (EEST) Received: by mail-pg1-f196.google.com with SMTP id m22so148968pgv.9 for ; Tue, 14 Jul 2020 16:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C3OBCwkU3YBUhM3til2CjVPeyZfvn+qafblxPf+mOXw=; b=NUt2ydZPBdA8J7GX36T2vdl/t4Ho4gk3mR3aBV49//ZX6rqmN3lkKxOH1bx6gR5Z8/ uXsoKSXCqrEJhWXJU1cggw58jsFGZ4ZPJ75SVGE/Z7nNfAImk4urF5CHKc4gtsa/Hm4k vZvJyowmufpyoGvKiJ+8pcMc+qG0RZjvMUdo1tADpgMPPSpgFV89esccjiLRTdchSWeA MEPaw+BsRQ3zKXJDC4J+tA5+XXvNyuuqvLdtQZF8ovnkt/LHahCxWyC5Q3ohLCdIkXRr hXvThTvx6eFcRfS7hRLFO+kWySdboPO5gBOM9pnxkxs/PWojuQdKolv8BgM7deFbMWhE DAoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C3OBCwkU3YBUhM3til2CjVPeyZfvn+qafblxPf+mOXw=; b=M0sXGTm2AJ7ux8/Oa/Pah4m8+vE2cMGJgEbMIpbYkIPgGQE/DQe9TGK+edPrJTA0eQ 7w15dSr9m7meBX0nl29oCC6tRnz9tSbS0zH3cOC5a4TFz5UrGJIAapXV8UEJo5S3NOTG 43Emm3j/zBS6tph3sJRmeHQyjiBG27zSx+omAx5F5Xo9f2WKw9UpxVplQnk2iWGyYJYj R2BLC3yr+ZD+EqBSio25rrY7A5YkSfk58PA9wnpsbib+533RUCwEJ8gYBRM57pfv/hqH htK+qEOwwHL9pkF54Ezu6CU5RfJ5RbCRGiJIrX7NHb9W0gDD8eyPRvC9J9jV50TCiExV jrIA== X-Gm-Message-State: AOAM532vyF+OXNeTf/qzRMlMHJffzESQUaMLNFJb4QE1G4NM/WIaw82M 6Qa2UQpf+X87wX0g4D6puYOkBqiX X-Google-Smtp-Source: ABdhPJyBmQKCRxMP1/KW3qUobtrztB3PcHnyqWDXmT9LF6/XGjdPJvmQpKVhki93cQiQugiiuGtnYQ== X-Received: by 2002:a63:2d44:: with SMTP id t65mr5417091pgt.257.1594769421296; Tue, 14 Jul 2020 16:30:21 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id y198sm212954pfg.116.2020.07.14.16.30.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Jul 2020 16:30:20 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Jul 2020 07:30:01 +0800 Message-Id: <1594769402-22526-5-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594769402-22526-1-git-send-email-lance.lmwang@gmail.com> References: <1594769402-22526-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 5/6] avformat/movenc: use the stream s12m side data for tmcd track if available X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang 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 --- libavformat/movenc.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) 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++;