用帧计算两个音频持续时间 [英] Calculate two audio duration with frame

查看:64
本文介绍了用帧计算两个音频持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困住了,我需要一个小的逻辑.

I am stuck, I need a small logic.

我有两个音频时长

x = "00:00:07:18"
y = "00:00:06:00"        H : M: S: F  
Answer should be x + y = 00:00:13:18 

H =小时S =秒M =分钟F =帧

H=hours S= seconds M=minutes F=frame

我的问题是

if x = "00:00:03:14"
   y = "00:00:13:18"

answer should be x + y = **00:00:17:02**

如果帧大于30,则应增加1秒钟.

If the frame is greater than 30 it should increase 1 in second.

我正在使用电源外壳.我该如何确定同时计算这两者的逻辑?

I am using power shell. How can I determine the logic to calculate both of this?

推荐答案

计算前3个部分( hour:minute:second ),我们可以将其卸载到 [timespan] 类型,那么我们只需要担心携带多余的帧:

Calculation of the first 3 parts (hour:minute:second), we can offload to the [timespan] type, then all we need to worry about is carrying excess frames over:

# Simple helper function to turn our input strings into a [timespan] + frame count
function Parse-FrameDuration
{
    param(
        [string]$Duration
    )

    $hour,$minute,$second,$frame = ($Duration -split ':') -as [int[]]

    [PSCustomObject]@{
        Time = New-TimeSpan -Hours $hour -Minutes $minute -Seconds $second
        Frame = $frame
    }
}

# function to do the actual calculation
function Add-Frame
{
    param(
        [string]$Base,
        [string]$Offset
    )

    # Parse our two timestamps
    $a = Parse-FrameDuration $Base
    $b = Parse-FrameDuration $Offset

    # Calculate frames % frame rate, remember to carry any excess seconds
    $frames = 0
    $carry = [math]::DivRem($a.Frame + $b.Frame , 30, [ref]$frames)

    # Calculate time difference, add any extra second carried from frame count
    $new = ($a.Time + $b.Time).Add($(New-TimeSpan -Seconds $carry))

    # Stitch output string together from new timespan + remaining frames
    return "{0:hh\:mm\:ss}:{1:00}" -f $new,$frames
}

现在我们可以做到:

PS C:\> Add-Frame -Base 00:00:03:14 -Offset 00:00:13:18
00:00:17:02

这篇关于用帧计算两个音频持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆