From patchwork Fri Jun 19 14:35:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 20503 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 05AA944B608 for ; Fri, 19 Jun 2020 17:36:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF2C168B70F; Fri, 19 Jun 2020 17:36:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB6FA68B6EF for ; Fri, 19 Jun 2020 17:35:59 +0300 (EEST) Received: by mail-pf1-f195.google.com with SMTP id j1so4515608pfe.4 for ; Fri, 19 Jun 2020 07:35:59 -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=h5YHTOKtfxIhRsT1OAhcBlpm10EgdZUDdiPJpTjfVmU=; b=EkUdn7fdd6bOB6gVTYGYsZ19sViFASjd7FOYDRn/FsSjqEshPFezrosZ7TtSb89JNP oqqfcP++p5MjupQGf2IlX6KXKDacRtOIlmK//8zZf/UBdKjYxIATmnHJER7VObUWSuqi SdKKZTZqWSLr8c3bzvyQd0AE9FlS+o7B7iu0FbSsfakE3v6wu0BEUxSczJRQOQdx3Q+A HM0hxEgLikv2dcu3ZNfPGQN4u14LcVbdGbl4tTNpAS5OCrfYTuJbbjR+8lycOWi4kx5A glIx0gvnGyh+0Yjh0W5hrcEDu8KT/EnfkhrpzspphXfsBvHlNCUhQ/07A1BcVblkWSxz 983Q== 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=h5YHTOKtfxIhRsT1OAhcBlpm10EgdZUDdiPJpTjfVmU=; b=NqzjHy31442KDDcnS4XUae3U0sZjQ1v9q1bZMdtxhZlY5o0XXLWAOSBXDj645sfly6 FpdRQ1vnWWaTwwwHGfkavQh3nv3RtXbEYFgFsEeE+lz40R4bHjgv6WYsEF4fzwGa1qMN axYjsra8mly1qNbqwnfcscFm6lRYJo04s/kPVW1+fhbnfZB1J+SeQxwDtRmD8S5zr1+8 MmaxMRLnf3/x0eSnXrxzxVx40t9LOgwmFaTeAS7/J6//GsRKuobV2Zx6+1q4dbC53D9S qKN9abkMcd4XMxtK4nzGv757x0hD2WJPUXC9k+B3I8c7OcRZsZX6wP2XVQaMR3TrVaB5 8CAQ== X-Gm-Message-State: AOAM533RsdedGgDavel/pgogQG+rxxRpezLmfLPUn4bpNjVpN4HB7NNC 0Kr4LVQIm9v/yEgk3LEsWRetzkTE X-Google-Smtp-Source: ABdhPJyyBjzAvKEDx0AXmHYDFV7mO9Rw3sSARy7JsohRXVkuQsXvALviRR9Ken8nedo7ybXkRvy2CA== X-Received: by 2002:a63:df48:: with SMTP id h8mr3278171pgj.411.1592577357892; Fri, 19 Jun 2020 07:35:57 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id s23sm5286912pju.35.2020.06.19.07.35.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jun 2020 07:35:57 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Jun 2020 22:35:33 +0800 Message-Id: <1592577334-19049-3-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1592577334-19049-1-git-send-email-lance.lmwang@gmail.com> References: <1592577334-19049-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/4] avutil/timecode: add function av_timecode_get_smpte_by_tc_string() 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 Signed-off-by: Limin Wang --- libavutil/timecode.c | 26 ++++++++++++++++++++++++++ libavutil/timecode.h | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index 60077ba..7a7ed1d 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -81,6 +81,32 @@ uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum) (hh % 10); // units of hours } +uint32_t av_timecode_get_smpte_by_tc_string(const char *buf) +{ + char c; + int hh, mm, ss, ff, drop; + + if (sscanf(buf, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) { + return AVERROR_INVALIDDATA; + } + drop = c != ':' ? AV_TIMECODE_FLAG_DROPFRAME : 0; // drop if ';', '.', ... + + return 0 << 31 | // color frame flag (0: unsync mode, 1: sync mode) + drop << 30 | // drop frame flag (0: non drop, 1: drop) + (ff / 10) << 28 | // tens of frames + (ff % 10) << 24 | // units of frames + 0 << 23 | // PC (NTSC) or BGF0 (PAL) + (ss / 10) << 20 | // tens of seconds + (ss % 10) << 16 | // units of seconds + 0 << 15 | // BGF0 (NTSC) or BGF2 (PAL) + (mm / 10) << 12 | // tens of minutes + (mm % 10) << 8 | // units of minutes + 0 << 7 | // BGF2 (NTSC) or PC (PAL) + 0 << 6 | // BGF1 + (hh / 10) << 4 | // tens of hours + (hh % 10); // units of hours +} + char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum) { int fps = tc->fps; diff --git a/libavutil/timecode.h b/libavutil/timecode.h index 37c1361..7bb4b78 100644 --- a/libavutil/timecode.h +++ b/libavutil/timecode.h @@ -71,6 +71,15 @@ int av_timecode_adjust_ntsc_framenum2(int framenum, int fps); uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum); /** + * Convert TC string to SMPTE 12M binary representation. + * + * @param buf TC string + * @return the SMPTE binary representation, or AVERROR otherwise + * + */ +uint32_t av_timecode_get_smpte_by_tc_string(const char *buf); + +/** * Load timecode string in buf. * * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long