How to use fluent-ffmpeg - 10 common examples

To help you get started, we’ve selected a few fluent-ffmpeg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenNewsLabs / autoEdit_2 / lib / interactive_transcription_generator / transcriber / split.js View on Github external
function split(file, tmpFolder, ffmpegBinPath, ffprobeBinPath, cb) {
  //maximum legth of clips in seconds. 5 minutes each.
  var maxLength = 60 * 5;
  //number of files
  var total = 0;
  //list of files
  var files = [];

  // set ffprobe bin
  if(ffprobeBinPath) {
    ffmpeg.setFfprobePath(ffprobeBinPath);
  } else {
    console.warn("ffprobe binary path not defined, so using system one. if available");
  }

  /**
  * @function finishedSplit
  * @description helper function used as callback to add info on trimmed clips to list of files. 
  * @param {string} - name of the audio clip 
  * @param {number} - clip time offset in seconds, in 5 min intervals
  * @returns {callback} callback - return list of files
  */
  var finishedSplit = function(filename, start) {
    files.push({
      name: filename,
      offset: start
    });
github petercunha / Wizardli / server / lib / downloader.js View on Github external
[/"/g, ""],
		[/'/g, ""],
		[/\//g, ""],
		[/\?/g, ""],
		[/:/g, ""],
		[/;/g, ""]
	];
	self.requestOptions =
		options && options.requestOptions
			? options.requestOptions
			: { maxRedirects: 5 };
	self.outputOptions =
		options && options.outputOptions ? options.outputOptions : [];

	if (options && options.ffmpegPath) {
		ffmpeg.setFfmpegPath(options.ffmpegPath);
	}

	// Async download/transcode queue
	self.downloadQueue = async.queue(function (task, callback) {
		self.emit(
			"queueSize",
			self.downloadQueue.running() + self.downloadQueue.length()
		);
		self.performDownload(task, function (err, result) {
			callback(err, result);
		});
	}, self.queueParallelism);
}
github leon-ai / leon / server / src / tts / google-cloud-tts / synthesizer.js View on Github external
fs.writeFile(file, res.audioContent, 'binary', (err) => {
      if (err) {
        log.error(`Google Cloud TTS: ${err}`)
        return
      }

      const ffmpeg = new Ffmpeg()
      ffmpeg.setFfmpegPath(ffmpegPath)
      ffmpeg.setFfprobePath(ffprobePath)

      // Get file duration thanks to ffprobe
      ffmpeg.input(file).ffprobe((err, data) => {
        if (err) log.error(err)
        else {
          const duration = data.streams[0].duration * 1000
          em.emit('saved', duration)
          cb(file, duration)
        }
      })
    })
  })
github OpenNewsLabs / autoEdit_2 / lib / interactive_transcription_generator / video_metadata_reader / index.js View on Github external
function readVideoMetadataForEDL(config){
  var file = config.file;
  var callback = config.callback;
  var video = {};

  if ( config.ffprobePath ) {
    //setting ffprobe bin
    ffmpeg.setFfprobePath( config.ffprobePath );
  } else {
    console.warn("ffprobe binary path not defined, so using system one. if available");
  }

  //running ffprobe   
  ffmpeg.ffprobe(file, function(err, metadata ) {
    // metadata is an object that contains all of the metadata available for the media file. Attributes especially nested onece may or may not be present costently across media files. Hence the following multiple boolean checks before reading attributes.
    //eg if format does not exist ad an attribtue then filename attribute will not be found under format.

    //reading file name 
    if(metadata !== undefined && metadata.format !== undefined && metadata.format.filename !== undefined ){
      video.filePathName = metadata.format.filename;
      var filePathO = path.parse(video.filePathName);
      video.fileName = filePathO.base;
    } else {
      video.filePathName = "NA";
github pjobson / movie2ascii / movie2ascii.node.js View on Github external
if (idx%6 === 0) {
					fout.push([]);
				}
				fout[fout.length-1].push(font);
			});

			console.log(columnify(fout, {
				showHeaders: false
			}));

			return deferred.resolve();
		});
	}
	// List of FFMPEG Decodable Formats
	if (global.info.formats) {
		ffmpeg.getAvailableFormats((err, formats) => {
			console.log('Available read formats:');
			for (const k in formats) {
				if(formats[k].canDemux) {
					console.log(`    - ${k}`);
				}
			}
			return deferred.resolve();
		});
	}
	// List of FFMPEG Decodable Codecs
	if (global.info.codecs) {
		ffmpeg.getAvailableCodecs((err, codecs) => {
			ffmpeg.getAvailableCodecs((err, codecs) => {
				console.log('Available read codecs:');
				for (const k in codecs) {
					if(codecs[k].canDecode) {
github sahat / cloudbucket / server.js View on Github external
if (err) {
                  console.error(err);
                  req.flash('info', 'Unable to save to database (EPUB)');
                  return res.redirect('/upload');
                }
                callback(null);
              });
            });

          });
          break;
        case 'avi':
        case 'mp4':
        case 'mov':
        case 'flv':
          var metaObject = new Metalib(filePath, function(metadata, err) {
            console.log(metadata);
            //var meta = util.inspect(metadata, false, null);
            file.videoCodec = metadata.video.codec;
            file.videoBitrate = metadata.video.bitrate;
            file.videoResolution = metadata.video.resolution;
            file.videoFps = metadata.video.fps;
            file.videoAudioCodec = metadata.audio.codec;
            file.videoAudioBitrate = metadata.audio.bitrate;
            file.videoAudioSampleRate = metadata.audio.sample_rate;

            // Save to database
            file.save(function(err) {
              if (err) {
                console.error(err);
                req.flash('info', 'Unable to save to database (VIDEO)');
                return res.redirect('/upload');
github juesato / gspeech-api / index.js View on Github external
.output(tmpFile)
				.audioFrequency(POST_SAMPLE_RATE)
				.toFormat('flac')
				.run();
		}

	    var file = options.file || options;
	    var segments = options.segments;
		var maxDuration = options.maxDuration | MAX_SEG_DUR;
		var maxRetries = options.maxRetries | 1;
		var limitConcurrent = options.limitConcurrent | MAX_CONCURRENT;
		var retries = 0;

		// Get file information and divide into segments
		// Then process each of these segments individually, and combine results at the end
	    ffmpeg.ffprobe(file, function (err, info) {
			var audioSegments = []
			var totalDuration = info.format.duration;
	    	if (segments) {
	    		for (var i = 0; i < segments.length; i++) {
	    			var duration = (i == segments.length-1) ? totalDuration-segments[i]: segments[i+1]-segments[i];
	    			if (duration < 0) {
	    				callback(new Error("segments must be a sorted array of start times, \
	    					each less than the total length of your audio"));
	    			}
	    			var curStart = segments[i];
	    			while (duration > maxDuration + .001) {
	    				audioSegments.push({
	    					'start': curStart,
	    					'duration': maxDuration
	    				});
	    				duration -= maxDuration;
github Lewdninja / liveme-pro-tools / index.js View on Github external
const dlQueue = async.queue((task, done) => {
    // Set custom FFMPEG path if defined
    if (appSettings.get('downloads.ffmepg')) ffmpeg.setFfmpegPath(appSettings.get('downloads.ffmepg'))
    // Get video info
    LiveMe.getVideoInfo(task).then(video => {
        const path = appSettings.get('downloads.path')
        const dt = new Date(video.vtime * 1000)
        const mm = dt.getMonth() + 1
        const dd = dt.getDate()

        let filename = appSettings.get('downloads.template')
            .replace(/%%broadcaster%%/g, video.uname)
            .replace(/%%longid%%/g, video.userid)
            .replace(/%%replayid%%/g, video.vid)
            .replace(/%%replayviews%%/g, video.playnumber)
            .replace(/%%replaylikes%%/g, video.likenum)
            .replace(/%%replayshares%%/g, video.sharenum)
            .replace(/%%replaytitle%%/g, video.title ? video.title : 'untitled')
            .replace(/%%replayduration%%/g, video.videolength)
github Ang-YC / wx-voice / index.js View on Github external
_checkDependencies() {
        var silkDecoder  = this._getSilkSDK("decoder"),
            silkEncoder  = this._getSilkSDK("encoder"),
            ffmpegPath   = this._ffmpegPath;

        // Check if Silk SDK is available
        if (!fs.existsSync(silkDecoder) || !fs.existsSync(silkEncoder)) {
            throw new Error("Silk SDK not found, make sure you compiled using command: wx-voice compile");
        }

        if (ffmpegPath && fs.existsSync(ffmpegPath)) {
            this._ffmpegPath = path.resolve(ffmpegPath);
            Ffmpeg.setFfmpegPath(this._ffmpegPath);

        } else if (ffmpegPath = this._getFfmpegPath()) {
            this._ffmpegPath = path.resolve(ffmpegPath);

        } else {
            throw new Error("FFMPEG not found");
        }
    }
github konsumer / easy-ffmpeg / index.js View on Github external
// osx: x64 / other: ia32
var arch = process.platform === 'darwin' ? 'x64' : 'ia32'

// only windows has an extension
var ext = process.platform === 'win32' ? '.exe' : ''

try {
  var ffmpeg = path.join(__dirname, 'ffmpeg', process.platform, arch, 'ffmpeg' + ext)
  var ffprobe = path.join(__dirname, 'ffmpeg', process.platform, arch, 'ffprobe' + ext)
  // this checks if the ffmpeg folder exists in our repo, if it doesn't it will return an error
  fs.accessSync(ffmpeg, fs.F_OK)
  fs.accessSync(ffprobe, fs.F_OK)

  // folder exists so we need to load ffmpeg and ffprobe from our repo
  FfmpegCommand.setFfmpegPath(ffmpeg)
  FfmpegCommand.setFfprobePath(ffprobe)
} catch (e) {
  // folder does not exist, this means that ffmpeg and ffprobe
  // wore found somewhere else during the install process
  // fluent-ffmpeg will set the correct paths on it's own
}

module.exports = FfmpegCommand