Code Monkey home page Code Monkey logo

node-ffmpeg's Introduction

node-ffmpeg

FFmpeg module for Node. This library provides a set of functions and utilities to abstract commands-line usage of ffmpeg. To use this library requires that ffmpeg is already installed (including all necessary encoding libraries like libmp3lame or libx264)

You can install this module using npm:

npm install ffmpeg

Usage

To start using this library, you must include it in your project and then you can either use the callback function or through the promise library:

var ffmpeg = require('ffmpeg');

Use the callback function

	try {
		new ffmpeg('/path/to/your_movie.avi', function (err, video) {
			if (!err) {
				console.log('The video is ready to be processed');
			} else {
				console.log('Error: ' + err);
			}
		});
	} catch (e) {
		console.log(e.code);
		console.log(e.msg);
	}

Use the approach with the library promise

	try {
		var process = new ffmpeg('/path/to/your_movie.avi');
		process.then(function (video) {
			console.log('The video is ready to be processed');
		}, function (err) {
			console.log('Error: ' + err);
		});
	} catch (e) {
		console.log(e.code);
		console.log(e.msg);
	}

The video object

Each time you create a new instance, this library provides a new object to retrieve the information of the video, the ffmpeg configuration and all methods to make the necessary conversions:

	try {
		var process = new ffmpeg('/path/to/your_movie.avi');
		process.then(function (video) {
			// Video metadata
			console.log(video.metadata);
			// FFmpeg configuration
			console.log(video.info_configuration);
		}, function (err) {
			console.log('Error: ' + err);
		});
	} catch (e) {
		console.log(e.code);
		console.log(e.msg);
	}

Preset functions

The video object contains a set of functions that allow you to perform specific operations independent of the settings for the conversion. In all the functions you can use the approach with the callback function or with the promise object

video.fnExtractSoundToMP3 (destionationFileName, callback)

This function extracts the audio stream of a video into an mp3 file

Params:

  • destionationFileName: Full path of the new file:

    /path/to/your_audio_file.mp3

  • callback: (optional) If specified at the end of the process it will return the path of the new audio file:

    function (error, file)

Example:

	try {
		var process = new ffmpeg('/path/to/your_movie.avi');
		process.then(function (video) {
			// Callback mode
			video.fnExtractSoundToMP3('/path/to/your_audio_file.mp3', function (error, file) {
				if (!error)
					console.log('Audio file: ' + file);
			});
		}, function (err) {
			console.log('Error: ' + err);
		});
	} catch (e) {
		console.log(e.code);
		console.log(e.msg);
	}

video.fnExtractFrameToJPG(destinationFolder, settings, callback)

This function takes care of extracting one or more frames from the video that is being developed. At the end of the operation will return an array containing the list of extracted images

Params:

  • destinationFolder: Destination folder for the frames generated:

    /path/to/save_your_frames

  • settings: (optional) Settings to change the default settings:

		{
			start_time				: null		// Start time to recording
		  , duration_time			: null		// Duration of recording
		  , frame_rate				: null		// Number of the frames to capture in one second
		  , size					: null		// Dimension each frame
		  , number					: null		// Total frame to capture
		  , every_n_frames			: null		// Frame to capture every N frames
		  , every_n_seconds			: null		// Frame to capture every N seconds
		  , every_n_percentage		: null		// Frame to capture every N percentage range
		  , keep_pixel_aspect_ratio	: true		// Mantain the original pixel video aspect ratio
		  , keep_aspect_ratio		: true		// Mantain the original aspect ratio
		  , padding_color			: 'black'	// Padding color
		  , file_name				: null		// File name
		}
  • callback: (optional) If specified at the end of the process will be returned list of paths of frames created:

    function (error, files)

Example:

	try {
		var process = new ffmpeg('/path/to/your_movie.avi');
		process.then(function (video) {
			// Callback mode
			video.fnExtractFrameToJPG('/path/to/save_your_frames', {
				frame_rate : 1,
				number : 5,
				file_name : 'my_frame_%t_%s'
			}, function (error, files) {
				if (!error)
					console.log('Frames: ' + files);
			});
		}, function (err) {
			console.log('Error: ' + err);
		});
	} catch (e) {
		console.log(e.code);
		console.log(e.msg);
	}

video.fnAddWatermark(watermarkPath, newFilepath, settings, callback)

This function takes care of adding a watermark to the video that is being developed. You can specify the exact position in which position the image

Params:

  • watermarkPath: The full path where the image is stored to add as watermark:

    /path/to/retrieve/watermark_file.png

  • newFilepath: (optional) Name of the new video. If not specified will be created by the function:

    /path/to/save/your_file_video.mp4

  • settings: (optional) Settings to change the default settings:

		{
			position		: "SW"		// Position: NE NC NW SE SC SW C CE CW
		  , margin_nord		: null		// Margin nord
		  , margin_sud		: null		// Margin sud
		  , margin_east		: null		// Margin east
		  , margin_west		: null		// Margin west
		};
  • callback: (optional) If specified at the end of the process it will return the path of the new video containing the watermark:

    function (error, files)

Example:

	try {
		var process = new ffmpeg('/path/to/your_movie.avi');
		process.then(function (video) {
			// Callback mode
			video.fnAddWatermark('/path/to/retrieve/watermark_file.png', '/path/to/save/your_file_video.mp4', {
				position : 'SE'
			}, function (error, file) {
				if (!error)
					console.log('New video file: ' + file);
			});
		}, function (err) {
			console.log('Error: ' + err);
		});
	} catch (e) {
		console.log(e.code);
		console.log(e.msg);
	}

Custom settings

In addition to the possibility of using the preset, this library provides a variety of settings with which you can modify to your liking settings for converting video

  • video.setDisableAudio(): Disables audio encoding

  • video.setDisableVideo(): Disables video encoding

  • video.setVideoFormat(format): Sets the new video format. Example:

    video.setVideoFormat('avi')
    
  • video.setVideoCodec(codec): Sets the new audio codec. Example:

    video.setVideoCodec('mpeg4')
    
  • video.setVideoBitRate(bitrate): Sets the video bitrate in kb. Example:

    video.setVideoBitRate(1024)
    
  • video.setVideoFrameRate(framerate): Sets the framerate of the video. Example:

    video.setVideoFrameRate(25)
    
  • video.setVideoStartTime(time): Sets the start time. You can specify the value in seconds or in date time format. Example:

		// Seconds
		video.setVideoStartTime(13)

		// Date time format
		video.setVideoStartTime('00:00:13')
  • video.setVideoDuration(duration): Sets the duration. You can specify the value in seconds or in date time format. Example:
		// Seconds
		video.setVideoDuration(100)

		// Date time format
		video.setVideoDuration('00:01:40')
  • video.setVideoAspectRatio(aspect): Sets the new aspetc ratio. You can specify the value with a number or with a string in the format 'xx:xx'. Example:
		// Value
		video.setVideoAspectRatio(1.77)

		// Format xx:xx
		video.setVideoAspectRatio('16:9')
  • video.setVideoSize(size, keepPixelAspectRatio, keepAspectRatio, paddingColor): Set the size of the video. This library can handle automatic resizing of the video. You can also apply a padding automatically keeping the original aspect ratio

    The following size formats are allowed to be passed to size:

    640x480 Fixed size (plain ffmpeg way)

    50% Percental resizing

    ?x480 Fixed height, calculate width

    640x? Fixed width, calculate height

    Example:

		// In this example, the video will be automatically resized to 640 pixels wide and will apply a padding white
		video.setVideoSize('640x?', true, true, '#fff')

		// In this example, the video will be resized to 640x480 pixel, and if the aspect ratio is different the video will be stretched
		video.setVideoSize('640x480', true, false)
  • video.setAudioCodec(codec): Sets the new audio codec. Example:

    video.setAudioCodec('libfaac')
    
  • video.setAudioFrequency(frequency): Sets the audio sample frequency for audio outputs in kb. Example:

    video.setAudioFrequency(48)
    
  • video.setAudioChannels(channel): Sets the number of audio channels. Example:

    video.setAudioChannels(2)
    
  • video.setAudioBitRate(bitrate): Sets the audio bitrate in kb. Example:

    video.setAudioBitRate(128)
    
  • video.setAudioQuality(quality): Sets the audio quality. Example:

    video.setAudioQuality(128)
    
  • video.setWatermark(watermarkPath, settings): Sets the watermark. You must specify the path where the image is stored to be inserted as watermark

    The possible settings (the values ​​shown are the default):

    • position : "SW"

      Position: NE NC NW SE SC SW C CE CW

    • margin_nord : null

      Margin nord (specify in pixel)

    • margin_sud : null

      Margin sud (specify in pixel)

    • margin_east : null

      Margin east (specify in pixel)

    • margin_west : null

      Margin west (specify in pixel)

    Example:

    // In this example will be added the watermark at the bottom right of the video
    video.setWatermark('/path/to/retrieve/watermark_file.png')
    

Add custom options

If the ffmpeg parameters are not present in the list of available function you can add it manually through the following function

video.addCommand(command, argument)

Example:

	// In this example will be changed the output to avi format
	video.addCommand('-f', 'avi');

Save the file

After setting the desired parameters have to start the conversion process. To do this you must call the function 'save'. This method takes as input the final destination of the file and optionally a callback function. If the function callback is not specified it's possible use the promise object.

video.save(destionationFileName, callback)

Example:

	try {
		var process = new ffmpeg('/path/to/your_movie.avi');
		process.then(function (video) {
			
			video
			.setVideoSize('640x?', true, true, '#fff')
			.setAudioCodec('libfaac')
			.setAudioChannels(2)
			.save('/path/to/save/your_movie.avi', function (error, file) {
				if (!error)
					console.log('Video file: ' + file);
			});

		}, function (err) {
			console.log('Error: ' + err);
		});
	} catch (e) {
		console.log(e.code);
		console.log(e.msg);
	}

node-ffmpeg's People

Contributors

ajmas avatar aleray avatar amilajack avatar bryancrotaz avatar damianociarla avatar jladuval avatar pawan-saxena avatar positlabs avatar ttillberg avatar wilsonwc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-ffmpeg's Issues

Does this package support URLs ?

Below is my code for trying to retrieve a video from an url and saving it as an adio file on my local disk. but it has an Error on input file. Does it mean that this package does not support urls ?

try {
	var process = new ffmpeg("http://www.url.mp4");
	process.then(function (video) {
		// Callback mode
    console.log('video', video);
		video.fnExtractSoundToMP3('localpath.mp3', function (error, file) {
      console.log('files is', file);
      if (error) console.log(error);
			if (!error)
				console.log('Audio file: ' + file);
		});
	}, function (err) {
		console.log('Error: ' + err);
	});
} catch (e) {
	console.log(e.code);
	console.log(e.msg);
}

No output received and no error

i write this below code to extract sound from avi video it run with no error but no audio extracted in desire path.
var ffmpeg = require('ffmpeg');
try {
var process = new ffmpeg('grb.avi');
process.then(function (video) {
// Callback mode
video.fnExtractSoundToMP3('/path/grbaudio.mp3', function (error, file) {
if (!error)
console.log('Audio file: ' + file);
});
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}

Empty information when filename have a space character

Hello,

I've a problem to read a movie information with space in the name (only space, no problem with special char same coma and other.. )
When this module try to read this movies, I got a obejct with empty properties like this :

video { filename: '',
  title: '',
  artist: '',
  album: '',
  track: '',
  date: '',
  synched: false,
  duration: { raw: '', seconds: 0 },
  video:
   { container: '',
     bitrate: 0,
     stream: 0,
     codec: '',
     resolution: { w: 0, h: 0 },
     resolutionSquare: { w: 0, h: NaN },
     aspect: {},
     rotate: 0,
     fps: 0,
     pixelString: '',
     pixel: 0 },
  audio:
   { codec: '',
     bitrate: '',
     sample_rate: 0,
     stream: 0,
     channels: { raw: '', value: '' } } }

But if I try to read it directly with "ffmpeg -i", I got the right information !
Apparently this function Stringify the filename received in params, and ironically if I copy this file name on this command > ffmpeg -i "this name" on command line, this work fine !?

I use Powershell on Windows 10, I've not try on Linux or Mac.
I'm French, sorry if I not speak correctly English.

Potentially unhandled rejection | FFMPEG throws a unsupported format Error message

I've created a script to convert a mp4 in a webm file but i got an error message that is not related to the script it self because the script works fine on my ubuntu desktop pc with node js installed.

But the script throws an error message in my project and testing docker container.
The docker container is running on the latest version of ubuntu for docker.

DESKTOP
Nodejs version: 9.11.1
npm version: 6.2.0

DOCKER CONTAINER
Nodejs version 10.7.0 (Also tried on the same version gave me the same result)
npm version 6.2.0

Install command for all programs:
apt-get update && apt-get upgrade && apt-get install -y curl git nano htop && apt-get install -y gnupg2 && curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs && npm install npm -g

Script: Bitbucket / converter script

ERROR Message:
Potentially unhandled rejection [1] {"code":104,"msg":"The format \"$s\" is not supported by the version of ffmpeg webm"} (WARNING: non-Error used)

Commit "Fixes issue #21, spaces in input paths" breaks existing filenames without spaces

Commit id 8659a9f "Fixes issue #21, spaces in input paths"
Breaks existing code that calls:

filename = "/tmp/preview.mp4";
new ffmpeg(filename)
.then(video => {
...
video.fnExtractFrameToJPG(...);
})

fnExtractFrameToJPG fails with error '/tmp/preview.mp4': No such file or directory

Adding fs.statSync(filename) before fnExtractFrameToJPG shows that the file does exist in this location before calling fnExtractFrameToJPG.

Using previous commit id c099e37 fnExtractFrameToJPG output files returned successfully.

[CRITICAL BUG] double quote

This commit (ca4a836#diff-ad82b5b82699c5afb1444512d08dd76b) introduces a critical bug (this lib doesn't work anymore)

// l.554
for (i=0; i<inputs.length; i++) {
  inputs[i] = '\'' + inputs[i] + '\'';
}
///... already done by inputs.map(utils.addQuotes)

You can see all the forks currently are for this unique fix purpose... Please remove lines or revert.

Always take care of testing before accepting pull requests ;). Thanks to you.

Video quality

Hi; what command can i use for setting video quality; i try setVideoBitrate nothing happens

Slow encoding

Encoding a video using ffmpeg directly is significantly faster (30 seconds versus 80 seconds) than using this module or fluent-ffmpeg, am I doing something wrong? Is this related to nodejs being single-threaded?

let transcode = new ffmpeg(this.testFile)
 transcode.then(function (video) {
                let outputPath = path.join(this.transcodePath, 'output.mp4');
                video.addCommand('-c:v', 'libx264');
                video.addCommand('-b:v', '2000000');
                video.save(outputPath);
});

vs

ffmpeg -i test.mov -b:v 2000000 -c:v libx264 test2.mp4

Limit CPU usage

  • How can i limit CPU and Memory usage?
  • How can i log actual command in console?

Replace %d in file names to digits.

Hi, I'm having problems using this module since I need to have control of the name of the files that get exported via the video-2-frames function.

you provide a file_name options, and then you replace commands like %t to dates, %s to size and etc, but left out the %d for the index of the frames.

at video.js#L765 you add this on manually at the end, leaving us no option to control this.

// At the filename will added the number of the frame
settings.file_name = path.basename(settings.file_name, path.extname(settings.file_name)) + '_%d.jpg';

Any thoughts on why you chose to leave this functionality out?

Command failed

I am trying to add watermark to video but it failed.
Error is:

error: { Error: Command failed: ffmpeg -i assets/encoded/upload-157113597459120191009_171749.mp4 -i assets/logo/logo.png -filter_complex "overlay=0-0+0:main_h-overlay_h-0+0" assets/encoded/water-157113597459120191009_171749.mp4
'ffmpeg' is not recognized as an internal or external command,
operable program or batch file.

at ChildProcess.exithandler (child_process.js:294:12)
at ChildProcess.emit (events.js:188:13)
at ChildProcess.EventEmitter.emit (domain.js:441:20)
at maybeClose (internal/child_process.js:978:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)

killed: false,
code: 1,
signal: null,
cmd:
'ffmpeg -i assets/encoded/upload-157113597459120191009_171749.mp4 -i assets/logo/logo.png -filter_complex "overlay=0-0+0:main_h-overlay_h-0+0" assets/encoded/water-157113597459120191009_171749.mp4' }

Please help me !

start_time Option does nothing

In my testing, i couldnt get fnExtractFrameToJPG(path_out, {number:1, start_time: <time in secs>}) to save a Frame of a given time.

I have no idea why.

stderr maxBuffer exceeded

Error encoding file:  { Error: stderr maxBuffer exceeded
    at Socket.onChildStderr (child_process.js:283:14)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at Pipe.onread (net.js:551:20)
  cmd: 'ffmpeg -i "video.avi" -preset veryfast -crf 18 -c:a libfdk_aac -b:a 128k -f mp4 "video.mp4"' }

It appears 200 KB is not a big enough maxBuffer when coding avi -> mp4

Command Failed on large files

I tried on some basic commands of ffmpeg, they worked fine on my local environment, but when i deployed it. Large files i.e approx 200MB starts failing with error command failed.
After some research i found it may be because of less CPU and RAM configurations.So I increased it , after which it starts failing on 500 MB files.Can someone please suggest how much resource ffmpeg needs or some pattern by which i can identify which type and size of files would work fine on how much resource.

500MB mp4 failed on 1500m CPU and 1000 Mi RAM

Function for conversion is ::
const convertWithFFMPEG = ({ fileName, path, dimensions, type, tempFiles, extension }) => { return new Promise((resolve, reject) => { const inputFilePath = path + "/" + fileName; var process = new ffmpeg(inputFilePath); let { height, width } = dimensions; process.then( command => { let vf; vf = ``thumbnail,scale=${width}:${height}``; let outputFilePath = ${path}/${fileName}_converted.${extension}``; command.addCommand("-frames:v 1"); command.addCommand("-compression_level", 100); command.addCommand("-vf", vf); command.save(outputFilePath, (error, file) => { if (error) { reject(error); } tempFiles.push(outputFilePath); resolve(outputFilePath); }); }, err => { reject(err); } ); }); };

Error is ::
Command failed: ffmpeg -i /usr/src/app/src/temp/video100mb___e839e9ef_07db_43af_8a4a_62f0cbec294c.mp4 -frames:v 1 -compression_level 100 -vf thumbnail,scale=144:256 /usr/src/app/src/temp/video100mb___3942b363_4e4e_4c7d_b236_edc23659f02d_ffmpeg_thumb.jpegffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 8.2.0 (Alpine 8.2.0) configuration: --prefix=/usr --enable-avresample --enable-avfilter --enable-gnutls --enable-gpl --enable-libass --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-libx265 --enable-libtheora --enable-libv4l2 --enable-postproc --enable-pic --enable-pthreads --enable-shared --enable-libxcb --disable-stripping --disable-static --disable-librtmp --enable-vaapi --enable-vdpau --enable-libopus --disable-debug libavutil 56. 14.100 / 56. 14.100 libavcodec 58. 18.100 / 58. 18.100 libavformat 58. 12.100 / 58. 12.100 libavdevice 58. 3.100 / 58. 3.100 libavfilter 7. 16.100 / 7. 16.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 libpostproc 55. 1.100 / 55. 1.100Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/src/app/src/temp/video100mb___e839e9ef_07db_43af_8a4a_62f0cbec294c.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2018-10-07T14:00:12.000000Z location : -23.5573-046.7765/ location-eng : -23.5573-046.7765/ com.android.version: 8.0.0 Duration: 00:00:46.85, start: 0.000000, bitrate: 17258 kb/s Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 16996 kb/s, SAR 1:1 DAR 16:9, 29.98 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate : 90 creation_time : 2018-10-07T14:00:12.000000Z handler_name : VideoHandle Side data: displaymatrix: rotation of -90.00 degrees Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default) Metadata: creation_time : 2018-10-07T14:00:12.000000Z handler_name : SoundHandleStream mapping: Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))Press [q] to stop, [?] for help[swscaler @ 0x564a3aac4a80] deprecated pixel format used, make sure you did set range correctlyOutput #0, image2, to '/usr/src/app/src/temp/video100mb___3942b363_4e4e_4c7d_b236_edc23659f02d_ffmpeg_thumb.jpeg': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 com.android.version: 8.0.0 location : -23.5573-046.7765/ location-eng : -23.5573-046.7765/ encoder : Lavf58.12.100 Stream #0:0(eng): Video: mjpeg, yuvj444p(pc), 144x256 [SAR 1:1 DAR 9:16], q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc (default) Metadata: encoder : Lavc58.18.100 mjpeg creation_time : 2018-10-07T14:00:12.000000Z handler_name : VideoHandle Side data: cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 displaymatrix: rotation of -0.00 degreesframe= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x

Problem with fnAddWatermark

In local computer work fine... I install in my hosting the FFMPEG but not working.

Unrecognized option 'filter_complex'
Failed to set value 'overlay=0-0+0:0-0+0' for option 'filter_complex'

Thanks

setVideoFormat() doesn't work

the functions inside 'custom settings' section don't seem to work for me with the given syntax. Is there any other syntax to be used? especially for setVideoFormat(). thanks in advance.

Sending output of ffmpeg to HTML5 stream

Hello,

I am trying to implement the video streaming server using ffmpeg and nodejs. Can you help me by providing the sample, how can i stream ffmpeg output over html5

setVideoDuration does not work

Hi , it seems I cannot get setVideoDuration to work . It alswas rounds down to the second.

so if I want "00:00:01.48" it will trim to exactly 1 second...
and If I want 00:00:00.76" it will create an unplayable video file of 0 seconds...

Progress Events ?

Hi,
is it somehow possible to return the current progress of a video conversion with node-ffmpeg ?

Cheers Marc

Metadata invalid when trying to read a file.

Basically I do this:

import FFmpeg from 'ffmpeg';

const res = './resources/video';
const output = './public';
const filename = 'newvideo';
const src = `${ res }/${ filename }.mp4`;

console.log('starting app');

const initVideo = async () => {
    let file = null;

    try {
        file = await new FFmpeg(src);
    } catch (error) {
        console.log(`there is an error: ${ error }`);
    }

    return file;
};

const initApp = async () => {
    let video = null;

    try {
        video = await initVideo();

        console.log(video.metadata);

        video.fnExtractFrameToJPG(`${ output }/thumbs/${ filename }/`, {
            frame_rate: 1,
            number: 5,
            file_name: 'my_frame_%t_%s'
        }, (error, files) => {
            console.log(error, files);
            if (!error) {
                console.log('Frames: ' + files);
            }
        });
    } catch (error) {
        console.log(error);
    }

    return video;
};

video.metadata log returns

{ filename: '',
  title: '',
  artist: '',
  album: '',
  track: '',
  date: '',
  synched: false,
  duration: { raw: '', seconds: 0 },
  video:
   { container: '',
     bitrate: 0,
     stream: 0,
     codec: '',
     resolution: { w: 0, h: 0 },
     resolutionSquare: { w: 0, h: NaN },
     aspect: {},
     rotate: 0,
     fps: 0,
     pixelString: '',
     pixel: 0 },
  audio:
   { codec: '',
     bitrate: '',
     sample_rate: 0,
     stream: 0,
     channels: { raw: '', value: '' } } }

and when trying to fnExtractFrameToJPG() it throws me this error:

{ Error: Command failed: ffmpeg -i ./resources/video/newvideo.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" ./public/thumbs/newvideo//my_frame_1524596748522_0x0_%d.jpg
/bin/sh: ffmpeg: command not found

    at ChildProcess.exithandler (child_process.js:273:12)
    at ChildProcess.emit (events.js:180:13)
    at maybeClose (internal/child_process.js:936:16)
    at Socket.stream.socket.on (internal/child_process.js:353:11)
    at Socket.emit (events.js:180:13)
    at Pipe._handle.close [as _onclose] (net.js:541:12)
  killed: false,
  code: 127,
  signal: null,
  cmd: 'ffmpeg -i ./resources/video/newvideo.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" ./public/thumbs/newvideo//my_frame_1524596748522_0x0_%d.jpg' } null

Just following your documentation.
Further info:
node -v >> v9.10.1
package.json

{
  "name": "video",
  "version": "1.0.0",
  "description": "video manipulation using nodejs",
  "main": "index.js",
  "scripts": {
    "start": "babel-watch index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "node",
    "video"
  ],
  "author": "Willmer Barahona",
  "license": "ISC",
  "devDependencies": {
    "@babel/preset-env": "^7.0.0-beta.46",
    "babel-cli": "^6.26.0",
    "babel-eslint": "^8.2.3",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-es2015-node5": "^1.2.0",
    "babel-preset-stage-3": "^6.24.1",
    "babel-watch": "^2.0.7",
    "eslint": "^4.19.1",
    "ffmpeg": "0.0.4"
  },
  "dependencies": {}
}

fnExtractFrameToJPG doesn't work for me

here is my code,help me if u can

var ffmpeg = require('ffmpeg');
var path=require('path')
try{
    var process = new ffmpeg('./serviceVideo.mp4');
    process.then(function (video) {
        // Callback mode
        video.fnExtractFrameToJPG('./frames', {
            start_time : 1,
            number : 2,
            file_name : 'my_frame_%t_%s'
        }, function (error, files) {
            if (!error)
                console.log('Frames: ' + files);
        });
    }, function (err) {
        console.log('Error: ' + err);
    });

}catch(e)
{
    console.error(e)
}

Ensuring ffmpeg installation

Hi,
I wanted to use ffmpeg as part of a continuous deployment strategy.
To do that I need ffmpeg to be installed automatically.

I guess that ffmpeg installation is a prerequisite for usage of this module since it's a large file.
I'd be happy to submit a PR that ensures ffmpeg is installed on a local machine (by exposing an "ensureInstallation()" method).

For a linux machine, this might be less of a problem, since you can run apt-get on shell.
But on a windows machine, this would require downloading the ffmpeg zip file, extracting it, and exposing the ffmpeg.exe file (including the other exe files).

WDYT?

Use BufferData instead of file path?

Hi, not sure if this is the right place, but wondering if it's possible to use the buffer data from a file upload so I don't have to save the file until after ffmpeg is done working with it. Right now the user uploads a video, and I save it to a temp folder then run ffmpeg and output it to a new folder, but wondering if there was a way to streamline the process so I don't have to save the temp file.

video.save() does not support paths with spaces

Trying to call save() with a path that has a space in it results in the following (truncated):

{ [Error: Command failed: /bin/sh -c ffmpeg -i /Users/ajmas/Development/projects/VideoTools/Saved Tracks/20160412115124.MOV -f mp4 /my/output/path/20160412115124.MOV.mp4 ... /Users/ajmas/Development/projects/VideoTools/Saved: No such file or directory

The code should be adjusted to support paths with spaces in them.

Multiple metadata options

Trying to set metadata as described in https://multimedia.cx/eggs/supplying-ffmpeg-with-metadata/

file.addCommand('-metadata', `title="TestTitle"`)
file.addCommand('-metadata', `artist="TestArtist"`)

And getting this error:

Potentially unhandled rejection [1] {"code":112,"msg":"The command "-metadata" already exists"} (WARNING: non-Error used)

Shouldn't multiple -metadata options be allowed ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.