I’m having some issues parsing audio files in Pipedream. I’ve tried a few packages, including music-metadata, jsmediatags, ffmpeg… The code below executes but the metadata is very limited - the file isn’t parsing basically. What I’m trying to do here is log to the console all metadata in the file header - Any suggestions?
import { readFile } from "fs/promises";
import { exec } from "child_process";
import util from "util";
import ffmpeg from "ffmpeg-static";
import ffprobeStatic from "ffprobe-static";
const execAsync = util.promisify(exec);
const ffprobePath = ffprobeStatic.path;
export default {
async run({ steps, $ }) {
const filePath = steps.download_file_to_tmp.$return_value[1];
console.log(`File path: ${filePath}`);
async function parseAudioFile() {
try {
// Execute ffprobe command to get metadata
const { stdout } = await execAsync(
`"${ffprobePath}" -v quiet -print_format json -show_format -show_streams "${filePath}"`
);
// Parse the JSON output
const metadata = JSON.parse(stdout);
// Log the entire metadata object to the console
console.log("Metadata:", metadata);
} catch (error) {
console.error("Error while parsing the audio file:", error);
}
}
// Call the function to parse the audio file
await parseAudioFile();
},
}
;