Skip to content

Instantly share code, notes, and snippets.

@teezzan
Created September 4, 2020 19:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teezzan/d8ee470f6dfc4f6ff2bad95e4e83e9ad to your computer and use it in GitHub Desktop.
Save teezzan/d8ee470f6dfc4f6ff2bad95e4e83e9ad to your computer and use it in GitHub Desktop.
Add Text to Video Using Nodejs
var ffmpeg = require('fluent-ffmpeg');
var axios = require('axios');
// make sure you set the correct path to your video file
var proc = ffmpeg('./input.mp4')
.videoFilters({
filter: 'drawtext',
options: {
fontfile:'font.ttf',
text: 'THIS IS TEXT',
fontsize: 20,
fontcolor: 'white',
x: '(main_w/2-text_w/2)',
y: 50,
shadowcolor: 'black',
shadowx: 2,
shadowy: 2
}
})
.input('https://verse.mp3quran.net/arabic/shaik_abu_baker_alshatri/64/001002.mp3')
.on('end', function () {
console.log('file has been converted succesfully');
})
.on('error', function (err) {
console.log('an error happened: ' + err.message);
})
// save to file
.save('./out.mp4');
@rohitgir93
Copy link

can you tell us how to add text at some seconds,, if possible

@sergioloom
Copy link

@Heinrich-Visualization check this out: https://stackoverflow.com/a/50749822/21420

@Dhruv-Shetty
Copy link

Dhruv-Shetty commented Sep 20, 2022

how can we customize font family?

I got solution instead of font-family use font:"Comic Sans MS" etc for font customization

@Dhruv-Shetty
Copy link

can you tell us how to add text at some seconds,, if possible

You can use option enable in options as : enable:"between(t,5,7)"
you can have any value here I have used 5 and 7 to enable text between 5 to 7 seconds of the video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment