javascript - 从 AWS Lambda 层的 ffmpeg 输出中删除逗号
问题描述
我正在使用 ffmpeg Lambda 层从音频文件中获取持续时间和通道。然后我将这些详细信息输出到变量以便稍后在我的代码中使用?
任何人都可以发现/整理这段代码,因此它只输出实际值,而不是一个以逗号开头的值
const { spawnSync } = require("child_process");
var fs = require('fs');
const https = require('https');
exports.handler = async (event) => {
const source_url = 'https://upload.wikimedia.org/wikipedia/commons/b/b2/Bell-ring.flac';
const target_path = '/tmp/test.flac';
async function downloadFile() {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(target_path);
const request = https.get(source_url, function(response) {
response.pipe(file);
console.log('file_downloaded!');
resolve();
});
});
}
await downloadFile();
const duration = spawnSync(
"/opt/bin/ffprobe",
[
target_path,
"-show_entries",
"stream=duration",
"-select_streams",
"a",
"-of",
"compact=p=0:nk=1",
"-v",
"0"
]
);
const channel = spawnSync(
"/opt/bin/ffprobe",
[
target_path,
"-show_entries",
"stream=channels",
"-select_streams",
"a",
"-of",
"compact=p=0:nk=1",
"-v",
"0"
]
);
var durations = duration.output.toString('utf8');
console.log(durations);
var channels = channel.output.toString('utf8');
console.log(channels);
/*const response = {
statusCode: 200,
//body: JSON.stringify([channel.output.toString('utf8')])
body: 'Complete'
};
return response;*/
};
只是不确定这些逗号值是从哪里来的,我需要这些值作为后面代码中比较函数的数值。
它使用这个简单的 Lambda 层,不需要外部模块
解决方案
推荐阅读
- r - 使用 data.frame 向量的名称作为函数参数的元素
- mysql - Mysql通过合并多列创建新列并显示结果
- python - 如何根据上传文件的类型在 Django 模板中显示视频或图像文件?
- angular - 根据具有反应形式的单选按钮更改形式 - Angular 2+
- ios - 在 iPhone X 系列上处理 Chrome 浏览器中的安全区域
- acumatica - Acumatica 和 SQL 监控和 APM 软件建议
- c# - 如何修复此错误:System.InvalidOperationException:'ConnectionString 属性尚未初始化。'
- javascript - WordPress的priority-menu.js的控制台出现错误
- python - 尝试通过 matplotlib 绘制数据,不断收到“builtins.IndexError:列表索引超出范围”。
- asp.net - 值“AddOrder”无效