How to Troubleshoot Timeout Error in Fluent-FFMPEG While Trimming MP3 or M4A Files?

This topic was automatically generated from Slack. You can find the original thread here.

Howdy! I am struggling with getting ffmpeg running. My goal is to simply trim an .mp3 or .m4a file that has been downloaded to /tmp. Problem is, when running the below step, I get a timeout error. I’m using fluent-ffmpeg, which seems to all be working fine (but don’t technically need).

• Any tips on how to troubleshoot a timeout error? What can I add to this code to help me understand where it is getting hung up?
• Can someone point me to a working pipedream ffmpeg code snippet that I can copy / modify?
• Any simpler ways to trim .m4a files?
Thanks!

import ffmpeg from '@ffmpeg-installer/ffmpeg';
import fluent from 'fluent-ffmpeg';
import fs from 'fs';
import { promisify } from 'util';

export default defineComponent({
  props: {
    fileName: { label: 'File Name', type: 'string' },
    filePath: { label: 'File Path', type: 'string' },
    fileExt: { label: 'File Extension', type: 'string' },
    shareUrl: { label: 'Share URL', type: 'string' },
    startSeconds: { label: 'Start Seconds', type: 'string' },
    endSeconds: { label: 'End Seconds', type: 'string' }
   },
  async run({ steps, $ }) {
    
    const target = `/tmp/clip-${this.fileName}`
    
    const command = fluent(this.filePath)
      .setFfmpegPath(ffmpeg.path)
      .setStartTime(this.startSeconds)
      .setDuration(this.endSeconds - this.startSeconds)
      .output(target);

    const runPromise = promisify(command.run).bind(command);
    await runPromise();

    console.log(await fs.promises.readdir("/tmp"))
    $.export('clippedFilePath', target)
  }
})

here’s how we use ffmpeg in the Create Transcription OpenAI action, if it helps: https://github.com/PipedreamHQ/pipedream/blob/master/components/openai/actions/create-transcription/create-transcription.mjs

Any logs you print / data you export before the timeout should show up in the test — we try to collect everything we can and show you the partial execution.

If you’re not seeing the partial logs, it may be that you’re hitting 100% of the available CPU on the worker. In that case, try to increase the memory of your workflow and you’ll get a proportional increase in vCPU, and that might help

thank you kindly!! Looking… :+1::skin-tone-3:

Sweet. I was able to look at that step, and copy relevant bits to get the below! It is working great (hasn’t failed yet) – however it does return a warning that “Code was still running when the step ended.“. I assume that’s a false positive?

import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
import { exec } from "child_process";
import { promisify } from "util";
import fs from 'fs'

export default defineComponent({
  props: {
    fileName: { label: 'File Name', type: 'string' },
    filePath: { label: 'File Path', type: 'string' },
    fileExt: { label: 'File Extension', type: 'string' },
   },
  async run({ steps, $ }) {
    const execAsync = promisify(exec);
    const ffmpegPath = ffmpegInstaller.path
    const startTime = 60
    const duration = 60

    const clipFile = `${ffmpegPath} -y -i "${this.filePath}" -ss ${startTime} -map 0:a -acodec copy -t ${duration} "/tmp/clip-${this.fileName}"`

	await execAsync(clipFile)  
    
    $.export("clippedFile", `/tmp/clip-${this.fileName}`)
  },
})

Code was still running when the step ended is usually a sign that there’s some async thing without an await.

Although from the code above… it seems fine. :thinking_face:

Yes probably a false positive