gpt4 book ai didi

javascript - 将时间码转换为秒

转载 作者:行者123 更新时间:2023-12-03 09:34:17 24 4
gpt4 key购买 nike

我在使用 JavaScript 将时间码更改为帧时遇到问题。以 30 fps 运行,我们得到

"00:00:01:00" = 30 frames

到目前为止一切都很好,只有我检查它转换成这样的秒数:

enter image description here

首先不知道发生了什么?!有人指出我用的是\f 而不是\nf。

其次返回的帧不正确。1 分钟应该是 1800 秒而不是 1800000

如果你能告诉我那是不是安卡,我会加分。

// set the frame rate or Frame Rat as we like to call him
var frameRat = 30 // fps
var numOfFrames = 60 // animation frame count
var animTime = "00:01:00:00" // time code

var a = convertTimeToFrames(animTime, frameRat);
var result = animTime + " at " + frameRat + " fps\n = " + a + " frames.";
alert(result);



function convertTimeCodeToSeconds(timeString, framerate)
{

var timeArray = timeString.split(":");
var hours = timeArray[0] * 60 * 60;
var minutes = timeArray[1] * 60;
var seconds = timeArray[2];
var frames = timeArray[3]*(1/framerate);
var str = "h:" + hours + "\nm:" + minutes + "\ns:" + seconds + "\f:" + frames;
alert(str)
var totalTime = hours + minutes + seconds + frames;

//alert(timeString + " = " + totalTime)
return totalTime;
}

function convertTimeToFrames(timeString, framerate)
{
var secs = convertTimeCodeToSeconds(timeString, framerate);
return secs * framerate;
}

最佳答案

您正在数字和字符之间进行运算。拆分后将所有值转换为数字,如下所示:

// set the frame rate or Frame Rat as we like to call him
var frameRat = 30 // fps
var numOfFrames = 60 // animation frame count
var animTime = "00:01:00:00" // time code

var a = convertTimeToFrames(animTime, frameRat);
var result = animTime + " at " + frameRat + " fps\n = " + a + " frames.";
alert(result);



function convertTimeCodeToSeconds(timeString, framerate)
{

var timeArray = timeString.split(":");
var hours = parseInt(timeArray[0]) * 60 * 60;
var minutes = parseInt(timeArray[1]) * 60;
var seconds = parseInt(timeArray[2]);
var frames = parseInt(timeArray[3])*(1/framerate);
var str = "h:" + hours + "\nm:" + minutes + "\ns:" + seconds + "\nf:" + frames;
alert(str)
var totalTime = hours + minutes + seconds + frames;

//alert(timeString + " = " + totalTime)
return totalTime;
}

function convertTimeToFrames(timeString, framerate)
{
var secs = convertTimeCodeToSeconds(timeString, framerate);
return secs * framerate;
}

关于javascript - 将时间码转换为秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31385418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com