Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (35)
Tags (387)
master
release/6.1
release/6.0
release/5.1
release/5.0
release/4.4
release/2.8
release/3.4
release/4.1
release/4.0
release/4.2
release/4.3
release/3.2
release/3.3
release/3.0
release/3.1
release/2.4
release/2.7
release/2.6
release/2.5
n6.1.1
n6.2-dev
n6.1
n6.0.1
n5.1.4
n2.8.22
n3.4.13
n4.1.11
n4.2.9
n4.3.6
n4.4.4
n5.0.3
n5.1.3
n6.1-dev
n6.0
n5.0.2
n2.8.21
n3.2.19
n3.4.12
n4.1.10
master
Branches (35)
Tags (387)
master
release/6.1
release/6.0
release/5.1
release/5.0
release/4.4
release/2.8
release/3.4
release/4.1
release/4.0
release/4.2
release/4.3
release/3.2
release/3.3
release/3.0
release/3.1
release/2.4
release/2.7
release/2.6
release/2.5
n6.1.1
n6.2-dev
n6.1
n6.0.1
n5.1.4
n2.8.22
n3.4.13
n4.1.11
n4.2.9
n4.3.6
n4.4.4
n5.0.3
n5.1.3
n6.1-dev
n6.0
n5.0.2
n2.8.21
n3.2.19
n3.4.12
n4.1.10
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (35)
Tags (387)
master
release/6.1
release/6.0
release/5.1
release/5.0
release/4.4
release/2.8
release/3.4
release/4.1
release/4.0
release/4.2
release/4.3
release/3.2
release/3.3
release/3.0
release/3.1
release/2.4
release/2.7
release/2.6
release/2.5
n6.1.1
n6.2-dev
n6.1
n6.0.1
n5.1.4
n2.8.22
n3.4.13
n4.1.11
n4.2.9
n4.3.6
n4.4.4
n5.0.3
n5.1.3
n6.1-dev
n6.0
n5.0.2
n2.8.21
n3.2.19
n3.4.12
n4.1.10
FFmpeg
/
libavutil
/
timecode.c
FFmpeg
/
libavutil
/
timecode.c
timecode.c 8.09 KB
Copy Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
/*
* Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
* Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Timecode helpers
* @see https://en.wikipedia.org/wiki/SMPTE_time_code
* @see http://www.dropframetimecode.org
*/
#include <stdio.h>
#include "common.h"
#include "timecode.h"
#include "log.h"
#include "error.h"
int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
{
/* only works for multiples of NTSC 29.97 */
int drop_frames = 0;
int d, m, frames_per_10mins;
if (fps && fps % 30 == 0) {
drop_frames = fps / 30 * 2;
frames_per_10mins = fps / 30 * 17982;
} else
return framenum;
d = framenum / frames_per_10mins;
m = framenum % frames_per_10mins;
return framenum + 9U * drop_frames * d + drop_frames * ((m - drop_frames) / (frames_per_10mins / 10));
}
uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum)
{
unsigned fps = tc->fps;
int drop = !!(tc->flags & AV_TIMECODE_FLAG_DROPFRAME);
int hh, mm, ss, ff;
framenum += tc->start;
if (drop)
framenum = av_timecode_adjust_ntsc_framenum2(framenum, tc->fps);
ff = framenum % fps;
ss = framenum / fps % 60;
mm = framenum / (fps*60) % 60;
hh = framenum / (fps*3600) % 24;
return av_timecode_get_smpte(tc->rate, drop, hh, mm, ss, ff);
}
uint32_t av_timecode_get_smpte(AVRational rate, int drop, int hh, int mm, int ss, int ff)
{
uint32_t tc = 0;
/* For SMPTE 12-M timecodes, frame count is a special case if > 30 FPS.
See SMPTE ST 12-1:2014 Sec 12.1 for more info. */
if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
if (ff % 2 == 1) {
if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
tc |= (1 << 7);
else
tc |= (1 << 23);
}
ff /= 2;
}
hh = hh % 24;
mm = av_clip(mm, 0, 59);
ss = av_clip(ss, 0, 59);
ff = ff % 40;
tc |= drop << 30;
tc |= (ff / 10) << 28;
tc |= (ff % 10) << 24;
tc |= (ss / 10) << 20;
tc |= (ss % 10) << 16;
tc |= (mm / 10) << 12;
tc |= (mm % 10) << 8;
tc |= (hh / 10) << 4;
tc |= (hh % 10);
return tc;
}
char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
{
int fps = tc->fps;
int drop = tc->flags & AV_TIMECODE_FLAG_DROPFRAME;
int hh, mm, ss, ff, ff_len, neg = 0;
framenum += tc->start;
if (drop)
framenum = av_timecode_adjust_ntsc_framenum2(framenum, fps);
if (framenum < 0) {
framenum = -framenum;
neg = tc->flags & AV_TIMECODE_FLAG_ALLOWNEGATIVE;
}
ff = framenum % fps;
ss = framenum / fps % 60;
mm = framenum / (fps*60LL) % 60;
hh = framenum / (fps*3600LL);
if (tc->flags & AV_TIMECODE_FLAG_24HOURSMAX)
hh = hh % 24;
ff_len = fps > 10000 ? 5 : fps > 1000 ? 4 : fps > 100 ? 3 : fps > 10 ? 2 : 1;
snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%0*d",
neg ? "-" : "",
hh, mm, ss, drop ? ';' : ':', ff_len, ff);
return buf;
}
static unsigned bcd2uint(uint8_t bcd)
{
unsigned low = bcd & 0xf;
unsigned high = bcd >> 4;
if (low > 9 || high > 9)
return 0;
return low + 10*high;
}
char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
{
unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
unsigned drop = tcsmpte & 1<<30 && !prevent_df; // 1-bit drop if not arbitrary bit
if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
ff <<= 1;
if (!skip_field) {
if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
ff += !!(tcsmpte & 1 << 7);
else
ff += !!(tcsmpte & 1 << 23);
}
}
snprintf(buf, AV_TIMECODE_STR_SIZE, "%02u:%02u:%02u%c%02u",
hh, mm, ss, drop ? ';' : ':', ff);
return buf;
}
char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
{
return av_timecode_make_smpte_tc_string2(buf, (AVRational){30, 1}, tcsmpte, prevent_df, 1);
}
char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit)
{
snprintf(buf, AV_TIMECODE_STR_SIZE,
"%02"PRIu32":%02"PRIu32":%02"PRIu32"%c%02"PRIu32,
tc25bit>>19 & 0x1f, // 5-bit hours
tc25bit>>13 & 0x3f, // 6-bit minutes
tc25bit>>6 & 0x3f, // 6-bit seconds
tc25bit & 1<<24 ? ';' : ':', // 1-bit drop flag
tc25bit & 0x3f); // 6-bit frames
return buf;
}
static int check_fps(int fps)
{
int i;
static const int supported_fps[] = {
24, 25, 30, 48, 50, 60, 100, 120, 150,
};
for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++)
if (fps == supported_fps[i])
return 0;
return -1;
}
static int check_timecode(void *log_ctx, AVTimecode *tc)
{
if ((int)tc->fps <= 0) {
av_log(log_ctx, AV_LOG_ERROR, "Valid timecode frame rate must be specified. Minimum value is 1\n");
return AVERROR(EINVAL);
}
if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps % 30 != 0) {
av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with multiples of 30000/1001 FPS\n");
return AVERROR(EINVAL);
}
if (check_fps(tc->fps) < 0) {
av_log(log_ctx, AV_LOG_WARNING, "Using non-standard frame rate %d/%d\n",
tc->rate.num, tc->rate.den);
}
return 0;
}
static int fps_from_frame_rate(AVRational rate)
{
if (!rate.den || !rate.num)
return -1;
return (rate.num + rate.den/2) / rate.den;
}
int av_timecode_check_frame_rate(AVRational rate)
{
return check_fps(fps_from_frame_rate(rate));
}
int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx)
{
memset(tc, 0, sizeof(*tc));
tc->start = frame_start;
tc->flags = flags;
tc->rate = rate;
tc->fps = fps_from_frame_rate(rate);
return check_timecode(log_ctx, tc);
}
int av_timecode_init_from_components(AVTimecode *tc, AVRational rate, int flags, int hh, int mm, int ss, int ff, void *log_ctx)
{
int ret;
memset(tc, 0, sizeof(*tc));
tc->flags = flags;
tc->rate = rate;
tc->fps = fps_from_frame_rate(rate);
ret = check_timecode(log_ctx, tc);
if (ret < 0)
return ret;
tc->start = (hh*3600 + mm*60 + ss) * tc->fps + ff;
if (tc->flags & AV_TIMECODE_FLAG_DROPFRAME) { /* adjust frame number */
int tmins = 60*hh + mm;
tc->start -= (tc->fps / 30 * 2) * (tmins - tmins/10);
}
return 0;
}
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
{
char c;
int hh, mm, ss, ff, flags;
if (sscanf(str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
av_log(log_ctx, AV_LOG_ERROR, "Unable to parse timecode, "
"syntax: hh:mm:ss[:;.]ff\n");
return AVERROR_INVALIDDATA;
}
flags = c != ':' ? AV_TIMECODE_FLAG_DROPFRAME : 0; // drop if ';', '.', ...
return av_timecode_init_from_components(tc, rate, flags, hh, mm, ss, ff, log_ctx);
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

fork from https://github.com/FFmpeg/FFmpeg.git
No labels
GPL-2.0
Use GPL-2.0
, LGPL-2.1
Use LGPL-2.1
, LGPL-3.0
Use LGPL-3.0
, GPL-3.0
Use GPL-3.0
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/source-code-sync/FFmpeg.git
git@gitee.com:source-code-sync/FFmpeg.git
source-code-sync
FFmpeg
FFmpeg
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /