Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added posibility to provide additional settings for ffmpeg subtitles #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var defaults = exports.defaults = {
audioChannels: 2,
format: 'mp4',
useSubripSubtitles: false,
subtitleStyle: null
subtitleStyle: null,
subtitleOptions: null,
}

exports.define = function (options) {
Expand Down
35 changes: 24 additions & 11 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,16 @@ function renderVideo(videoshow, options, forwardEvent, cb) {
})

if (subtitles) {
options.push('-vf subtitles=\'' + subtitles + '\'')
const subtitleOptions = [
'\'' + subtitles + '\'',
]
if (params.subtitleOptions) {
Object.keys(params.subtitleOptions).forEach(key => {
subtitleOptions.push(key + '=' + '\'' + params.subtitleOptions[key] + '\'');
});
}

options.push(`-vf subtitles=` + subtitleOptions.join(':'))
}

if (videoOptions.pixelFormat) {
Expand Down Expand Up @@ -222,15 +231,15 @@ function getImageSubtitles(videoshow) {

var length = 0
var subtitles = videoshow.images
.map(function (image, index) {
var offset = calculateOffsetDelay(index)
if (image.caption) {
return renderCaption(image, length++, offset, params)
}
})
.filter(function (caption) {
return caption != null
})
.map(function (image, index) {
var offset = calculateOffsetDelay(index)
if (image.caption) {
return renderCaption(image, length++, offset, params)
}
})
.filter(function (caption) {
return caption != null
})

if (!subtitles.length) {
return
Expand All @@ -240,7 +249,11 @@ function getImageSubtitles(videoshow) {
extension = '.srt'
subtitles = subrip.stringify(subtitles)
} else {
subtitles = substation.stringify(subtitles, params.subtitleStyle)
subtitles = substation.stringify(subtitles, {
'V4 Styles': {
'Style': params.subtitleStyle,
}
})
}

filepath = randomName() + extension
Expand Down
9 changes: 4 additions & 5 deletions lib/substation.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ var defaultParams = {
}
}

exports.stringify = function (captions, styles) {
var params = mergeParams(styles)
exports.stringify = function (captions, params) {
var params = mergeParams(params)

captions.forEach(function (caption) {
var subtitle = merge({}, captionParams, {
Expand All @@ -103,9 +103,8 @@ exports.stringify = function (captions, styles) {
return substation(params)
}

function mergeParams(styles) {
var params = merge({}, defaultParams)
merge(params['V4 Styles'].Style, styles)
function mergeParams(params) {
var params = merge({}, defaultParams, params);

return Object.keys(params).map(function (key) {
var body = params[key]
Expand Down