Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
node-thumbnails-webvtt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Göttlich
node-thumbnails-webvtt
Commits
dc985e83
Commit
dc985e83
authored
Jul 01, 2014
by
Alexander Makarenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introduce secondsPerThumbnail and framesPerThumbnail
parent
2ee20c28
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
8 deletions
+52
-8
README.md
README.md
+9
-1
index.js
lib/index.js
+41
-6
utils.js
lib/utils.js
+2
-1
No files found.
README.md
View file @
dc985e83
...
...
@@ -89,10 +89,18 @@ Create thumbnails (and optionally pack them into spritesheet) and create WebVTT
* Array with timemarks in seconds. E.g. ['123.123', '345.345']
*
**numThumbnails**
defaults to
`
null
`
*
**numThumbnails**
defaults to
`
0
`
* Number of thumbnails to generate. Used in opposite to `timemarks`. Each thumbnail moment is calculated as `source_duration * 0.9 / numThumbnails`.
*
**secondsPerThumbnail**
defaults to
`0`
* If specified thumbnails will be generated each `secondsPerThumbnail` seconds.
*
**framesPerThumbnail**
defaults to
`0`
* If specified thumbnails will be generated each `framesPerThumbnail` frames.
*
**spritesheet**
defaults to
`false`
* Generate spritesheet or not.
...
...
lib/index.js
View file @
dc985e83
...
...
@@ -27,8 +27,8 @@ module.exports = function(source, options, callback) {
if
(
!
source
)
{
return
callback
(
new
Error
(
'Source video file is not specified'
))
}
else
if
(
!
options
.
numThumbnails
&&
!
options
.
timemarks
)
{
return
callback
(
new
Error
(
'You should specify
either timemarks or number of thumbnails to generate
'
))
else
if
(
!
options
.
numThumbnails
&&
!
options
.
secondsPerThumbnail
&&
!
options
.
framesPerThumbnail
&&
!
options
.
timemarks
)
{
return
callback
(
new
Error
(
'You should specify
the way timemarks are calculated
'
))
}
var
sourceExt
=
path
.
extname
(
source
)
...
...
@@ -58,18 +58,53 @@ module.exports = function(source, options, callback) {
metadata
=
data
if
(
!
options
.
timemarks
)
{
var
diff
=
metadata
.
duration
*
0.9
/
options
.
numThumbnails
,
i
=
0
options
.
timemarks
=
[]
}
options
.
bounds
=
[]
var
mark
,
i
=
0
if
(
options
.
timemarks
.
length
)
{
i
=
0
while
(
mark
=
options
.
timemarks
[
i
++
])
{
options
.
bounds
.
push
(
mark
)
}
}
else
if
(
options
.
numThumbnails
)
{
var
diff
=
metadata
.
duration
*
0.9
/
options
.
numThumbnails
i
=
0
while
(
i
<
options
.
numThumbnails
)
{
options
.
bounds
.
push
(
Number
(
i
*
diff
).
toFixed
(
3
))
options
.
timemarks
.
push
(
Number
(
i
*
diff
+
diff
/
2
).
toFixed
(
3
))
i
++
}
}
else
if
(
options
.
secondsPerThumbnail
)
{
mark
=
0
while
(
mark
<
metadata
.
duration
)
{
options
.
bounds
.
push
(
Number
(
mark
).
toFixed
(
3
))
options
.
timemarks
.
push
(
Number
(
mark
).
toFixed
(
3
))
mark
+=
options
.
secondsPerThumbnail
}
}
else
if
(
options
.
framesPerThumbnail
)
{
mark
=
0
while
(
mark
<
metadata
.
duration
)
{
options
.
bounds
.
push
(
Number
(
mark
).
toFixed
(
3
))
options
.
timemarks
.
push
(
Number
(
mark
).
toFixed
(
3
))
if
(
!
metadata
.
fps
)
{
return
callback
(
new
Error
(
'Can
\'
t determine video FPS.'
))
}
mark
+=
options
.
framesPerThumbnail
/
metadata
.
fps
}
}
if
(
!
options
.
size
)
{
options
.
size
=
{
...
...
lib/utils.js
View file @
dc985e83
...
...
@@ -80,7 +80,8 @@ exports.metadata = function(source, callback) {
return
callback
(
null
,
{
duration
:
parseFloat
(
metadata
.
format
.
duration
),
width
:
parseInt
(
stream
.
width
,
10
),
height
:
parseInt
(
stream
.
height
,
10
)
height
:
parseInt
(
stream
.
height
,
10
),
fps
:
parseInt
((
stream
.
r_frame_rate
||
stream
.
avg_frame_rate
).
replace
(
/
\/
1/
,
''
),
10
)
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment