Forked from DusanBrejka/fluent-ffmpeg-custom-args.js
Created
February 16, 2020 20:03
-
-
Save merapi/967b93d89d2fc61243c5431ecb2575e2 to your computer and use it in GitHub Desktop.
node-fluent-ffmpeg - Execute Custom FFMPEG arguments hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| As at the time of writing this Fluent ffmpeg-API for node.js has not been updated | |
| for years and still does not support custom FFMPEG attributes, the only solutions | |
| are either forking it or resorting to hacks like this one... | |
| Please use it only when fluent does not support more complex arguments | |
| (like generating multi-rendition HLS with all playlists in a single command) | |
| NOTE: this does not support 'progress' event, but you can do it easily by | |
| parsing 'stderr' event with extractProgress method from fluent-ffmpeg/lib/options.js | |
| */ | |
| const fluent = require('fluent-ffmpeg'); | |
| const executeFfmpeg = args => { | |
| let command = fluent().output(' '); // pass "Invalid output" validation | |
| command._outputs[0].isFile = false; // disable adding "-y" argument | |
| command._outputs[0].target = ""; // bypass "Unable to find a suitable output format for ' '" | |
| command._global.get = () => { // append custom arguments | |
| if(typeof args === "string") { | |
| return args.split(' ').filter(c => c !== "" && c !== "\\\n") | |
| } else return args; | |
| }; | |
| return command; | |
| }; | |
| executeFfmpeg('-f lavfi -i testsrc=size=1920x1080:rate=30 -y -t 60 ./test.mp4') | |
| .on('start', commandLine => console.log('start', commandLine)) | |
| .on('codecData', codecData => console.log('codecData', codecData)) | |
| .on('error', error => console.log('error', error)) | |
| .on('stderr', stderr => console.log('stderr', stderr)) | |
| .run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment