What is causing the "Invalid argument" error when using '@ffprobe-installer/ffprobe'?

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

Kris Niles : Howdy team! I’m trying to upgrade the below step from a v1 to a v2 workflow, and struggling a bit - Not sure how to import ffmpeg in the same way as it is below. Any tips on converting this to a v2 workflow? Thanks in advance!

const fs = require("fs");
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const { promisify } = require("util");
const exec = promisify(require('child_process').exec);
const filePath = params.filePath;
const fileName = params.fileName;
const startTime = params.startTime;
const duration = params.duration;  

const clip = await exec(`${ffmpegPath} -y -i ${filePath} -ss ${startTime} -map 0:a -acodec copy -t ${duration} /tmp/clip-${fileName}`, {timeout: 5000});

return clip

Dylan Pierce : Hi , we recommend switching to ESM import statements instead of the CommonJS require statements.

Kris Niles : Awesome! I think I can manage that transition - but where I’m getting stuck is that I had been using

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;

How do I convert that to using import?

Kris Niles : Or, maybe more specifically, should I change the way I’m using exec?

Kris Niles : - I think you helped me write that v1 code step above, way back in the day. I know that ffmpeg is not easy to work with. I’m not sure how to convert this:

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;

to use the ESM import format.

Any clues would be greatly appreciated!

Dylan Sather (Pipedream) : technically you can just:

import { path } from '@ffmpeg-installer/ffmpeg'

I don’t believe ESM supports renaming destructured imports but if you want to keep the ffmpegPath variable name for readability, you can also do:

import ffmpeg from '@ffmpeg-installer/ffmpeg'

export default defineComponent({
  async run({ steps, $ }) {
    const { path: ffmpegPath } = ffmpeg
    console.log(ffmpegPath)
  },
})

Kris Niles : Thank you Dylan! I’m not sure if I need the path, etc - but here’s the simplest version, and it’s giving me “Invalid argument” (I know the ffprobe command works, it just seems like it’s not able to find ffprobe?) - any thoughts on what I’m doing wrong? Sorry, I’m kinda lost here!

import ffprobe from "@ffprobe-installer/ffprobe"
import exec from "exec"

export default defineComponent({
  async run({ steps, $ }) {
  
  const filePath = 'my-file.mp3'

  chapters = await exec(`${ffprobe} -i ${filePath} -print_format json -show_chapters`);

  return chapters

}})

Dylan Sather (Pipedream) : Could you show me the full error / stack trace that you’re seeing?

Kris Niles : Error
invalid arguments
DETAILS

    at global.exec (/tmp/__pdg__/dist/code/0ebe76d8330310d32a6a405f0942504f51a3f10d00fb61bde755254a1ae0568c/node_modules/.pnpm/exec@0.2.1/node_modules/exec/exec.js:17:11)
    at null.deprecated (internal/util.js:118:15)
    at Object.run (file:///tmp/__pdg__/dist/code/0ebe76d8330310d32a6a405f0942504f51a3f10d00fb61bde755254a1ae0568c/component.mjs:9:18)
    at global.executeComponent (/var/task/launch_worker.js:146:53)
    at MessagePort.messageHandler (/var/task/launch_worker.js:618:28)

Kris Niles : AH CRAP - one min… the error might be in the filePath

Kris Niles : actually, nevermind… fixed the filePath, and still getting the same invalid arguments error.

Kris Niles : Hrm. I might just have to keep using the v1 version… I’m a little out of my element here. :pensive:

Giao Phan : It looks like that exec package you are using is deprecated: https://www.npmjs.com/package/exec

Giao Phan : This one has a promise interface if you don’t want to use the standard nodejs one: https://www.npmjs.com/package/execa

Kris Niles : Hey there - Finally getting back to revisiting this! I’ve started using the execa package as recommended, which seems to be working fine – however, I am getting an ACTIVE HANDLE error when running it, and the exec command isn’t finishing. All my googling hasn’t been helping, so I’m kinda stuck! :unamused:

Any pointers on how to ensure that the the exec process finishes before the step ends would be greatly appreciated… I don’t know what else to add on top.

I’ve created a single workflow step here with my code: https://pipedream.com/@krisniles/ffmpeg-test-p_ZJClKyO/build and opened it up for Support to access, so that you can see it. I also attached the step code here, if that’s easier. It’s a self-contained step, so you don’t need to pass anything to it.

Any pointers would be greatly appreciated!

Giao Phan : I think you need to split those ffcomand into an argument array, or conversely add the ffmpeg path to the ffcommand. My other suggestion is to check ‘stderr’ as well, maybe ffmpeg is logging some errors but exiting with a 0 return code.

Kris Niles : - thanks for those clues. I’m struggling how to figure out how to split them into an arry… any tips on how to do that? My googling has failed me. But I did add a return to the ffmpeg command, and I get these results. Seem to be showing that the process didn’t complete. Kinda helpful, but still not seeing any errors. :thinking_face:

Kris Niles : I also removed the stdout pipe, and I am now getting an error, and seeing it in the logs. Maybe a clude is the “error splitting the argument list”… I can’t quite figure out what that means.

Unrecognized option 'i /tmp/973bc742.mp3 -ss 50 -y -map 0:a -acodec copy -hide_banner -t 30 /tmp/clip-973bc742.mp3'. Error splitting the argument list: Option not found

Giao Phan : try ffcommand = ffcommand.split(" ")

Kris Niles : Hrm! I’m now getting the below. Looks like it is splitting the string and inserting a comma between each argument:

Unrecognized option 'i,/tmp/973bc742.mp3,-ss,50,-y,-map,0:a,-acodec,copy,-hide_banner,-t,30,/tmp/clip-973bc742.mp3'. Error splitting the argument list: Option not found