Skip to content

Commit

Permalink
Added vaapi support (#29)
Browse files Browse the repository at this point in the history
* Added vaapi hwaccel params
Included hwaccel params if vaapi selected.

* Added check for bitrate with hwaccel
hwaccel does not support quality-based setting, only bitrate
  • Loading branch information
dravenst authored Feb 9, 2022
1 parent 4f67c79 commit 81bf3b4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ This is not compatible with the `quality` option.
opts = { bitrate: '1200k' }
```

##### HW acceleration

Enable VAAPI HW accleration if supported on your platform (typically Intel/AMD chipsets.)
Requires intel-media-driver package to enable.
This is not compatiable with the `quality` option and requires a `bitrate` setting.
The default value is `none`

```js
// values 'vaapi' or 'none'
opts = { video-hwaccel: 'vaapi' }
```

##### Conversion progress

The `.video()` call returns an [EventEmitter](https://nodejs.org/api/events.html)
Expand Down
22 changes: 19 additions & 3 deletions lib/video/ffargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ const ENCODER_CRF = {
}

exports.prepare = function (source, target, options) {
// output framerate
const args = ['-y']

// IF VAAPI acceleration needs to go before -i input files
if ((options.bitrate) && (options.hwaccel === 'vaapi')) {
args.push('-hwaccel_device', '/dev/dri/renderD128', '-hwaccel', 'vaapi', '-hwaccel_output_format', 'vaapi')
}

// source file
const args = ['-i', source]
args.push('-i', source)

// output framerate
args.push('-r', DEFAULT_VIDEO_FPS)
Expand All @@ -27,7 +35,12 @@ exports.prepare = function (source, target, options) {
if (options.format === 'webm') {
args.push('-f', 'webm', '-vcodec', 'libvpx-vp9', '-strict', '-2')
} else {
args.push('-f', 'mp4', '-vcodec', 'libx264')
args.push('-f', 'mp4')
if ((options.bitrate) && (options.hwaccel === 'vaapi')) {
args.push('-c:v', 'h264_vaapi') // if VAAPI available
} else {
args.push('-vcodec', 'libx264')
}
}

// set average video bitrate or perceptual quality
Expand All @@ -43,10 +56,13 @@ exports.prepare = function (source, target, options) {
// AVCHD/MTS videos need a full-frame export to avoid interlacing artefacts
if (path.extname(source).toLowerCase() === '.mts') {
args.push('-vf', 'yadif=1')
} else if ((options.bitrate) && (options.hwaccel === 'vaapi')) {
// if VAAPI + here you to add the scaling option too ",scale_vaapi=1280:-1"
args.push('-vf', 'format=nv12|vaapi,hwupload')
}

// target filename
args.push('-y', target)
args.push(target)

return args
}
Expand Down

0 comments on commit 81bf3b4

Please sign in to comment.