Adobe Premiere中的setInPoint和setOutPoint时的脚本错误?

问题描述 投票:0回答:1

使用时遇到了令人沮丧的砖墙:

projectItem.setInPoint(seconds)
projectItem.setOutPoint(seconds)

…大约50%的时间(源窗口中)的I / O点设置为1帧错误(有时输出2帧)。我觉得我已经尽了一切努力来发现模式,但这似乎完全是随机的。我认为这可能与丢帧,可变帧速率,剪辑与序列不同或其他奇怪因素有关,但是错误发生在简单的恒定帧速率(如25 fps)下。似乎没有韵律或错误原因(尽管同一错误在某些帧上始终出现)。子片段的问题甚至更大,因为脚本环境认为所有子片段都始于第0帧。我已经尝试了所有方法,包括以刻度,秒或帧为单位进行工作,并在它们之间进行转换。没有任何改变。我要完成的工作是在一组剪辑上进行输入/输出,运行脚本以从这些源剪辑中进行较小的剪切,然后将剪辑还原到原始I / O点。除了无法使用此错误将所有剪辑还原到原始I / O点以外,其他大部分工作都可以进行。以下是我编写的测试脚本。它获取当前的I / O位置,进行存储,然后将其设置回相同的剪辑。一半的时间值不一样!啊!这使得无法正确设置片段的I / O。

function framesToSeconds (frames, fps)
{
    return frames / fps;
}

function secondsToFrames (sec, fps)
{
    return sec * fps;
}

/*---------------------------------------------------*/

var projItems = app.project.rootItem.children;
var clip = projItems[2];
var fps = clip.getFootageInterpretation().frameRate;

var setIn = clip.getInPoint().seconds;
var setOut = clip.getOutPoint().seconds;

var inFrame = secondsToFrames (setIn, fps);
var outFrame = secondsToFrames (setOut, fps);

var secIn = framesToSeconds (inFrame, fps);
var secOut = framesToSeconds (outFrame, fps);

clip.setInPoint( secIn );
clip.setOutPoint( secOut );

var setIn = clip.getInPoint().seconds;
var setOut = clip.getOutPoint().seconds;
javascript video editing extendscript adobe-premiere
1个回答
0
投票

我做了更多测试。尽管我不太了解错误的根源,但我相信我已经找到了解决方法。

我测试了2个子弹,每个子弹长10秒,具有不同的帧速率,然后让它们循环运行并设置每个帧的IO点。我检查了每个帧,看看哪些帧返回错误。我发现的是:

test_25fps_1280x720.mov:第211,209,207,205,203,201帧错误

test_29fps_1024x576.mov:第251,244,242,122,121,61帧错误

这些错误不是随机的。每当我尝试在这些帧上设置入点或出点时,总会舍入1帧(在关闭大约50%的帧之前,我错了,实际上不到3%)。

我的最佳猜测是,由于存在涉及大浮点数的计算,因此会存在一些精度误差。我无法确认,也不知道该如何解决。但是我确实发现我可以在设置进出点后对其进行测试,如果不符合预期,我可以通过增加半帧(以秒为单位)的持续时间来重置该点。一个完整的帧只会重复该错误,但是半帧将使Premiere舍入到正确的帧。

这是我的代码的主要部分:

/*---------------------------------------------------*/
function fixAnyFrameErrors (clip, inFrame, outFrame, fps, halfFrame)
/*---------------------------------------------------*/
{
    var inSecSet    = clip.getInPoint().seconds;
    var inFrameSet  = secondsToFrames (inSecSet, fps);
    var outSecSet   = clip.getOutPoint().seconds;
    var outFrameSet = secondsToFrames (outSecSet, fps);

    if ( parseFloat(inFrame) != parseFloat(inFrameSet) ) {
        clip.setInPoint( secIn + halfFrame );
    }

    if ( parseFloat(outFrame) != parseFloat(outFrameSet) ) {
        clip.setOutPoint( secOut + halfFrame );
    }
}

/*---------------------------------------------------*/

var tps = 254016000000; // 2.54016e11 ticks per second (Premiere Pro constant)

var projItems = app.project.rootItem.children;
var clip = projItems[2];
clip.addMetadata();
var fps = clip.getFootageInterpretation().frameRate;
var tpf = clip.videoInPoint.frame_rate;
var frameDuration = tpf / tps; // in seconds
var halfFrame = (frameDuration * 0.5);

var inFrame = 201;
var outFrame = 211;

var secIn  = framesToSeconds (inFrame,  fps);
var secOut = framesToSeconds (outFrame, fps);

clip.setInPoint ( secIn  );
clip.setOutPoint( secOut );

fixAnyFrameErrors (clip, inFrame, outFrame, fps, halfFrame);
© www.soinside.com 2019 - 2024. All rights reserved.