shauntarves / livebarn

A Javascript library for fetching videos from the LiveBarn streaming service.
MIT License
6 stars 1 forks source link

ffmpeg Invalid argument #1

Open cosalich opened 3 years ago

cosalich commented 3 years ago

Everything works great right up until ffmpeg gets involved:

Fetching medialist 0
Fetching medialist 1
Fetching medialist 2
Downloading video chunklists
Downloading video chunklists
Downloading video chunklists
Downloading video chunks
Downloading video chunks
Downloading video chunks
Processing 482 chunks
Chunking 482 files into batches of 60 for intermediate merge
Starting merge 1
Merging 60 chunks to file D:\Programs\livebarn-1.0.0\tmp\<<redacted>>5__896b59.ts
(node:9308) UnhandledPromiseRejectionWarning: Error: An error occurred merging files: ffmpeg exited with code 1: D:\Programs\livebarn-1.0.0\tmp\<<redacted>>5__896b59.ts: Invalid argument

    at FfmpegCommand.<anonymous> (D:\Programs\livebarn-1.0.0\lib\livebarn.js:67:18)
    at FfmpegCommand.emit (events.js:400:28)
    at emitEnd (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:424:16)
    at endCB (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:544:13)
    at handleExit (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:170:11)
    at ChildProcess.<anonymous> (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:182:11)
    at ChildProcess.emit (events.js:400:28)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9308) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9308) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Running via NodeJS. ffmpeg v4.4,

shauntarves commented 3 years ago

I think the problem is the <> in the resultant file name. I've honestly never run this library on a Windows machine, so I can only assume there may be some problem generating the temporary file name/directory.

That file name at the end of the command that is failing should be something like tmp\the_name.ts, and it looks like that final slash after the tmp is coming up with those left and right brackets.

I don't even have a Windows machine to test on, but you are welcome to submit a pull request if you can figure out what's causing it.

On Sat, Sep 4, 2021, 5:11 PM cosalich @.***> wrote:

Everything works great right up until ffmpeg gets involved:

`Fetching medialist 0 Fetching medialist 1 Fetching medialist 2 Downloading video chunklists Downloading video chunklists Downloading video chunklists Downloading video chunks Downloading video chunks Downloading video chunks Processing 482 chunks Chunking 482 files into batches of 60 for intermediate merge Starting merge 1 Merging 60 chunks to file D:\Programs\livebarn-1.0.0\tmp<>5896b59.ts (node:9308) UnhandledPromiseRejectionWarning: Error: An error occurred merging files: ffmpeg exited with code 1: D:\Programs\livebarn-1.0.0\tmp<>5896b59.ts: Invalid argument

at FfmpegCommand. (D:\Programs\livebarn-1.0.0\lib\livebarn.js:67:18) at FfmpegCommand.emit (events.js:400:28) at emitEnd (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:424:16) at endCB (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:544:13) at handleExit (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:170:11) at ChildProcess. (D:\Programs\livebarn-1.0.0\node_modules\fluent-ffmpeg\lib\processor.js:182:11) at ChildProcess.emit (events.js:400:28) at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)

(Use node --trace-warnings ... to show where the warning was created) (node:9308) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:9308) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/shauntarves/livebarn/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEDBMEN62D54EOPYVMRGO3UAKDRXANCNFSM5DNU6RLA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

cosalich commented 3 years ago

<> is just a result of me altering the identifying file - your scripts don't pass those characters through to ffmpeg, they push a standard alphanumeric filename that has no issue completing.

The issue seems to be somewhere either in the arguments your script passes to fluent-ffmpeg or between fluent-ffmpeg and ffmpeg itself

Which versions of fluent-ffmpeg and ffmpeg were you using for testing?

cosalich commented 3 years ago

You were right! At least, you were right about the directory being an issue under windows - the problem wasn't <> but rather :

Commenting out lines 19-22 in game.js removed the dateranges that included : which left me with a shorter filename & less descriptive filename, but does allow the script to run on windows.

I'm sure a more elegant solution exists, but this is a "good enough is good enough" solution for me.

Thanks again for the great script & help troubleshooting.

shauntarves commented 3 years ago

Okay, that's good to know. I would recommend that you run the generated command manually and see if that works. The illegal argument message from ffmpeg is something I often see when running a command where it doesn't like the filename for whatever reason.

See if that produces any leads as to what might be failing

On Sat, Sep 4, 2021, 11:14 PM cosalich @.***> wrote:

You were right! At least, you were right about the directory being an issue under windows - the problem wasn't <> but rather :

Commenting out lines 19-22 in game.js removed the dateranges that included : which left me with a shorter filename & less descriptive filename, but does allow the script to run on windows.

I'm sure a more elegant solution exists, but this is a "good enough is good enough" solution for me.

Thanks again for the great script & help troubleshooting.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/shauntarves/livebarn/issues/1#issuecomment-913078091, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEDBMH2PHWPSJEKSZMFHCLUALOAHANCNFSM5DNU6RLA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

CaTeNdrE commented 11 months ago

You were right! At least, you were right about the directory being an issue under windows - the problem wasn't <> but rather :

Commenting out lines 19-22 in game.js removed the dateranges that included : which left me with a shorter filename & less descriptive filename, but does allow the script to run on windows.

I'm sure a more elegant solution exists, but this is a "good enough is good enough" solution for me.

Thanks again for the great script & help troubleshooting.

You can work around the issue by replacing the colons with periods using str.split(':').join(".") or using RegEx replace(/\:/g,".")

For example:

  createFilenameForGame() {
    let parts = [];
    parts.push(`${this.surface.id}`);
    parts.push(`${this.dateRange.start.toJSON()}`);
    if (this.dateRange.end) {
      parts.push(`${this.dateRange.end.toJSON()}`);
    }
    parts.push(`${this.feedMode}`);
    return parts.join("-").split(':').join(".");
  }

or

  createFilenameForGame() {
    let parts = [];
    parts.push(`${this.surface.id}`);
    parts.push(`${this.dateRange.start.toJSON()}`);
    if (this.dateRange.end) {
      parts.push(`${this.dateRange.end.toJSON()}`);
    }
    parts.push(`${this.feedMode}`);
    return parts.join("-").replace(/\:/g,".");

I use the RegEx approach to also remove the seconds and milliseconds as well as the end date (keeping the end time).

  return parts.join("-").replace(/\:/g,".").replace(/\.[0]{2}\.[0]{3}Z[\d\.-]*?T|\.[0]{2}\.[0]{3}Z-/g,'-');