繁体   English   中英

如何使用JSFL查找音频剪辑的长度

[英]How to find the length of an audio clip using JSFL

我希望有人可以帮助我。 我遇到需要将音频文件添加到已经开发的FLA文件中的情况。 为此,我必须打开fla文件,创建一个新层,将音频片段拖到该层,将所有层扩展到音频片段的末尾,然后添加一个停止点。

我希望使用JSFL为我做到这一点。 目前,我可以在库中选择一个音频剪辑并运行JSFL脚本。 我将声音剪辑添加到新图层。 它创建另一个图层,并在最后一帧添加停止点。 我还可以扩展所有图层,但要扩展很多框架。 我的问题是我似乎无法弄清楚如何获得声音片段的长度,因此我知道扩展所有层的长度。

任何帮助都会很棒。

谢谢

快速浏览JSFL文档 (pdf链接),您只有几个可用的属性:

Property Description
soundItem.bitRate                   A string that specifies the bit rate of a sound in the library. Available only for the MP3 compression type. 
soundItem.bits                      A string that specifies the bits value for a sound in the library that has ADPCM compression.
soundItem.compressionType           A string that specifies the compression type for a sound in the library. 
soundItem.convertStereoToMono       A Boolean value available only for MP3 and Raw compression types. 
soundItem.fileLastModifiedDate      Read-only; a string containing a hexadecimal number that represents the number of seconds that have elapsed between January 1, 1970, and the modification date of the original file (on disk) at the time the file was imported to the library. 
soundItem.originalCompressionType   Read-only; a string that specifies whether the specified item was imported as an MP3 file.
soundItem.quality                   A string that specifies the playback quality of a sound in the library. Available only for the MP3 compression type. 
soundItem.sampleRate                A string that specifies the sample rate for the audio clip.
soundItem.sourceFileExists          Read-only; a Boolean value that specifies whether the file that was imported to the Library still exists in the location from where it was imported.
soundItem.sourceFileIsCurrent       Read-only; a Boolean value that specifies whether the file modification date of the Library item is the same as the modification date on disk of the file that was imported.
soundItem.sourceFilePath            Read-only; a string, expressed as a file:/// URI, that represents the path and name of the file that was imported into the Library.
soundItem.useImportedMP3Quality     A Boolean value; if true, all other properties are ignored, and the imported MP3 quality is used

目前,我只能想到几个棘手的解决方法...两个版本中的一个:

  • 让导出声音的人也导出与声音同名的.txt,其中包含声音的长度。 您可以使用FLfile加载和读取此文件,然后使用文档的帧速率,计算所需的帧数
  • 与上述方法类似,您可以拨出一个命令行工具,其唯一目的是输出音频文件的长度(使用声音的sourceFilePath属性)或使用现有工具(*)。 您可以使用未记录的FLfile.runCommandLine()调用命令行应用程序。

命令行工具的一些示例是ffmpeg(例如ffmpeg -i yourAudioFile )或MediaInfo 我确定那里还有其他人。 这取决于您需要使用的操作系统以及该工具是否易于安装。 理想情况下,您将使用仅输出持续时间的内容,但是如果您获得更多数据,则应该能够解析输出并获取持续时间。 还要注意,该函数将返回1以成功执行,否则返回0,因此您将需要一个将输出也写入文本文件的命令,您可以使用jsfl读取该文件。

如果音频文件以恒定的比特率编码,则最终可以使用FLfile.getSize()方法获取文件的长度并计算其持续时间。

这是一个jsfl片段,用于计算并显示库中每种声音的帧时长:

var dom = fl.getDocumentDOM();
var lib = dom.library;

var soundsBitRate = 705;//specify here the bitrate of your files in Kbits/s

for (i = 0; i < lib.items.length; i++) {
    if (lib.items[i].itemType == "sound") {
        alert ("Duration of "+ lib.items[i].name + " : " + Math.ceil(FLfile.getSize(lib.items[i].sourceFilePath) / (soundsBitRate/8) / 1000 * dom.frameRate)+ " frames");
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM