Permalink
Browse files

implemented auto-calculation of video dimensions (see readme)

  • Loading branch information...
1 parent 3d1dc20 commit da619f2db435166e11edf2f5480d021ea45e89a5 @schaermu schaermu committed Apr 15, 2011
Showing with 683 additions and 572 deletions.
  1. +3 −3 .npmignore
  2. +8 −8 LICENSE
  3. +86 −78 README.md
  4. +24 −24 examples/express-stream.js
  5. +27 −25 examples/full.js
  6. +5 −5 examples/metadata.js
  7. +11 −11 examples/preset.js
  8. +469 −371 lib/fluent-ffmpeg.js
  9. +11 −11 lib/presets/divx.js
  10. +13 −10 lib/presets/flashvideo.js
  11. +13 −13 lib/presets/podcast.js
  12. +13 −13 package.json
View
@@ -1,4 +1,4 @@
-*.md
-.git*
-test/
+*.md
+.git*
+test/
examples/
View
16 LICENSE
@@ -1,9 +1,9 @@
-(The MIT License)
-
-Copyright (c) 2011 Stefan Schaermeli <schaermu@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
+(The MIT License)
+
+Copyright (c) 2011 Stefan Schaermeli <schaermu@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
164 README.md
@@ -1,79 +1,87 @@
-# Fluent ffmpeg-API for node.js
-This library abstracts the complex command-line usage of ffmpeg into a fluent, easy to use node.js module. In order to be able to use this module, make sure you have [ffmpeg](http://www.ffmpeg.org) installed on your system (including all necessary encoding libraries like libmp3lame or libx264)
-## Installation
-Via npm:
-`$ npm install fluent-ffmpeg`
-
-Or as a submodule:
-`$ git submodule add git://github.com/schaermu/node-fluent-ffmpeg.git`
-## Usage
-You find a lot of usage examples (including a real-time streaming example using [flowplayer](http://www.flowplayer.org) and [express](https://github.com/visionmedia/express)!) in the `examples` folder.
-### Simple conversion using preset
-This example loads up a predefined preset in the preset folder (currently, fluent-ffmpeg ships with presets for DIVX, Flashvideo and Podcast conversions)
-
- var ffmpeg = require('fluent-ffmpeg');
-
- var proc = new ffmpeg('/path/to/your_movie.avi')
- .usingPreset('podcast')
- .saveToFile('/path/to/your_target.m4v', function(retcode, error){
- console.log('file has been converted succesfully');
- });
-### Conversion using chainable API
-Using the chainable API, you are able to perform any operation using FFMPEG. the most common options are implemented using methods, for more advanced usages you can still use the `addOption(s)` method group.
-
- var ffmpeg = require('fluent-ffmpeg');
-
- var proc = new ffmpeg('/path/to/your_movie.avi')
- .withVideoBitrate(1024)
- .withVideoCodec('divx')
- .withAspectRatio('16:9')
- .withFps(24)
- .withAudioBitrate('128k')
- .withAudioCodec('libmp3lame')
- .withAudioChannels(2)
- .addOption('-vtag', 'DIVX')
- .toFormat('avi')
- .saveToFile('/path/to/your_target.avi', function(retcode, error){
- console.log('file has been converted succesfully');
- });
-### Creating thumbnails from a video file
-One pretty neat feature is the ability of fluent-ffmpeg to generate any amount of thumbnails from your movies. The screenshots are taken at automatically determined timemarks using the following formula: `(duration_in_sec * 0.9) / number_of_thumbnails`.
-
- var ffmpeg = require('fluent-ffmpeg');
-
- var proc = new ffmpeg('/path/to/your_movie.avi')
- .withSize('150x100')
- .takeScreenshots(5, '/path/to/thumbnail/folder', function(err) {
- console.log('screenshots were saved')
- });
-### Reading video metadata
-Using a seperate object, you are able to access various metadata of your video file.
-
- var ffmpegmeta = require('fluent-ffmpeg').Metadata;
-
- // make sure you set the correct path to your video file
- ffmpegmeta.get('/path/to/your_movie.avi', function(metadata) {
- console.log(require('util').inspect(metadata, false, null));
- });
-## Creating a custom preset
-To create a custom preset, you have to create a new file inside the `lib/presets` folder. The filename is used as the preset's name ([presetname].js). In order to make the preset work, you have to export a `load` function using the CommonJS module specifications:
-
- exports.load = function(ffmpeg) {
- // your custom preset code
- }
-
-The `ffmpeg` parameter is a full fluent-ffmpeg object, you can use all the chaining-goodness from here on. For a good example for the possibilities using presets, check out `lib/presets/podcast.js`.
-
-## Contributing
-Contributions in any form are highly encouraged and welcome! Be it new or improved presets, optimized streaming code or just some cleanup. So start forking!
-
-## License
-(The MIT License)
-
-Copyright (c) 2011 Stefan Schaermeli &lt;schaermu@gmail.com&gt;
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
+# Fluent ffmpeg-API for node.js
+This library abstracts the complex command-line usage of ffmpeg into a fluent, easy to use node.js module. In order to be able to use this module, make sure you have [ffmpeg](http://www.ffmpeg.org) installed on your system (including all necessary encoding libraries like libmp3lame or libx264).
+## Installation
+Via npm:
+`$ npm install fluent-ffmpeg`
+
+Or as a submodule:
+`$ git submodule add git://github.com/schaermu/node-fluent-ffmpeg.git`
+## Usage
+You find a lot of usage examples (including a real-time streaming example using [flowplayer](http://www.flowplayer.org) and [express](https://github.com/visionmedia/express)!) in the `examples` folder.
+### Auto-calculation of video dimensions
+Since ffmpeg does not support dynamic sizing of your movies, fluent-ffmpeg can do this job for you (using it's internal metadata-discovery). The following size formats are allowed to be passed to `withSize`:
+
+ * `320x?` - Fixed width, calculate height
+ * `?x240` - Fixed height, calculate width
+ * `50%` - percental resizing
+ * `320x240` - fixed size (plain ffmpeg way)
+
+### Simple conversion using preset
+This example loads up a predefined preset in the preset folder (currently, fluent-ffmpeg ships with presets for DIVX, Flashvideo and Podcast conversions)
+
+ var ffmpeg = require('fluent-ffmpeg');
+
+ var proc = new ffmpeg('/path/to/your_movie.avi')
+ .usingPreset('podcast')
+ .saveToFile('/path/to/your_target.m4v', function(retcode, error){
+ console.log('file has been converted succesfully');
+ });
+### Conversion using chainable API
+Using the chainable API, you are able to perform any operation using FFMPEG. the most common options are implemented using methods, for more advanced usages you can still use the `addOption(s)` method group.
+
+ var ffmpeg = require('fluent-ffmpeg');
+
+ var proc = new ffmpeg('/path/to/your_movie.avi')
+ .withVideoBitrate(1024)
+ .withVideoCodec('divx')
+ .withAspectRatio('16:9')
+ .withFps(24)
+ .withAudioBitrate('128k')
+ .withAudioCodec('libmp3lame')
+ .withAudioChannels(2)
+ .addOption('-vtag', 'DIVX')
+ .toFormat('avi')
+ .saveToFile('/path/to/your_target.avi', function(retcode, error){
+ console.log('file has been converted succesfully');
+ });
+### Creating thumbnails from a video file
+One pretty neat feature is the ability of fluent-ffmpeg to generate any amount of thumbnails from your movies. The screenshots are taken at automatically determined timemarks using the following formula: `(duration_in_sec * 0.9) / number_of_thumbnails`.
+
+ var ffmpeg = require('fluent-ffmpeg');
+
+ var proc = new ffmpeg('/path/to/your_movie.avi')
+ .withSize('150x100')
+ .takeScreenshots(5, '/path/to/thumbnail/folder', function(err) {
+ console.log('screenshots were saved')
+ });
+### Reading video metadata
+Using a seperate object, you are able to access various metadata of your video file.
+
+ var ffmpegmeta = require('fluent-ffmpeg').Metadata;
+
+ // make sure you set the correct path to your video file
+ ffmpegmeta.get('/path/to/your_movie.avi', function(metadata) {
+ console.log(require('util').inspect(metadata, false, null));
+ });
+## Creating a custom preset
+To create a custom preset, you have to create a new file inside the `lib/presets` folder. The filename is used as the preset's name ([presetname].js). In order to make the preset work, you have to export a `load` function using the CommonJS module specifications:
+
+ exports.load = function(ffmpeg) {
+ // your custom preset code
+ }
+
+The `ffmpeg` parameter is a full fluent-ffmpeg object, you can use all the chaining-goodness from here on. For a good example for the possibilities using presets, check out `lib/presets/podcast.js`.
+
+## Contributing
+Contributions in any form are highly encouraged and welcome! Be it new or improved presets, optimized streaming code or just some cleanup. So start forking!
+
+## License
+(The MIT License)
+
+Copyright (c) 2011 Stefan Schaermeli &lt;schaermu@gmail.com&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,25 +1,25 @@
-var express = require('express'),
- ffmpeg = require('../lib/fluent-ffmpeg');
-
-var app = express.createServer();
-
-app.use(express.static(__dirname + '/flowplayer'));
-
-app.get('/', function(req, res) {
- res.send('index.html');
-});
-
-app.get('/video/:filename', function(req, res) {
- res.contentType('flv');
- // make sure you set the correct path to your video file storage
- var pathToMovie = '/path/to/storage/' + req.params.filename;
- var proc = new ffmpeg(pathToMovie)
- // use the 'flashvideo' preset (located in /lib/presets/flashvideo.js)
- .usingPreset('flashvideo')
- // save to stream
- .writeToStream(res, function(retcode, error){
- console.log('file has been converted succesfully');
- });
-});
-
+var express = require('express'),
+ ffmpeg = require('../lib/fluent-ffmpeg');
+
+var app = express.createServer();
+
+app.use(express.static(__dirname + '/flowplayer'));
+
+app.get('/', function(req, res) {
+ res.send('index.html');
+});
+
+app.get('/video/:filename', function(req, res) {
+ res.contentType('flv');
+ // make sure you set the correct path to your video file storage
+ var pathToMovie = '/path/to/storage/' + req.params.filename;
+ var proc = new ffmpeg(pathToMovie)
+ // use the 'flashvideo' preset (located in /lib/presets/flashvideo.js)
+ .usingPreset('flashvideo')
+ // save to stream
+ .writeToStream(res, function(retcode, error){
+ console.log('file has been converted succesfully');
+ });
+});
+
app.listen(4000);
View
@@ -1,26 +1,28 @@
-var ffmpeg = require('../lib/fluent-ffmpeg');
-
-// make sure you set the correct path to your video file
-var proc = new ffmpeg('/path/to/your_movie.avi')
- // set video bitrate
- .withVideoBitrate(1024)
- // set target codec
- .withVideoCodec('divx')
- // set aspect ratio
- .withAspectRatio('16:9')
- // set fps
- .withFps(24)
- // set audio bitrate
- .withAudioBitrate('128k')
- // set audio codec
- .withAudioCodec('libmp3lame')
- // set number of audio channels
- .withAudioChannels(2)
- // set custom option
- .addOption('-vtag', 'DIVX')
- // set output format to force
- .toFormat('avi')
- // save to file
- .saveToFile('/path/to/your_target.avi', function(retcode, error){
- console.log('file has been converted succesfully');
+var ffmpeg = require('../lib/fluent-ffmpeg');
+
+// make sure you set the correct path to your video file
+var proc = new ffmpeg('/path/to/your_movie.avi')
+ // set video bitrate
+ .withVideoBitrate(1024)
+ // set target codec
+ .withVideoCodec('divx')
+ // set aspect ratio
+ .withAspectRatio('16:9')
+ // set size in percent
+ .withSize('50%')
+ // set fps
+ .withFps(24)
+ // set audio bitrate
+ .withAudioBitrate('128k')
+ // set audio codec
+ .withAudioCodec('libmp3lame')
+ // set number of audio channels
+ .withAudioChannels(2)
+ // set custom option
+ .addOption('-vtag', 'DIVX')
+ // set output format to force
+ .toFormat('avi')
+ // save to file
+ .saveToFile('/path/to/your_target.avi', function(retcode, error){
+ console.log('file has been converted succesfully');
});
View
@@ -1,6 +1,6 @@
-var ffmpegmeta = require('../lib/fluent-ffmpeg').Metadata;
-
-// make sure you set the correct path to your video file
-ffmpegmeta.get('/path/to/your_movie.avi', function(metadata) {
- console.log(require('util').inspect(metadata, false, null));
+var ffmpegmeta = require('../lib/fluent-ffmpeg').Metadata;
+
+// make sure you set the correct path to your video file
+ffmpegmeta.get('/path/to/your_movie.avi', function(metadata) {
+ console.log(require('util').inspect(metadata, false, null));
});
View
@@ -1,12 +1,12 @@
-var ffmpeg = require('../lib/fluent-ffmpeg');
-
-// make sure you set the correct path to your video file
-var proc = new ffmpeg('/path/to/your_movie.avi')
- // use the 'podcast' preset (located in /lib/presets/podcast.js)
- .usingPreset('podcast')
- // in case you want to override the preset's setting, just keep chaining
- .withVideoBitrate('512k')
- // save to file
- .saveToFile('/path/to/your_target.m4v', function(retcode, error){
- console.log('file has been converted succesfully');
+var ffmpeg = require('../lib/fluent-ffmpeg');
+
+// make sure you set the correct path to your video file
+var proc = new ffmpeg('/path/to/your_movie.avi')
+ // use the 'podcast' preset (located in /lib/presets/podcast.js)
+ .usingPreset('podcast')
+ // in case you want to override the preset's setting, just keep chaining
+ .withVideoBitrate('512k')
+ // save to file
+ .saveToFile('/path/to/your_target.m4v', function(retcode, error){
+ console.log('file has been converted succesfully');
});
Oops, something went wrong.

0 comments on commit da619f2

Please sign in to comment.