mediasnacks 0.16.5 → 0.18.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/.zsh/completions/_mediasnacks +2 -1
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/cli.js +2 -1
- package/src/prores.js +73 -0
- package/src/vtrim.js +57 -0
- package/src/vtrim.test.js +25 -7
- package/src/vtrim.sh +0 -36
|
@@ -16,6 +16,7 @@ _mediasnacks_commands=(
|
|
|
16
16
|
'vdiff:Plays a video with the difference of two videos'
|
|
17
17
|
'vsplit:Splits a video into multiple clips from CSV timestamps'
|
|
18
18
|
'vtrim:Trims video from start to end time'
|
|
19
|
+
'prores:Converts video to Apple ProRes'
|
|
19
20
|
|
|
20
21
|
'flattendir:Moves unique files to the top dir and deletes empty dirs'
|
|
21
22
|
'seqcheck:Finds missing sequence number'
|
|
@@ -37,7 +38,7 @@ fi
|
|
|
37
38
|
|
|
38
39
|
local cmd="$words[2]"
|
|
39
40
|
case "$cmd" in
|
|
40
|
-
avif|resize|sqcrop|moov2front|dropdups|edgespic|seqcheck|hev1tohvc1|framediff|vdiff|vconcat|vsplit|vtrim|dlaudio|dlvideo|unemoji|rmcover|curltime|gif|flattendir)
|
|
41
|
+
avif|resize|sqcrop|moov2front|dropdups|edgespic|seqcheck|hev1tohvc1|framediff|vdiff|vconcat|vsplit|vtrim|dlaudio|dlvideo|unemoji|rmcover|curltime|gif|flattendir|prores)
|
|
41
42
|
_files
|
|
42
43
|
;;
|
|
43
44
|
qdir)
|
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ npx mediasnacks <command> <args>
|
|
|
28
28
|
- `vdiff`: Plays a video with the difference of two videos
|
|
29
29
|
- `vsplit`: Splits a video into multiple clips from CSV timestamps
|
|
30
30
|
- `vtrim`: Trims video from start to end time
|
|
31
|
+
- `prores`: Converts video to Apple ProRes
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
- `flattendir`: Moves unique files to the top dir and deletes empty dirs
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -21,7 +21,8 @@ const COMMANDS = {
|
|
|
21
21
|
vconcat: ['vconcat.sh', 'Concatenates videos'],
|
|
22
22
|
vdiff: ['vdiff.sh', 'Plays a video with the difference of two videos'],
|
|
23
23
|
vsplit: ['vsplit.js', 'Splits a video into multiple clips from CSV timestamps'],
|
|
24
|
-
vtrim: ['vtrim.
|
|
24
|
+
vtrim: ['vtrim.js', 'Trims video from start to end time'],
|
|
25
|
+
prores: ['prores.js', 'Converts video to ProRes\n'],
|
|
25
26
|
|
|
26
27
|
flattendir: ['flattendir.sh', 'Moves all files to top dir and deletes dirs'],
|
|
27
28
|
qdir: ['qdir.js', 'Sequentially runs all *.sh files in a folder'],
|
package/src/prores.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { resolve, parse, join } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { parseOptions } from './utils/parseOptions.js'
|
|
6
|
+
import { assertUserHasFFmpeg, run } from './utils/ffmpeg.js'
|
|
7
|
+
|
|
8
|
+
const PRORES_PROFILES = {
|
|
9
|
+
'proxy': 0,
|
|
10
|
+
'lt': 1,
|
|
11
|
+
'standard': 2,
|
|
12
|
+
'hq': 3,
|
|
13
|
+
'4444': 4,
|
|
14
|
+
'4444xq': 5,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const USAGE = `
|
|
18
|
+
Usage: mediasnacks prores [options] <video>
|
|
19
|
+
|
|
20
|
+
Converts a video to ProRes format.
|
|
21
|
+
|
|
22
|
+
Arguments:
|
|
23
|
+
<video> Video file to convert
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--profile <n> ProRes profile (default: 3 (HQ))
|
|
27
|
+
-h, --help Show this help message
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
npx mediasnacks prores video.mov
|
|
31
|
+
npx mediasnacks prores --profile 2 video.mov
|
|
32
|
+
|
|
33
|
+
Outputs: video.prores.mov
|
|
34
|
+
`.trim()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async function main() {
|
|
38
|
+
await assertUserHasFFmpeg()
|
|
39
|
+
|
|
40
|
+
const { values, files } = await parseOptions({
|
|
41
|
+
help: { short: 'h', type: 'boolean' },
|
|
42
|
+
profile: { short: 'p', type: 'string', default: String(PRORES_PROFILES.hq) },
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
if (values.help) {
|
|
46
|
+
console.log(USAGE)
|
|
47
|
+
process.exit(0)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (files.length !== 1)
|
|
51
|
+
throw new Error('Expected 1 argument: video file. See npx mediasnacks prores --help')
|
|
52
|
+
|
|
53
|
+
const videoPath = resolve(files[0])
|
|
54
|
+
|
|
55
|
+
const { name, dir } = parse(videoPath)
|
|
56
|
+
const outputPath = join(dir, `${name}.prores.mov`)
|
|
57
|
+
|
|
58
|
+
console.log(`Converting to ProRes…`)
|
|
59
|
+
await run('ffmpeg', [
|
|
60
|
+
'-v', 'error',
|
|
61
|
+
'-stats',
|
|
62
|
+
'-i', videoPath,
|
|
63
|
+
'-c:v', 'prores_ks',
|
|
64
|
+
'-profile:v', values.profile,
|
|
65
|
+
'-pix_fmt', 'yuv422p10le',
|
|
66
|
+
outputPath
|
|
67
|
+
])
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
main().catch(err => {
|
|
71
|
+
console.error(err.message || err)
|
|
72
|
+
process.exit(1)
|
|
73
|
+
})
|
package/src/vtrim.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { resolve, parse } from 'node:path'
|
|
4
|
+
import { parseOptions } from './utils/parseOptions.js'
|
|
5
|
+
import { ffmpeg, assertUserHasFFmpeg } from './utils/ffmpeg.js'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const USAGE = `
|
|
9
|
+
Usage: mediasnacks vtrim [--start <time>] [--end <time>] <video>
|
|
10
|
+
|
|
11
|
+
Trims a video without re-encoding (fast, but approximate cuts).
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
-s, --start <time> Start time (e.g. 10, 00:00:10, 1:23.5). Default: beginning.
|
|
15
|
+
-e, --end <time> End time (e.g. 30, 00:00:30, 2:45.0). Default: end of video.
|
|
16
|
+
-h, --help
|
|
17
|
+
`.trim()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
await assertUserHasFFmpeg()
|
|
22
|
+
|
|
23
|
+
const { values, files } = await parseOptions({
|
|
24
|
+
start: { short: 's', type: 'string', default: '' },
|
|
25
|
+
end: { short: 'e', type: 'string', default: '' },
|
|
26
|
+
help: { short: 'h', type: 'boolean' }
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
if (values.help) {
|
|
30
|
+
console.log(USAGE)
|
|
31
|
+
process.exit(0)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!files.length)
|
|
35
|
+
throw new Error('No video specified. See npx mediasnacks vtrim --help')
|
|
36
|
+
|
|
37
|
+
for (const file of files)
|
|
38
|
+
await trim(resolve(file), values.start, values.end)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function trim(video, start, end) {
|
|
42
|
+
const { dir, name, ext } = parse(video)
|
|
43
|
+
await ffmpeg([
|
|
44
|
+
'-v', 'error',
|
|
45
|
+
'-y',
|
|
46
|
+
start ? ['-ss', start] : [],
|
|
47
|
+
end ? ['-to', end] : [],
|
|
48
|
+
'-i', video,
|
|
49
|
+
'-c', 'copy',
|
|
50
|
+
resolve(dir, `${name}.trim${ext}`)
|
|
51
|
+
].flat())
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main().catch(err => {
|
|
55
|
+
console.error(err.message || err)
|
|
56
|
+
process.exit(1)
|
|
57
|
+
})
|
package/src/vtrim.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ok } from 'node:assert/strict'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
|
-
import { test } from 'node:test'
|
|
4
3
|
import { cpSync } from 'node:fs'
|
|
4
|
+
import { describe, test } from 'node:test'
|
|
5
5
|
|
|
6
6
|
import { videoAttrs } from './utils/ffmpeg.js'
|
|
7
7
|
import { mkTempDir, cli } from './utils/test-utils.js'
|
|
@@ -9,14 +9,32 @@ import { mkTempDir, cli } from './utils/test-utils.js'
|
|
|
9
9
|
const rel = f => join(import.meta.dirname, f)
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
describe('vtrim', () => {
|
|
13
|
+
function almostEqual(actual, expected) {
|
|
14
|
+
const EPSILON = 0.05
|
|
15
|
+
ok(Math.abs(parseFloat(actual) - expected) < EPSILON,
|
|
16
|
+
`Duration should be around ${expected}s, got ${actual}s`)
|
|
17
|
+
}
|
|
14
18
|
|
|
19
|
+
const tmp = mkTempDir('vtrim')
|
|
15
20
|
const inputFile = join(tmp, '60fps.mp4')
|
|
16
21
|
cpSync(rel('fixtures/60fps.mp4'), inputFile)
|
|
17
|
-
cli('vtrim', 5, 10, inputFile)
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
test('from start to end time', async () => {
|
|
24
|
+
cli('vtrim', '--start', 5, '--end', 11, inputFile)
|
|
25
|
+
const { duration } = await videoAttrs(join(tmp, '60fps.trim.mp4'))
|
|
26
|
+
almostEqual(duration, 6)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('start time only', async () => {
|
|
30
|
+
cli('vtrim', '--start', 5, inputFile)
|
|
31
|
+
const { duration } = await videoAttrs(join(tmp, '60fps.trim.mp4'))
|
|
32
|
+
almostEqual(duration, 25)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('end time only', async () => {
|
|
36
|
+
cli('vtrim', '--end', 11, inputFile)
|
|
37
|
+
const { duration } = await videoAttrs(join(tmp, '60fps.trim.mp4'))
|
|
38
|
+
almostEqual(duration, 11)
|
|
39
|
+
})
|
|
22
40
|
})
|
package/src/vtrim.sh
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
if [ "$#" -ne 3 ]; then
|
|
4
|
-
cat << EOF
|
|
5
|
-
Usage:
|
|
6
|
-
$(basename $0) <start-time> <end-time> <video-file>
|
|
7
|
-
|
|
8
|
-
Examples:
|
|
9
|
-
$(basename $0) 10 30 input.mp4
|
|
10
|
-
$(basename $0) 00:00:10 00:00:30 input.mkv
|
|
11
|
-
$(basename $0) 1:23.5 2:45.0 video.mov
|
|
12
|
-
EOF
|
|
13
|
-
exit 1
|
|
14
|
-
fi
|
|
15
|
-
|
|
16
|
-
START="$1"
|
|
17
|
-
END="$2"
|
|
18
|
-
VIDEO="$3"
|
|
19
|
-
|
|
20
|
-
if [ ! -f "$VIDEO" ]; then
|
|
21
|
-
echo "Error: file not found: $VIDEO"
|
|
22
|
-
exit 1
|
|
23
|
-
fi
|
|
24
|
-
|
|
25
|
-
BASENAME=$(basename "$VIDEO")
|
|
26
|
-
DIRNAME=$(dirname "$VIDEO")
|
|
27
|
-
EXT="${BASENAME##*.}"
|
|
28
|
-
NAME="${BASENAME%.*}"
|
|
29
|
-
|
|
30
|
-
# For speed, we copy without re-encoding (with -ss before -i), but
|
|
31
|
-
# that means that the output isn’t going to be exact
|
|
32
|
-
ffmpeg -v error -y \
|
|
33
|
-
-ss "$START" \
|
|
34
|
-
-to "$END" \
|
|
35
|
-
-i "$VIDEO" \
|
|
36
|
-
-c copy "$DIRNAME/${NAME}.trim.$EXT"
|