How can i deploy a node app using ffmpeg to heroku? - node.js

Struggling to go from local development to deploying my web app. using ffmpeg in node to crop things. tried following this guide to deploying ffmpeg, https://github.com/HYPERHYPER/heroku-buildpack-ffmpeg, and how the binary needs to be in a buildpack. Achieved this, but it still doesn't work. How do i reference the buildpack?
is is something to do with this line?
.setFfmpegPath('./ffmpeg')
var fileName = './new_crops/' + videoTitle + '.mp3';
var process = new ffmpeg({
source: videoGrab
})
.setFfmpegPath('./ffmpeg')
.audioBitrate(info.formats[0].audioBitrate)
.withAudioCodec('libmp3lame')
.toFormat('mp3')
.outputOptions('-id3v2_version', '4')
.outputOptions('-metadata', 'title=' + title)
.outputOptions('-metadata', 'artist=' + artist)
thanks in advance

Try removing the ./ from the ffmpeg path. According to the buildpack documentation, the app is installed in the server path, so it's globally available.
The full path where the executable is located is /app/vendor/ffmpeg/bin.

Related

How to fix "Error: /home/site/wwwroot/node_modules/canvas/build/Release/canvas.node: invalid ELF header" on NodeJs Azure Functions in Linux?

I am trying to deploy an AzureFunctions in NodeJs but it doesn't work on Azure.
My apllication is a v3 functions running on Linux.
When the deploy is completed, i get this 500 error:
Error:
/home/site/wwwroot/node_modules/canvas/build/Release/canvas.node:
invalid ELF header
Its happen only when I do this imports:
import ChartDataLabels from 'chartjs-plugin-datalabels';
const canvasRenderService = new CanvasRenderService(width, height, chartCallback);
const chartCallback = (ChartJS) => {
ChartJS.register(require('chartjs-plugin-datalabels'))
};
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { document } = (new JSDOM(`...`)).window;
Would someone help me please?
It works (only) on my machine :(
Edit: It works when I make the deploy by Linux Subsystem.
I hope this will help somebody.
Azure function will not include the Node_modules while deploying into azure. Because Node_modules directory contains very large file. You can include your package.json in you function directory and run npm install as you normally would with Node.js projects using Kudu (https://<function_app_name>.scm.azurewebsites.net )or the Console in the Azure portal.
Check Dependency management for more information.
Refer here Link 1 & Link 2
Any updates on this topic?
Doesn't seem like a valid option for me to manually run npm install via KUDU or some other terminal in a Cloud Function App - especially with Continoues Deployment etc.
Got the same problem while using canvas for barcode generation...

Nodejs - small Express server + trayicon + pkg

I'm trying to find out if smaller file size is possible, to have distributable one file for Express based API server app with some trayicon for basic controls - basically exit + restart app + open the API in default browser.
With Electron Builder I can do --ia32 target in about 68MB, but wonder if any lower size is possible, to learn more about it. But was having problem trying to get Systray2 and related solutions working using pkg (getting ENONENT on the exe file from node_modules (yes, tried adding it to package.json pkg assets, or even copied that exe to traybin folder under project root). I am sure there is a way but I may be missing something maybe obvious, so ready made Git would be great.
So if anything handy possible, is there some boilerplate ready to download? It just feels like waste of space to download Electron, when I only use the builder, Tray & Notification, but no mainWindow, ipc Renderer etc...
Not sure if this is relevant for you still, but I actually ran across the exact same requirement today. After many trials & errors, I did manage to solve it simply by setting the copyDir flag to true as shown in the below code when using the systray2 npm package:
const systray = new SysTray({
menu: {
icon: os.platform() === 'win32' ? './logo_s.ico' : './logo_s.png',
isTemplateIcon: os.platform() === 'darwin',
title: 'App',
tooltip: 'App',
items: [
itemExit
]
},
debug: false,
copyDir: true // This makes the systray2 work with pkg
})
My win-x64 binary size ended up at 38MB with Brotli compression (fastify server + systray2 + some css/images/js).
I didn't compare it with Electron Builder though, but I have a hunch it would be larger than that :)

Adding ffmpeg to heroku buildback nodejs

I've been trying to make a server that can visualize music (This is what I have so far). That's been successful but I want to try and make it work with youtube videos, and I've found a lot of repositories on github for youtube video to audio conversion that make this reasonably doable, but in order to deploy a server on heroku that can host temporary audio files of youtube videos in the format that I want, I'd need to include ffmpeg in a buildpack and I'm not sure how to go about doing that. This is the heroku buildpack for node.js but I don't really understand how it works.
TL;DR: What steps would I need to follow after forking the heroku-buildpack-nodejs repository on github in order to successfully deploy a node.js server to heroku and run this code?
var conversionProcess = child_process.spawn(
'ffmpeg',
['-i', 'some_youtube_audio.mp3', 'some_youtube_audio.webm'],
{
cwd: __dirname + '/tmp'
}
);
The documentation for this function is on the node.js API, by the way.
you should use the multipack https://github.com/ddollar/heroku-buildpack-multi
then use the node buildpack as well as an ffmpeg buildpack https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest

NodeJS: Set path to FFMPEG binaries for module Fluent-FFMPEG

I am building a application that uses the module node-fluent-ffmpeg. https://github.com/schaermu/node-fluent-ffmpeg
And I'm trying to package the ffmpeg binaries along with my application.
I want to do this so (especially on Windows) the user does not have to install FFMPEG manually.
Sadly everything I've tried results in errors. I've tried the following:
ffmpeg.setFfmpegPath : Gives an error saying setFfmpegPath is not a method
and:
proc.setFfmpegPath : Gives a createproces error.
It seems I'm doing something wrong. Could someone point out my mistake.
Thanks a lot.
I fix it!
I did not know I had to include the binary itself in the path. So I made something like this:
if(os.platform() === 'win32'){
var ffmpegPath = './bin/ffmpeg/ffmpeg.exe'
}else{
var ffmpegPath = './bin/ffmpeg/ffmpeg'
}
proc = new ffmpeg({ source: movieUrl, nolog: true, timeout: FFMPEG_TIMEOUT })
proc.setFfmpegPath(ffmpegPath)
proc.addOptions(opts)
proc.writeToStream(response, function(return_code, error){
In my case I have downloaded the npm i -S ffmpeg-binaries~ and after that I just set the process.env.FFMPEG_PATH to './node_modules/ffmpeg-binaries/bin/ffmpeg.exe'. This worked for me.

Deploy phantomJS to node.js app?

I realize "Running PhantomJS on Heroku" is a related but slightly different question as I am trying to use a node app.
I'm having trouble deploying a casperJS (based on phantomJS) script for a node app. I've tried deploying to Heroku by placing the PhantomJS 64-bit binary in my app's /bin directory, but I get the following error when I try to run PhantomJS:
phantomjs: error while loading shared libraries: libQtWebKit.so.4: cannot open shared object file: No such file or directory
From what I've read this can be solved by installing the QtWebKit library, but Heroku does not have this installed. Is there another hosting provider I could use that will work or a way to install this package on Heroku?
Relevant code:
app.get('/', function(request, response) {
var sys = require('sys')
var exec = require('child_process').exec;
var child;
//works but gives error while loading shared library libqtwebkit.so.4
child = exec("phantomjs --version | tr -d '\n'", function(error, stdout, stderr) {
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr + '\n');
response.header('Content-Type', 'application/json');
response.send('_testcb(stdout:' + stdout + '\nstderr:' + stderr + ')', 200);
if(error !== null) {
console.log('exec error: ' + error);
}
});
});
I've signed up for beta-testing on Nodester but their documentation is still pretty limited at this point.
EDIT: I was able to get it working by simply copying the lib folder of PhantomJS to the root directory of my node app.
Copy the lib folder of phantomjs to the root directory of your node app
You could also try putting a sym link in bin or sbin
The key is that is has to run from terminal using the same account that node runs on.
Also, node-phantom is a good npm library to utilize phantomjs, once you get it working.

Resources