Node.js: Converting MP4 to GIF (puppeteer-lottie) - node.js

I am trying to convert a .mp4 file to .gif using NPM packages, but nothing seems to be working.
I tried using gifski binary package (NPM) for this, but no luck. It says its a binary package and you can use it by child_process.spawn() or similar. I installed it with -g (global) flag and seems like its not recognized even with global flag. Not sure If you can set PATH or anything. Let me know if its possible.
As for the other tries, I used gify and its just not doing anything (no file or error).
I am getting the .mp4 file from puppeteer-lottie NPM package. Here's my code, if needed for testing:
const renderLottie = require('puppeteer-lottie');
await renderLottie({ animationData: data, output: 'example.mp4', width: 640 });
animationData: Sticker JSON
I am pretty sure that there are much easier ways to do this, but I am just using complex ones. I just want .mp4 to .gif at the end.
Thanks for your time.

For those of you who are still trying to find solution, I finally found it.
We just use ffmpeg with child_process.exec(). No need to install anything.
const { exec } = require("child_process");
exec("ffmpeg -i input.mp4 -qscale 0 output.gif");
input is your mp4 file that you want to convert, and output is your result gif file.
Source: Conrad Lotz's answer

Related

How to convert m3u8 file to mp4 video using nodeJS with a remote S3 input

The objective is to convert .m3u8 file(hls stream) to .mp4 video inside my NodeJS application. I've tried doing the same using ffmpeg on console and that works fine but unable to find a recently maintained package that helps me do this in node.
Also, my input file is not the usual file located in my local directory but a remote AWS S3 object URL which is otherwise accessible to all(public bucket), in simpler words,
How do I do ffmpeg -i https://mycloudfrontURL/myHLSfile.m3u8 output.mp4 in JS?
The best solution is to use ffmpeg directly in your node.js application.
Install ffmpeg on your pc. Then create a node.js file that runs ffmpeg like so:
const { execSync } = require('child_process')
const input = 'https://mycloudfrontURL/myHLSfile.m3u8'
const output = 'output.mp4'
execSync(`ffmpeg -y -i "${input}" "${output}"`)
You'll be able to execute ffmpeg and get the same result as if running it from the terminal. Make sure to have ffmpeg installed or indicate the full path if it doesn't work.
If this worked for you, upvote the solution.

Getting "Cannot find ffprobe error " when attempting to run nodejs script

I am attempting to use an npm package for splitting audio (https://github.com/calufornia/audio-split), however I am not able to run a single test since I get the following error on my callback:
Error: Cannot find ffprobe, I have read a bit and it seems that this is directly related to the npm package fluent_ffmpeg, which is actually a dependency of the first package I mentioned.
The problem on some other questions/forums is that people do not have properly installed ffmpeg on their environment. In my case however, I have made sure that my PATH is updated with the ffmpeg directory (C:\FFmpeg\bin for me), and I am able to open a command prompt and run both
ffmpeg -version
and
ffprobe -version
I would much appreciate if anyone else has struggled with this previously and could provide me with some more guidance. Thanks

Cannot find ffprobe?

I am trying to generate video thumbnail in my node project for that I tried
thumbsupply and video-thumbnail npm both returns the same error called not found: ffprobe
const thumbsupply = require('thumbsupply');
const ffprobe = require('#ffprobe-installer/ffprobe');
let aa = thumbsupply.generateThumbnail('videoplayback.mp4', {
size: thumbsupply.ThumbSize.MEDIUM, // or ThumbSize.LARGE
timestamp: "10%", // or `30` for 30 seconds
forceCreate: true,
cacheDir: "~/myapp/cache",
mimetype: "video/mp4"
})
console.log(aa);
Thumbsupply uses fluent-ffmpeg (from a quick look at the source):
https://github.com/fluent-ffmpeg/node-fluent-ffmpeg
fluent-ffmpeg has information on the requirements around ffmpeg installation and the required path at the link above.
Prerequisites
ffmpeg and ffprobe
fluent-ffmpeg requires ffmpeg >= 0.9 to work. It may work with previous versions but several features won't be available (and the library is not tested with lower versions anylonger).
If the FFMPEG_PATH environment variable is set, fluent-ffmpeg will use it as the full path to the ffmpeg executable. Otherwise, it will attempt to call ffmpeg directly (so it should be in your PATH). You must also have ffprobe installed (it comes with ffmpeg in most distributions). Similarly, fluent-ffmpeg will use the FFPROBE_PATH environment variable if it is set, otherwise it will attempt to call it in the PATH.
ffmpeg details including installation is here: https://www.ffmpeg.org/download.html
I was also getting this issue Error: Cannot find ffprobe
I have done following steps to make it work in ubuntu
sudo apt update
sudo apt install ffmpeg
restarted my pm2 api instance.
This was my case with the deployment server,
Since, I was working in local on mac os, I used
brew install ffmpeg

MPEG DASH:using Gpac to get MPD files

My goal is to convert some mpeg4 files in my hard disk into mpd files that will alllow me to use it in mpeg dash streaming .i read about gpac's MP4Box capability to create mpd files and i followed the instructions of the following link to successfully compile gpac for ubuntu like in the instructions in this two links
http://gpac.wp.mines-telecom.fr/2011/04/20/compiling-gpac-on-ubuntu/
http://gpac.wp.mines-telecom.fr/2012/02/01/dash-support/
But when i try to execute any command such as
MP4Box -dash 10000 -frag 1000 -rap myFile.mp4
I get the following error
Option -dash unknown. Please check usage
I wonder is there any commands or instructions that i must execute when building gpac to add the dash and if is there any other methods to get my own MPD File not those provided by itec.
Thanks in advance !!!
Try to follow the compile instruction carefully & make sure to fetch the latest version from SVN.
MP4Box should work with your commands.
looks like you are using a outdated version of MP4Box. try downloading and compiling the latest one from here (for me the same command works): http://gpac.wp.mines-telecom.fr/downloads/gpac-nightly-builds/

Node.js ImageMagick & GM both cause error 127 when trying to load a valid image

I have a node app which accepts an uploaded image (using formidable) and stores it into an Amazon S3 bucket. Before it is saved to S3, I want to get the image's width, height, etc. for future consideration. I found this question which helped: Opening images on NodeJS and finding out width/height
However, when I try to open the image with imagemagick (or gm, for that matter, I've tried both) I get error 127. Specifically, imagemagick reports:
{"timedOut":false,"killed":false,"code":127,"signal":null}
I know the file exists (because it is properly uploaded to the S3 bucket), and I can manipulate it (eg, rename) via fs, but I cannot find any documentation on error code 127 to determine why IM fails. Thinking that perhaps there was something odd about the file uploaded to formidable causing it to not be read properly, I tried using imagemagick to load a simple "test.jpg" image in the same folder:
im.identify('test.jpg', function(err, features){
if(!err)
{
// my image processing code
}
else
{
// my err handling code; spits out the error above
}
});
Unfortunately, this fails in the exact same manner, even though I'm sure test.jpg is a good and properly formatted image.
So, can anybody help me understand what error 127 is and why ImageMagick would throw it when fs is able to read the file just fine...?
These are a couple of php commands to find the path to Imagemagick which should confirm it is installed.
Sometimes in php there is a problem just using convert and you need to use the full path; something like /usr/local/bin/convert
echo "<pre>";
system("type convert");
system('which convert',$path); print_r($path);
echo "</pre>";
I know you are not using php but you should still be able to use the methods.
Make sure "convert" is installed
sudo apt-get update
sudo apt-get install imagemagick --fix-missing
Derp. I didn't have ImageMagick itself installed. I assumed that the NPM installation was all that was required; did not realize there were additional dependencies, and the error message was a bit cryptic ;)
I had the same problem, just install Graphics Magick, http://www.graphicsmagick.org/
test if your intallation works as the wizard suggest and that's it.

Resources