{"id":13526429,"url":"https://github.com/damianociarla/node-ffmpeg","last_synced_at":"2025-05-15T10:07:04.598Z","repository":{"id":5629800,"uuid":"6837925","full_name":"damianociarla/node-ffmpeg","owner":"damianociarla","description":"ffmpeg module for nodejs","archived":false,"fork":false,"pushed_at":"2022-11-09T05:40:55.000Z","size":47,"stargazers_count":611,"open_issues_count":65,"forks_count":140,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-14T16:56:09.808Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/damianociarla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-24T08:52:01.000Z","updated_at":"2025-02-11T23:35:32.000Z","dependencies_parsed_at":"2023-01-13T13:38:01.812Z","dependency_job_id":null,"html_url":"https://github.com/damianociarla/node-ffmpeg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianociarla%2Fnode-ffmpeg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianociarla%2Fnode-ffmpeg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianociarla%2Fnode-ffmpeg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianociarla%2Fnode-ffmpeg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damianociarla","download_url":"https://codeload.github.com/damianociarla/node-ffmpeg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:29.578Z","updated_at":"2025-05-15T10:06:59.576Z","avatar_url":"https://github.com/damianociarla.png","language":"JavaScript","readme":"node-ffmpeg\n===========\n\n[FFmpeg](http://ffmpeg.org/) module for [Node](http://nodejs.org/). 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)\n\nYou can install this module using [npm](http://github.com/isaacs/npm):\n\n\tnpm install ffmpeg\n\n## Usage\n\nTo start using this library, you must include it in your project and then you can either use the callback function or through the [promise](https://github.com/cujojs/when) library:\n\n\tvar ffmpeg = require('ffmpeg');\n\t\nUse the callback function\n```js\n\ttry {\n\t\tnew ffmpeg('/path/to/your_movie.avi', function (err, video) {\n\t\t\tif (!err) {\n\t\t\t\tconsole.log('The video is ready to be processed');\n\t\t\t} else {\n\t\t\t\tconsole.log('Error: ' + err);\n\t\t\t}\n\t\t});\n\t} catch (e) {\n\t\tconsole.log(e.code);\n\t\tconsole.log(e.msg);\n\t}\n```\t\nUse the approach with the library promise\n```js\n\ttry {\n\t\tvar process = new ffmpeg('/path/to/your_movie.avi');\n\t\tprocess.then(function (video) {\n\t\t\tconsole.log('The video is ready to be processed');\n\t\t}, function (err) {\n\t\t\tconsole.log('Error: ' + err);\n\t\t});\n\t} catch (e) {\n\t\tconsole.log(e.code);\n\t\tconsole.log(e.msg);\n\t}\n```\t\n## The video object\n\nEach 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:\n```js\n\ttry {\n\t\tvar process = new ffmpeg('/path/to/your_movie.avi');\n\t\tprocess.then(function (video) {\n\t\t\t// Video metadata\n\t\t\tconsole.log(video.metadata);\n\t\t\t// FFmpeg configuration\n\t\t\tconsole.log(video.info_configuration);\n\t\t}, function (err) {\n\t\t\tconsole.log('Error: ' + err);\n\t\t});\n\t} catch (e) {\n\t\tconsole.log(e.code);\n\t\tconsole.log(e.msg);\n\t}\n```\t\n## Preset functions\n\nThe 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\n\n### *video.fnExtractSoundToMP3 (destionationFileName, callback)*\n\nThis function extracts the audio stream of a video into an mp3 file\n\nParams:\n\n*\t__destionationFileName__: Full path of the new file:\n\t\u003e /path/to/your_audio_file.mp3\n\n*\t__callback__: *(optional)* If specified at the end of the process it will return the path of the new audio file:\n\t\u003e function (error, file)\n\nExample:\n```js\n\ttry {\n\t\tvar process = new ffmpeg('/path/to/your_movie.avi');\n\t\tprocess.then(function (video) {\n\t\t\t// Callback mode\n\t\t\tvideo.fnExtractSoundToMP3('/path/to/your_audio_file.mp3', function (error, file) {\n\t\t\t\tif (!error)\n\t\t\t\t\tconsole.log('Audio file: ' + file);\n\t\t\t});\n\t\t}, function (err) {\n\t\t\tconsole.log('Error: ' + err);\n\t\t});\n\t} catch (e) {\n\t\tconsole.log(e.code);\n\t\tconsole.log(e.msg);\n\t}\n```\n### *video.fnExtractFrameToJPG(destinationFolder, settings, callback)*\n\nThis 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\n\nParams:\n\n*\t__destinationFolder__: Destination folder for the frames generated:\n\t\u003e /path/to/save_your_frames\n\n*\t__settings__: *(optional)* Settings to change the default settings:\n```js\n\t\t{\n\t\t\tstart_time\t\t\t\t: null\t\t// Start time to recording\n\t\t  , duration_time\t\t\t: null\t\t// Duration of recording\n\t\t  , frame_rate\t\t\t\t: null\t\t// Number of the frames to capture in one second\n\t\t  , size\t\t\t\t\t: null\t\t// Dimension each frame\n\t\t  , number\t\t\t\t\t: null\t\t// Total frame to capture\n\t\t  , every_n_frames\t\t\t: null\t\t// Frame to capture every N frames\n\t\t  , every_n_seconds\t\t\t: null\t\t// Frame to capture every N seconds\n\t\t  , every_n_percentage\t\t: null\t\t// Frame to capture every N percentage range\n\t\t  , keep_pixel_aspect_ratio\t: true\t\t// Mantain the original pixel video aspect ratio\n\t\t  , keep_aspect_ratio\t\t: true\t\t// Mantain the original aspect ratio\n\t\t  , padding_color\t\t\t: 'black'\t// Padding color\n\t\t  , file_name\t\t\t\t: null\t\t// File name\n\t\t}\n```\n*\t__callback__: *(optional)* If specified at the end of the process will be returned list of paths of frames created:\n\t\u003e function (error, files)\n\nExample:\n```js\n\ttry {\n\t\tvar process = new ffmpeg('/path/to/your_movie.avi');\n\t\tprocess.then(function (video) {\n\t\t\t// Callback mode\n\t\t\tvideo.fnExtractFrameToJPG('/path/to/save_your_frames', {\n\t\t\t\tframe_rate : 1,\n\t\t\t\tnumber : 5,\n\t\t\t\tfile_name : 'my_frame_%t_%s'\n\t\t\t}, function (error, files) {\n\t\t\t\tif (!error)\n\t\t\t\t\tconsole.log('Frames: ' + files);\n\t\t\t});\n\t\t}, function (err) {\n\t\t\tconsole.log('Error: ' + err);\n\t\t});\n\t} catch (e) {\n\t\tconsole.log(e.code);\n\t\tconsole.log(e.msg);\n\t}\n```\n### *video.fnAddWatermark(watermarkPath, newFilepath, settings, callback)* \n\nThis 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\n\nParams:\n\n*\t__watermarkPath__: The full path where the image is stored to add as watermark:\n\t\u003e /path/to/retrieve/watermark_file.png\n\n*\t__newFilepath__: *(optional)* Name of the new video. If not specified will be created by the function:\n\t\u003e /path/to/save/your_file_video.mp4\n\n*\t__settings__: *(optional)* Settings to change the default settings:\n```js\n\t\t{\n\t\t\tposition\t\t: \"SW\"\t\t// Position: NE NC NW SE SC SW C CE CW\n\t\t  , margin_nord\t\t: null\t\t// Margin nord\n\t\t  , margin_sud\t\t: null\t\t// Margin sud\n\t\t  , margin_east\t\t: null\t\t// Margin east\n\t\t  , margin_west\t\t: null\t\t// Margin west\n\t\t};\n```\n*\t__callback__: *(optional)* If specified at the end of the process it will return the path of the new video containing the watermark:\n\t\u003e function (error, files)\n\nExample:\n```js\n\ttry {\n\t\tvar process = new ffmpeg('/path/to/your_movie.avi');\n\t\tprocess.then(function (video) {\n\t\t\t// Callback mode\n\t\t\tvideo.fnAddWatermark('/path/to/retrieve/watermark_file.png', '/path/to/save/your_file_video.mp4', {\n\t\t\t\tposition : 'SE'\n\t\t\t}, function (error, file) {\n\t\t\t\tif (!error)\n\t\t\t\t\tconsole.log('New video file: ' + file);\n\t\t\t});\n\t\t}, function (err) {\n\t\t\tconsole.log('Error: ' + err);\n\t\t});\n\t} catch (e) {\n\t\tconsole.log(e.code);\n\t\tconsole.log(e.msg);\n\t}\n```\n## Custom settings\n\nIn 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\n\n*\t__video.setDisableAudio()__: Disables audio encoding\n\n*\t__video.setDisableVideo()__: Disables video encoding\n\n*\t__video.setVideoFormat(format)__: Sets the new video format. Example:\n\t\t\n\t\tvideo.setVideoFormat('avi')\n\n*\t__video.setVideoCodec(codec)__: Sets the new audio codec. Example:\n\t\n\t\tvideo.setVideoCodec('mpeg4')\n\n*\t__video.setVideoBitRate(bitrate)__: Sets the video bitrate in kb. Example:\n\t\n\t\tvideo.setVideoBitRate(1024)\n\n*\t__video.setVideoFrameRate(framerate)__: Sets the framerate of the video. Example:\n\t\n\t\tvideo.setVideoFrameRate(25)\n\n*\t__video.setVideoStartTime(time)__: Sets the start time. You can specify the value in seconds or in date time format. Example:\n```js\t\n\t\t// Seconds\n\t\tvideo.setVideoStartTime(13)\n\n\t\t// Date time format\n\t\tvideo.setVideoStartTime('00:00:13')\n```\n*\t__video.setVideoDuration(duration)__: Sets the duration. You can specify the value in seconds or in date time format. Example:\n```js\t\n\t\t// Seconds\n\t\tvideo.setVideoDuration(100)\n\n\t\t// Date time format\n\t\tvideo.setVideoDuration('00:01:40')\n```\n*\t__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:\n```js\t\n\t\t// Value\n\t\tvideo.setVideoAspectRatio(1.77)\n\n\t\t// Format xx:xx\n\t\tvideo.setVideoAspectRatio('16:9')\n```\n*\t__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\n\t\n\tThe following size formats are allowed to be passed to _size_:\n\n\t\u003e 640x480 _Fixed size (plain ffmpeg way)_\n\n\t\u003e 50% _Percental resizing_\n\n\t\u003e ?x480 _Fixed height, calculate width_\n\n\t\u003e 640x? _Fixed width, calculate height_\n\n\tExample:\n```js\t\n\t\t// In this example, the video will be automatically resized to 640 pixels wide and will apply a padding white\n\t\tvideo.setVideoSize('640x?', true, true, '#fff')\n\n\t\t// In this example, the video will be resized to 640x480 pixel, and if the aspect ratio is different the video will be stretched\n\t\tvideo.setVideoSize('640x480', true, false)\n```\n*\t__video.setAudioCodec(codec)__: Sets the new audio codec. Example:\n\t\n\t\tvideo.setAudioCodec('libfaac')\n\n*\t__video.setAudioFrequency(frequency)__: Sets the audio sample frequency for audio outputs in kb. Example:\n\t\n\t\tvideo.setAudioFrequency(48)\n\n*\t__video.setAudioChannels(channel)__: Sets the number of audio channels. Example:\n\t\n\t\tvideo.setAudioChannels(2)\n\n*\t__video.setAudioBitRate(bitrate)__: Sets the audio bitrate in kb. Example:\n\t\n\t\tvideo.setAudioBitRate(128)\n\n*\t__video.setAudioQuality(quality)__: Sets the audio quality. Example:\n\t\n\t\tvideo.setAudioQuality(128)\n\n*\t__video.setWatermark(watermarkPath, settings)__: Sets the watermark. You must specify the path where the image is stored to be inserted as watermark\n\t\n\tThe possible settings (the values ​​shown are the default):\n\n\t*\t**position : \"SW\"** \n\t\t\n\t\tPosition: NE NC NW SE SC SW C CE CW\n\n\t*\t**margin_nord : null** \n\n\t\tMargin nord (specify in pixel)\n\n\t*\t**margin_sud : null** \n\n\t\tMargin sud (specify in pixel)\n\n\t*\t**margin_east : null** \n\n\t\tMargin east (specify in pixel)\n\n\t*\t**margin_west : null** \n\n\t\tMargin west (specify in pixel)\n\n\tExample:\n\n\t\t// In this example will be added the watermark at the bottom right of the video\n\t\tvideo.setWatermark('/path/to/retrieve/watermark_file.png')\n\n## Add custom options\n\nIf the ffmpeg parameters are not present in the list of available function you can add it manually through the following function\n\n**video.addCommand(command, argument)**\n\nExample:\n```js\t\n\t// In this example will be changed the output to avi format\n\tvideo.addCommand('-f', 'avi');\n```\n## Save the file\n\nAfter 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.\n\n**video.save(destionationFileName, callback)**\n\nExample:\n```js\t\n\ttry {\n\t\tvar process = new ffmpeg('/path/to/your_movie.avi');\n\t\tprocess.then(function (video) {\n\t\t\t\n\t\t\tvideo\n\t\t\t.setVideoSize('640x?', true, true, '#fff')\n\t\t\t.setAudioCodec('libfaac')\n\t\t\t.setAudioChannels(2)\n\t\t\t.save('/path/to/save/your_movie.avi', function (error, file) {\n\t\t\t\tif (!error)\n\t\t\t\t\tconsole.log('Video file: ' + file);\n\t\t\t});\n\n\t\t}, function (err) {\n\t\t\tconsole.log('Error: ' + err);\n\t\t});\n\t} catch (e) {\n\t\tconsole.log(e.code);\n\t\tconsole.log(e.msg);\n\t}\n```\n","funding_links":[],"categories":["Repository"],"sub_categories":["Audio / Video"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamianociarla%2Fnode-ffmpeg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamianociarla%2Fnode-ffmpeg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamianociarla%2Fnode-ffmpeg/lists"}