grunt-ffmpeg

Grunt task to wrap ffmpeg

grunt-ffmpeg

Grunt task to wrap ffmpeg using node-fluent-ffmpeg

You need FFmpeg >= 0.9 installed to work with this plugin. Read about it here

npm install grunt-ffmpeg --save-dev

Type: Boolien
Default: false

debug mode (now only for displaying ffmpeg command)

Type: String
Default: undefined
Example: '1000k' - 1000 kbps

Generated video bitrate

Type: String
Default: undefined
Example: '64k' - 64 kbps

Generated audio bitrate

Type: String
Default: undefined (don't chage size)
Example: '800x600'

Generated video size WIDTH x HEIGHT

Type: Object
Default: undefined
Example:

{
  withAudioChannels: 1
}

Object of extra node-fluent-ffmpeg options. Full list here You can merge FFmpegOptions from options and actual task config:

ffmpeg: {
  options: {
    FFmpegOptions: {
      withVideoCodec: 'libx624',
      withAudioChannels: 2
    }
  },
  compile: {
    options: {
      FFmpegOptions: {
        withAudioChannels: 1,
        withAspectRatio: 1.33
      }
    },
    files: [...]
  }
}

With this config compile task will have this FFmpegOptions:

FFmpegOptions: {
  withVideoCodec: 'libx624', // from options 
  withAudioChannels: 1, // merge task.options with options 
  withAspectRatio: 1.33 // from task.options 
}

Type: Function
Default: undefined

input: String input file name
ouptut: String output file name

Triggers when single file decoding is finished

Type: Function
Default: undefined

err: String error message
input: String input file name
ouptut: String output file name

Triggers when single file decoding has an error

Type: Function
Default: undefined

data: Object codec data object
input: String input file name

Triggers on single file and give codec info object

Generate *.mp4 files from *.avi and *.flv source files

grunt.initConfig({
  ffmpeg: {
    video: {
      files: [{
        expand: true,
        cwd: 'video_source',
        src: ['*.avi', '*.flv'],
        dest: 'dist',
        ext: '.mp4'
      }]
    }
  }
});
 
grunt.loadNpmTasks('grunt-ffmpeg');
grunt.registerTask('default', ['ffmpeg']);

Generate *.ogg and *.mp3 files from *.wav source files

grunt.initConfig({
  ffmpeg: {
    audio: {
      files: [{
        expand: true,
        cwd: 'test/assets',
        src: ['*.wav'],
        dest: 'dist',
        ext: '.ogg'
      },{
        expand: true,
        cwd: 'test/assets',
        src: ['*.wav'],
        dest: 'dist',
        ext: '.mp3'
      }]
    }
  }
});
 
grunt.loadNpmTasks('grunt-ffmpeg');
grunt.registerTask('default', ['ffmpeg']);

Generate *.ogg and *.mp3 files from *.wav source files

grunt.initConfig({
  ffmpeg: {
    compile: {
      options: {
        videoBitrate: '1000k',
        audioBitrate: '64k',
        size: '1920x1080',
 
        onEndfunction (inputoutput) {
          console.log(input + ' -> ' + output);
        },
        onErrorfunction (errorinputoutput) {
          console.log('error on: ' + input + ' ['+ error +']');
        },
        onCodecDatafunction (datainput) {
          console.log(input + ' input is ' + data.audio + ' audio with ' + data.video + ' video');
        },
        FFmpegOptions: {
          // Specify video codec 
          withVideoCodec: 'libx624'
 
          // Auto-pad video, defaulting to black padding 
          applyAutopadding: true
 
          // Set aspect ratio 
          withAspectRatio: 1.33
 
          // Keep aspect ratio 
          keepPixelAspect: true
 
          // more at https://github.com/schaermu/node-fluent-ffmpeg#supplying-ffmpeg-options 
        }
      },
      files: [{
        expand: true,
        cwd: 'test/assets',
        src: ['*.avi', '*.flv'],
        dest: 'dist',
        ext: '.mp4'
      },{
        expand: true,
        cwd: 'test/assets',
        src: ['*.avi', '*.flv'],
        dest: 'dist',
        ext: '.webm'
      }]
    },
  }
});

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

  • #1 Add feature to merge options.FFmpegOptions with task.options.FFmpegOptions
  • init release

Copyright (c) 2014 Licensed under the MIT license.