mediasnacks 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -7
- package/index.js +18 -0
- package/package.json +16 -7
- package/src/avif.js +18 -27
- package/src/cli.js +45 -37
- package/src/countframes.js +57 -0
- package/src/detectdups.js +12 -22
- package/src/dropdups.js +2 -10
- package/src/edgespic.js +7 -17
- package/src/frameseq.js +69 -0
- package/src/hev1tohvc1.js +13 -19
- package/src/moov2front.js +12 -21
- package/src/{random.js → openrand.js} +8 -10
- package/src/play.js +2 -8
- package/src/prores.js +22 -26
- package/src/qdir.js +1 -10
- package/src/resize.js +25 -29
- package/src/seqcheck.js +16 -18
- package/src/sqcrop.js +17 -25
- package/src/ssim.js +1 -9
- package/src/utils/parseOptions.js +1 -0
- package/src/utils/parseTimecode.js +16 -0
- package/src/utils/subprocess.js +1 -93
- package/src/utils/videoAttrs.js +91 -0
- package/src/vsplit.js +2 -8
- package/src/vtrim.js +7 -10
package/README.md
CHANGED
|
@@ -10,12 +10,6 @@ Utilities video and images.
|
|
|
10
10
|
npm install -g mediasnacks
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Optionally, if you have `ignore-scripts=true` in your `.npmprc`,
|
|
14
|
-
you can install zsh auto-completions with:
|
|
15
|
-
```sh
|
|
16
|
-
$(npm root -g)/mediasnacks/install-zsh-completions.js
|
|
17
|
-
```
|
|
18
|
-
|
|
19
13
|
|
|
20
14
|
|
|
21
15
|
## Overview
|
|
@@ -32,6 +26,8 @@ mediasnacks <command> <args>
|
|
|
32
26
|
|
|
33
27
|
- `resize` Resizes videos or images
|
|
34
28
|
- `edgespic` Extracts first and last frames
|
|
29
|
+
- `frameseq` Converts video to sequence of PNGs
|
|
30
|
+
- `countframes` Counts frames in a video
|
|
35
31
|
- `ssim` Computes similarity of two images
|
|
36
32
|
- `gif`: Video to GIF
|
|
37
33
|
|
|
@@ -51,7 +47,7 @@ mediasnacks <command> <args>
|
|
|
51
47
|
- `flattendir`: Moves unique files to the top dir and deletes empty dirs
|
|
52
48
|
- `qdir` Sequentially runs all *.sh files in a folder
|
|
53
49
|
- `seqcheck` Finds missing sequence number
|
|
54
|
-
- `
|
|
50
|
+
- `openrand` Opens a random file
|
|
55
51
|
- `play` Plays filtered playlist with mpv
|
|
56
52
|
|
|
57
53
|
|
package/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { avif } from './src/avif.js'
|
|
2
|
+
export { countframes } from './src/countframes.js'
|
|
3
|
+
export { detectdups } from './src/detectdups.js'
|
|
4
|
+
export { dropdups } from './src/dropdups.js'
|
|
5
|
+
export { edgespic } from './src/edgespic.js'
|
|
6
|
+
export { frameseq } from './src/frameseq.js'
|
|
7
|
+
export { hev1tohvc1 } from './src/hev1tohvc1.js'
|
|
8
|
+
export { moov2front } from './src/moov2front.js'
|
|
9
|
+
export { play } from './src/play.js'
|
|
10
|
+
export { prores } from './src/prores.js'
|
|
11
|
+
export { qdir } from './src/qdir.js'
|
|
12
|
+
export { openrand, pickRandomFile } from './src/openrand.js'
|
|
13
|
+
export { resize } from './src/resize.js'
|
|
14
|
+
export { seqcheck } from './src/seqcheck.js'
|
|
15
|
+
export { sqcrop } from './src/sqcrop.js'
|
|
16
|
+
export { ssim } from './src/ssim.js'
|
|
17
|
+
export { vsplit } from './src/vsplit.js'
|
|
18
|
+
export { vtrim } from './src/vtrim.js'
|
package/package.json
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
"name": "mediasnacks",
|
|
3
|
+
"version": "0.26.0",
|
|
4
|
+
"description": "Utilities for optimizing and preparing videos and images",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Eric Fortis",
|
|
7
|
+
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
9
|
"mediasnacks": "src/cli.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"test": "
|
|
12
|
+
"test": "FORCE_COLOR=1 node --test",
|
|
13
|
+
"test-docker": "docker run --rm $(docker build -q .)",
|
|
13
14
|
"postinstall": "node install-zsh-completions.js",
|
|
14
15
|
"dev-install": "npm i -g . --ignore-scripts=false"
|
|
15
16
|
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./index.js",
|
|
20
|
+
"types": "./index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
16
23
|
"files": [
|
|
17
24
|
"src",
|
|
25
|
+
"index.js",
|
|
26
|
+
"index.d.js",
|
|
18
27
|
"install-zsh-completions.js"
|
|
19
28
|
]
|
|
20
29
|
}
|
package/src/avif.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import { join, basename, dirname } from 'node:path'
|
|
3
2
|
import { parseOptions } from './utils/parseOptions.js'
|
|
4
3
|
import { replaceExt, lstat } from './utils/fs-utils.js'
|
|
@@ -7,22 +6,22 @@ import { ffmpeg, assertUserHasFFmpeg } from './utils/subprocess.js'
|
|
|
7
6
|
|
|
8
7
|
const HELP = `
|
|
9
8
|
SYNOPSIS
|
|
10
|
-
mediasnacks avif [-y | --overwrite] [--
|
|
9
|
+
mediasnacks avif [-y | --overwrite] [--outdir=<dir>] <images>
|
|
11
10
|
|
|
12
11
|
DESCRIPTION
|
|
13
12
|
Converts images to AVIF.
|
|
14
13
|
|
|
15
14
|
EXAMPLES
|
|
16
15
|
mediasnacks avif -y '*.png'
|
|
17
|
-
mediasnacks avif --
|
|
16
|
+
mediasnacks avif --outdir=foo/ 'a/**/*.png'
|
|
18
17
|
`.trim()
|
|
19
18
|
|
|
20
19
|
|
|
21
|
-
async function main() {
|
|
20
|
+
export default async function main() {
|
|
22
21
|
await assertUserHasFFmpeg()
|
|
23
22
|
|
|
24
23
|
const { values, files } = await parseOptions({
|
|
25
|
-
|
|
24
|
+
outdir: { type: 'string', default: '' },
|
|
26
25
|
overwrite: { short: 'y', type: 'boolean' },
|
|
27
26
|
help: { short: 'h', type: 'boolean' },
|
|
28
27
|
})
|
|
@@ -37,27 +36,24 @@ async function main() {
|
|
|
37
36
|
|
|
38
37
|
console.log('AVIF…')
|
|
39
38
|
for (const file of files)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
try {
|
|
40
|
+
await avif({
|
|
41
|
+
file,
|
|
42
|
+
outFile: join(values.outdir || dirname(file), replaceExt(basename(file), 'avif')),
|
|
43
|
+
overwrite: values.overwrite
|
|
44
|
+
})
|
|
45
|
+
console.log(file)
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.error(err?.message || err)
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
async function avif({ file, outFile, overwrite }) {
|
|
52
|
+
export async function avif({ file, outFile, overwrite = false }) {
|
|
48
53
|
const stAvif = lstat(outFile)
|
|
54
|
+
if (!overwrite && stAvif?.isFile()) throw new Error(`output file exists but --overwrite=false. ${file}`)
|
|
55
|
+
if (stAvif?.mtimeMs > lstat(file)?.mtimeMs) throw new Error(`avif is newer. ${file}`)
|
|
49
56
|
|
|
50
|
-
if (!overwrite && stAvif?.isFile()) {
|
|
51
|
-
console.log('(skipped: output file exists but --overwrite=false)', file)
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
if (stAvif?.mtimeMs > lstat(file)?.mtimeMs) {
|
|
55
|
-
console.log('(skipped: avif is newer)', file)
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// TODO fix transparent PNGs
|
|
60
|
-
console.log(file)
|
|
61
57
|
await ffmpeg([
|
|
62
58
|
'-y',
|
|
63
59
|
'-i', file,
|
|
@@ -66,8 +62,3 @@ async function avif({ file, outFile, overwrite }) {
|
|
|
66
62
|
outFile
|
|
67
63
|
])
|
|
68
64
|
}
|
|
69
|
-
|
|
70
|
-
main().catch(err => {
|
|
71
|
-
console.error(err.message)
|
|
72
|
-
process.exit(1)
|
|
73
|
-
})
|
package/src/cli.js
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { join } from 'node:path'
|
|
4
|
-
import { styleText } from 'node:util'
|
|
5
4
|
import { spawn } from 'node:child_process'
|
|
5
|
+
import { styleText } from 'node:util'
|
|
6
6
|
import pkgJSON from '../package.json' with { type: 'json' }
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
const COMMANDS = {
|
|
10
|
-
avif: ['avif.js', 'Converts images to AVIF'],
|
|
11
|
-
png: ['png.sh', 'Optimizes PNG images with oxipng'],
|
|
12
|
-
sqcrop: ['sqcrop.js', 'Square crops images\n'],
|
|
13
|
-
|
|
14
|
-
resize: ['resize.js', 'Resizes videos or images'],
|
|
15
|
-
edgespic: ['edgespic.js', 'Extracts first and last frames'],
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
10
|
+
avif: ['./avif.js', 'Converts images to AVIF'],
|
|
11
|
+
png: ['./png.sh', 'Optimizes PNG images with oxipng'],
|
|
12
|
+
sqcrop: ['./sqcrop.js', 'Square crops images\n'],
|
|
13
|
+
|
|
14
|
+
resize: ['./resize.js', 'Resizes videos or images'],
|
|
15
|
+
edgespic: ['./edgespic.js', 'Extracts first and last frames'],
|
|
16
|
+
frameseq: ['./frameseq.js', 'Converts video to sequence of PNGs'],
|
|
17
|
+
countframes: ['./countframes.js', 'Counts frames in a video'],
|
|
18
|
+
ssim: ['./ssim.js', 'Computes SSIM between two images'],
|
|
19
|
+
gif: ['./gif.sh', 'Video to GIF\n'],
|
|
20
|
+
|
|
21
|
+
detectdups: ['./detectdups.js', 'Detects duplicate frames in a video'],
|
|
22
|
+
dropdups: ['./dropdups.js', 'Removes duplicate frames in a video'],
|
|
23
|
+
framediff: ['./framediff.sh', 'Plays a video of adjacent frames diff'],
|
|
24
|
+
hev1tohvc1: ['./hev1tohvc1.js', 'Fixes video thumbnails not rendering on macOS Finder'],
|
|
25
|
+
moov2front: ['./moov2front.js', 'Rearranges .mov and .mp4 metadata for fast-start streaming'],
|
|
26
|
+
vconcat: ['./vconcat.sh', 'Concatenates videos'],
|
|
27
|
+
vdiff: ['./vdiff.sh', 'Plays a video with the difference of two videos'],
|
|
28
|
+
vsplit: ['./vsplit.js', 'Splits a video into multiple clips from CSV timestamps'],
|
|
29
|
+
vtrim: ['./vtrim.js', 'Trims video from start to end time'],
|
|
30
|
+
prores: ['./prores.js', 'Converts video to ProRes\n'],
|
|
31
|
+
|
|
32
|
+
flattendir: ['./flattendir.sh', 'Moves all files to top dir and deletes dirs'],
|
|
33
|
+
qdir: ['./qdir.js', 'Sequentially runs all *.sh files in a folder'],
|
|
34
|
+
seqcheck: ['./seqcheck.js', 'Finds missing sequence number'],
|
|
35
|
+
openrand: ['./openrand.js', 'Opens a random file (macOS only)'],
|
|
36
|
+
play: ['./play.js', 'Plays filtered playlist with mpv\n'],
|
|
37
|
+
|
|
38
|
+
dlaudio: ['./dlaudio.sh', 'yt-dlp best audio'],
|
|
39
|
+
dlvideo: ['./dlvideo.sh', 'yt-dlp best video\n'],
|
|
40
|
+
|
|
41
|
+
unemoji: ['./unemoji.sh', 'Removes emojis from filenames'],
|
|
42
|
+
rmcover: ['./rmcover.sh', 'Removes cover art'],
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
export function commandsSummary() {
|
|
@@ -55,7 +57,7 @@ ${commandsSummary().map(([cmd, desc]) =>
|
|
|
55
57
|
`.trim()
|
|
56
58
|
|
|
57
59
|
|
|
58
|
-
function main() {
|
|
60
|
+
async function main() {
|
|
59
61
|
const [, , opt, ...args] = process.argv
|
|
60
62
|
|
|
61
63
|
if (opt === '-v' || opt === '--version') {
|
|
@@ -76,10 +78,16 @@ function main() {
|
|
|
76
78
|
process.exit(1)
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
const cmd =
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
const cmd = COMMANDS[opt][0]
|
|
82
|
+
if (cmd.endsWith('.js'))
|
|
83
|
+
(await import(cmd)).default()
|
|
84
|
+
else
|
|
85
|
+
spawn(join(import.meta.dirname, cmd), args, { stdio: 'inherit' })
|
|
86
|
+
.on('exit', process.exit)
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
if (import.meta.main)
|
|
85
|
-
main()
|
|
90
|
+
main().catch(err => {
|
|
91
|
+
console.error(err?.message || err)
|
|
92
|
+
process.exit(1)
|
|
93
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { parseOptions } from './utils/parseOptions.js'
|
|
2
|
+
import { assertUserHasFFmpeg } from './utils/subprocess.js'
|
|
3
|
+
import { videoAttrs } from './utils/videoAttrs.js'
|
|
4
|
+
import { parseTimecode } from './utils/parseTimecode.js'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const HELP = `
|
|
8
|
+
SYNOPSIS
|
|
9
|
+
mediasnacks countframes [options] <file>
|
|
10
|
+
|
|
11
|
+
DESCRIPTION
|
|
12
|
+
Counts the number of frames in a video between optional start and end bounds.
|
|
13
|
+
|
|
14
|
+
OPTIONS
|
|
15
|
+
-f, --fps <num> Frames per second (default: same as video)
|
|
16
|
+
-s, --start <timecode> Start time in seconds (default: 0)
|
|
17
|
+
-e, --end <timecode> End time in seconds (default: end of video)
|
|
18
|
+
|
|
19
|
+
EXAMPLES
|
|
20
|
+
mediasnacks countframes --start=1:30.16 --end=60 video.mov
|
|
21
|
+
mediasnacks countframes --fps=12 video.mov
|
|
22
|
+
`.trim()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export default async function main() {
|
|
26
|
+
await assertUserHasFFmpeg()
|
|
27
|
+
|
|
28
|
+
const { values, files } = await parseOptions({
|
|
29
|
+
fps: { type: 'string', default: '' },
|
|
30
|
+
start: { short: 's', type: 'string', default: '' },
|
|
31
|
+
end: { short: 'e', type: 'string', default: '' },
|
|
32
|
+
help: { short: 'h', type: 'boolean' }
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
if (values.help) {
|
|
36
|
+
console.log(HELP)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { fps, start, end } = values
|
|
41
|
+
const video = files[0]
|
|
42
|
+
if (!video) throw new Error('No video file specified')
|
|
43
|
+
|
|
44
|
+
const n = await countframes({ video, fps, start, end })
|
|
45
|
+
console.log(String(n))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export async function countframes({ video, fps, start, end }) {
|
|
50
|
+
const v = await videoAttrs(video)
|
|
51
|
+
const videoDuration = parseFloat(v.duration || 0)
|
|
52
|
+
const startSecs = start ? parseTimecode(start) : 0
|
|
53
|
+
const endSecs = end ? parseTimecode(end) : videoDuration
|
|
54
|
+
const durationLimit = Math.max(0, endSecs - startSecs)
|
|
55
|
+
const actualFps = fps ? Number(fps) : eval(v.r_frame_rate)
|
|
56
|
+
return Math.ceil(durationLimit * actualFps)
|
|
57
|
+
}
|
package/src/detectdups.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
import { parseOptions } from './utils/parseOptions.js'
|
|
4
|
-
import { ffmpeg, assertUserHasFFmpeg
|
|
2
|
+
import { ffmpeg, assertUserHasFFmpeg } from './utils/subprocess.js'
|
|
3
|
+
import { videoAttrs } from './utils/videoAttrs.js'
|
|
5
4
|
|
|
6
5
|
const STDEV_THRESHOLD = 0.2
|
|
7
6
|
|
|
@@ -30,7 +29,7 @@ SEE ALSO
|
|
|
30
29
|
`.trim()
|
|
31
30
|
|
|
32
31
|
|
|
33
|
-
async function main() {
|
|
32
|
+
export default async function main() {
|
|
34
33
|
await assertUserHasFFmpeg()
|
|
35
34
|
|
|
36
35
|
const { values, files } = await parseOptions({
|
|
@@ -44,13 +43,11 @@ async function main() {
|
|
|
44
43
|
return
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
if (files.length !== 1)
|
|
48
|
-
throw new Error('Invalid input file. One video file must be specified. See mediasnacks detectdups --help')
|
|
49
|
-
|
|
50
|
-
const v = await videoAttrs(files[0])
|
|
46
|
+
if (files.length !== 1) throw new Error('Invalid input file. One video file must be specified. See mediasnacks detectdups --help')
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
const video = files[0]
|
|
49
|
+
const v = await videoAttrs(video)
|
|
50
|
+
if (v.codec_type !== 'video') throw new Error('Invalid input file. Must be a video.')
|
|
54
51
|
|
|
55
52
|
const vDur = Number(v.duration)
|
|
56
53
|
|
|
@@ -66,7 +63,7 @@ async function main() {
|
|
|
66
63
|
if (isNaN(duration) || duration < 1) throw new Error(`Invalid --duration value: ${values.duration}`)
|
|
67
64
|
if ((seek + duration) > vDur) throw new Error(`Invalid analysis range. Exceeds video duration: ${vDur}`)
|
|
68
65
|
|
|
69
|
-
const dups = await detectdups(files[0], seek, duration)
|
|
66
|
+
const dups = await detectdups({ video: files[0], seek, duration })
|
|
70
67
|
const h = deltaHistogram(dups)
|
|
71
68
|
const report = {
|
|
72
69
|
n: maxFreqKey(h),
|
|
@@ -79,12 +76,12 @@ async function main() {
|
|
|
79
76
|
console.log(JSON.stringify(report, null, 2))
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
export async function detectdups(video, seek, duration) {
|
|
79
|
+
export async function detectdups({ video, seek, duration }) {
|
|
83
80
|
const { stderr } = await ffmpeg([
|
|
84
81
|
'-v', 'info',
|
|
85
82
|
'-stats',
|
|
86
|
-
'-ss', seek,
|
|
87
|
-
'-t', duration,
|
|
83
|
+
seek ? ['-ss', seek] : [],
|
|
84
|
+
duration ? ['-t', duration] : [],
|
|
88
85
|
'-i', video,
|
|
89
86
|
'-vf', [
|
|
90
87
|
'tblend=all_mode=difference',
|
|
@@ -92,7 +89,7 @@ export async function detectdups(video, seek, duration) {
|
|
|
92
89
|
'showinfo',
|
|
93
90
|
].join(','),
|
|
94
91
|
'-f', 'null', '-',
|
|
95
|
-
])
|
|
92
|
+
].flat())
|
|
96
93
|
|
|
97
94
|
const reNearBlackFrames = /n:\s*(\d+).*?mean:\[0].*?stdev:\[([0-9.]+)]/
|
|
98
95
|
const dupFrames = []
|
|
@@ -132,10 +129,3 @@ function maxFreqKey(histogram) {
|
|
|
132
129
|
? Number(maxKey)
|
|
133
130
|
: null
|
|
134
131
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (import.meta.main)
|
|
138
|
-
main().catch(err => {
|
|
139
|
-
console.error(err.message || err)
|
|
140
|
-
process.exit(1)
|
|
141
|
-
})
|
package/src/dropdups.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
import { resolve, parse, format } from 'node:path'
|
|
4
|
-
|
|
5
2
|
import { parseOptions } from './utils/parseOptions.js'
|
|
6
3
|
import { ffmpeg, assertUserHasFFmpeg, run } from './utils/subprocess.js'
|
|
7
4
|
import { ProresProfiles } from './prores.js'
|
|
@@ -30,7 +27,7 @@ EXAMPLES
|
|
|
30
27
|
`.trim()
|
|
31
28
|
|
|
32
29
|
|
|
33
|
-
async function main() {
|
|
30
|
+
export default async function main() {
|
|
34
31
|
await assertUserHasFFmpeg()
|
|
35
32
|
|
|
36
33
|
const { values, files } = await parseOptions({
|
|
@@ -55,7 +52,7 @@ async function main() {
|
|
|
55
52
|
await dropdups(resolve(file), dupFrameNum)
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
async function dropdups(video, dupFrameNum) {
|
|
55
|
+
export async function dropdups(video, dupFrameNum) {
|
|
59
56
|
await run('ffmpeg', [
|
|
60
57
|
'-v', 'error',
|
|
61
58
|
'-stats',
|
|
@@ -77,8 +74,3 @@ function makeOutputPath(video) {
|
|
|
77
74
|
? format({ dir, name: `${name}.dedup`, ext: '.mov' })
|
|
78
75
|
: format({ dir, name, ext: '.mov' })
|
|
79
76
|
}
|
|
80
|
-
|
|
81
|
-
main().catch(err => {
|
|
82
|
-
console.error(err.message || err)
|
|
83
|
-
process.exit(1)
|
|
84
|
-
})
|
package/src/edgespic.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
import { basename, extname, join, parse } from 'node:path'
|
|
4
2
|
|
|
5
3
|
import { mkDir } from './utils/fs-utils.js'
|
|
4
|
+
import { videoAttrs } from './utils/videoAttrs.js'
|
|
6
5
|
import { parseOptions } from './utils/parseOptions.js'
|
|
7
|
-
import { ffmpeg,
|
|
6
|
+
import { ffmpeg, assertUserHasFFmpeg } from './utils/subprocess.js'
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
const HELP = `
|
|
@@ -23,7 +22,7 @@ EXAMPLES
|
|
|
23
22
|
`.trim()
|
|
24
23
|
|
|
25
24
|
|
|
26
|
-
async function main() {
|
|
25
|
+
export default async function main() {
|
|
27
26
|
await assertUserHasFFmpeg()
|
|
28
27
|
|
|
29
28
|
const { values, files } = await parseOptions({
|
|
@@ -37,14 +36,11 @@ async function main() {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
const width = Number(values['width'])
|
|
40
|
-
if (width <= 0 || !Number.isInteger(width))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!files.length)
|
|
44
|
-
throw new Error('No video files specified')
|
|
39
|
+
if (width <= 0 || !Number.isInteger(width)) throw new Error('--width must be a positive number')
|
|
40
|
+
if (!files.length) throw new Error('No video files specified')
|
|
45
41
|
|
|
46
42
|
const outDir = join(parse(files[0]).dir, 'edgespic')
|
|
47
|
-
await mkDir(outDir)
|
|
43
|
+
await mkDir(outDir)
|
|
48
44
|
|
|
49
45
|
console.log('Extracting edge frames…')
|
|
50
46
|
for (const file of files)
|
|
@@ -52,7 +48,7 @@ async function main() {
|
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
|
|
55
|
-
async function edgespic(video, width, outDir) {
|
|
51
|
+
export async function edgespic(video, width, outDir) {
|
|
56
52
|
const { r_frame_rate } = await videoAttrs(video)
|
|
57
53
|
const name = basename(video, extname(video))
|
|
58
54
|
|
|
@@ -73,9 +69,3 @@ async function edgespic(video, width, outDir) {
|
|
|
73
69
|
join(outDir, `${name}_last.png`)
|
|
74
70
|
])
|
|
75
71
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
main().catch(err => {
|
|
79
|
-
console.error(err.message)
|
|
80
|
-
process.exit(1)
|
|
81
|
-
})
|
package/src/frameseq.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { basename, extname, join, parse } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { mkDir } from './utils/fs-utils.js'
|
|
4
|
+
import { parseOptions } from './utils/parseOptions.js'
|
|
5
|
+
import { ffmpeg, assertUserHasFFmpeg } from './utils/subprocess.js'
|
|
6
|
+
import { countframes } from './countframes.js'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const HELP = `
|
|
10
|
+
SYNOPSIS
|
|
11
|
+
mediasnacks frameseq [options] <files>
|
|
12
|
+
|
|
13
|
+
DESCRIPTION
|
|
14
|
+
Converts a video into a sequence of PNGs.
|
|
15
|
+
|
|
16
|
+
OPTIONS
|
|
17
|
+
-f, --fps <num> Frames per second (default: same as video)
|
|
18
|
+
-s, --start <timecode> Start time in seconds (default: 0)
|
|
19
|
+
-e, --end <timecode> End time in seconds (default: end of video)
|
|
20
|
+
|
|
21
|
+
EXAMPLES
|
|
22
|
+
Start and End
|
|
23
|
+
mediasnacks frameseq --start=1:30.16 --end=60 video.mov
|
|
24
|
+
|
|
25
|
+
Custom framerate, all video duration
|
|
26
|
+
mediasnacks frameseq --fps=12 video.mov
|
|
27
|
+
`.trim()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export default async function main() {
|
|
31
|
+
await assertUserHasFFmpeg()
|
|
32
|
+
|
|
33
|
+
const { values, files } = await parseOptions({
|
|
34
|
+
fps: { short: 'f', type: 'string', default: '' },
|
|
35
|
+
start: { short: 's', type: 'string', default: '' },
|
|
36
|
+
end: { short: 'e', type: 'string', default: '' },
|
|
37
|
+
outdir: { type: 'string', default: '' },
|
|
38
|
+
help: { short: 'h', type: 'boolean' }
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (values.help) {
|
|
42
|
+
console.log(HELP)
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { fps, start, end, outdir } = values
|
|
47
|
+
const video = files[0]
|
|
48
|
+
if (!video) throw new Error('No video files specified')
|
|
49
|
+
if (fps && isNaN(parseFloat(fps))) throw new Error('Invalid --fps')
|
|
50
|
+
if (start && isNaN(parseFloat(start))) throw new Error('Invalid --start')
|
|
51
|
+
if (end && isNaN(parseFloat(end))) throw new Error('Invalid --end')
|
|
52
|
+
|
|
53
|
+
const nFrames = await countframes({ video, fps, start, end })
|
|
54
|
+
const pad = String(nFrames).length
|
|
55
|
+
await frameseq({ video, fps, start, end, pad, outdir })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function frameseq({ video, fps, start, end, pad, outdir }) {
|
|
59
|
+
const name = basename(video, extname(video))
|
|
60
|
+
const outDir = outdir || join(parse(video).dir, name)
|
|
61
|
+
await mkDir(outDir)
|
|
62
|
+
await ffmpeg([
|
|
63
|
+
start ? ['-ss', start] : [],
|
|
64
|
+
end ? ['-to', end] : [],
|
|
65
|
+
'-i', video,
|
|
66
|
+
fps ? ['-vf', `fps=${fps}`] : [],
|
|
67
|
+
join(outDir, `${name}_%0${pad}d.png`)
|
|
68
|
+
].flat())
|
|
69
|
+
}
|
package/src/hev1tohvc1.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
import { parseOptions } from './utils/parseOptions.js'
|
|
4
2
|
import { uniqueFilenameFor, overwrite } from './utils/fs-utils.js'
|
|
5
|
-
import {
|
|
3
|
+
import { ffmpeg, assertUserHasFFmpeg } from './utils/subprocess.js'
|
|
4
|
+
import { videoAttrs } from './utils/videoAttrs.js'
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
const HELP = `
|
|
@@ -16,7 +15,7 @@ DESCRIPTION
|
|
|
16
15
|
`.trim()
|
|
17
16
|
|
|
18
17
|
|
|
19
|
-
async function main() {
|
|
18
|
+
export default async function main() {
|
|
20
19
|
await assertUserHasFFmpeg()
|
|
21
20
|
|
|
22
21
|
const { values, files } = await parseOptions({
|
|
@@ -28,21 +27,22 @@ async function main() {
|
|
|
28
27
|
return
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
if (!files.length)
|
|
32
|
-
throw new Error(HELP)
|
|
30
|
+
if (!files.length) throw new Error('Missing input file(s)')
|
|
33
31
|
|
|
34
32
|
for (const file of files)
|
|
35
|
-
|
|
33
|
+
try {
|
|
34
|
+
await hev1tohvc1(file)
|
|
35
|
+
console.log(file)
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
console.error(err?.message || err)
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
async function hev1tohvc1(file) {
|
|
42
|
+
export async function hev1tohvc1(file) {
|
|
39
43
|
const v = await videoAttrs(file)
|
|
40
|
-
if (v.codec_tag_string !== 'hev1') {
|
|
41
|
-
console.log('(skipped: non hev1)', file)
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
+
if (v.codec_tag_string !== 'hev1') throw new Error(`non hev1 ${file}`)
|
|
44
45
|
|
|
45
|
-
console.log(file)
|
|
46
46
|
const tmp = uniqueFilenameFor(file)
|
|
47
47
|
await ffmpeg([
|
|
48
48
|
'-i', file,
|
|
@@ -52,9 +52,3 @@ async function hev1tohvc1(file) {
|
|
|
52
52
|
])
|
|
53
53
|
await overwrite(tmp, file)
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
main().catch(err => {
|
|
58
|
-
console.error(err.message)
|
|
59
|
-
process.exit(1)
|
|
60
|
-
})
|