mediasnacks 0.20.1 → 0.21.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.
@@ -29,8 +29,6 @@ _mediasnacks_commands=(
29
29
 
30
30
  'unemoji:Removes emojis from filenames'
31
31
  'rmcover:Removes cover art'
32
-
33
- 'curltime:Measures request response timings'
34
32
  )
35
33
 
36
34
  if (( CURRENT == 2 )); then
package/README.md CHANGED
@@ -60,8 +60,6 @@ mediasnacks <command> <args>
60
60
  - `rmcover`: Removes cover art
61
61
 
62
62
 
63
- - `curltime`: Measures request response timings
64
-
65
63
  ### Globs
66
64
  Glob patterns are expanded by Node.js.
67
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediasnacks",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "description": "Utilities for optimizing and preparing videos and images",
5
5
  "license": "MIT",
6
6
  "author": "Eric Fortis",
package/src/cli.js CHANGED
@@ -34,9 +34,7 @@ const COMMANDS = {
34
34
  dlvideo: ['dlvideo.sh', 'yt-dlp best video\n'],
35
35
 
36
36
  unemoji: ['unemoji.sh', 'Removes emojis from filenames'],
37
- rmcover: ['rmcover.sh', 'Removes cover art\n'],
38
-
39
- curltime: ['curltime.sh', 'Measures request response timings'],
37
+ rmcover: ['rmcover.sh', 'Removes cover art'],
40
38
  }
41
39
 
42
40
  const MAN = `
package/src/detectdups.js CHANGED
@@ -71,7 +71,16 @@ async function main() {
71
71
 
72
72
 
73
73
  const dups = await detectDuplicateFramesNums(files[0], seek, duration)
74
- analyze(dups, seek, duration)
74
+ const h = deltaHistogram(dups)
75
+ const report = {
76
+ n: maxFreqKey(h),
77
+ histogram: h,
78
+ analyzed_region: {
79
+ start_sec: seek,
80
+ end_sec: seek + duration
81
+ },
82
+ }
83
+ console.log(JSON.stringify(report, null, 2))
75
84
  }
76
85
 
77
86
  export async function detectDuplicateFramesNums(video, seek, duration) {
@@ -106,29 +115,22 @@ export async function detectDuplicateFramesNums(video, seek, duration) {
106
115
 
107
116
  // This is only good for when there's one repeated frame in a cycle.
108
117
  // i.e. it's the wrong approach for e.g. 25 to 60, in which N=2 and N=3
109
- function analyze(dup_frames, seek, duration) {
118
+ function deltaHistogram(dups) {
110
119
  const histogram = {}
111
- for (let i = 1; i < dup_frames.length; i++) {
112
- const diff = dup_frames[i] - dup_frames[i - 1]
120
+ for (let i = 1; i < dups.length; i++) {
121
+ const diff = dups[i] - dups[i - 1]
113
122
  histogram[diff] = (histogram[diff] || 0) + 1
114
123
  }
115
- console.log(JSON.stringify({
116
- analyzed_region: {
117
- start_sec: seek,
118
- end_sec: seek + duration
119
- },
120
- histogram,
121
- n: maxFreqKey(histogram)
122
- }, null, 2))
124
+ return histogram
123
125
  }
124
126
 
125
- function maxFreqKey(hist) {
127
+ function maxFreqKey(histogram) {
126
128
  let maxKey = null
127
129
  let maxVal = -1
128
- for (const [key, val] of Object.entries(hist))
129
- if (val > maxVal) {
130
- maxVal = val
131
- maxKey = key
130
+ for (const [k, v] of Object.entries(histogram))
131
+ if (v > maxVal) {
132
+ maxVal = v
133
+ maxKey = k
132
134
  }
133
135
  return maxKey !== null
134
136
  ? Number(maxKey)
@@ -136,7 +138,6 @@ function maxFreqKey(hist) {
136
138
  }
137
139
 
138
140
 
139
-
140
141
  if (import.meta.main)
141
142
  main().catch(err => {
142
143
  console.error(err.message || err)
@@ -6,31 +6,19 @@ import { cli } from './utils/test-utils.js'
6
6
  const rel = f => join(import.meta.dirname, f)
7
7
 
8
8
  function detect(video) {
9
- const { stdout } = cli('detectdups', rel(video), 0, 7)
9
+ const { stdout } = cli('detectdups', rel(video))
10
10
  return JSON.parse(stdout).n
11
11
  }
12
12
 
13
-
14
- test('no dups', () =>
15
- equal(detect('fixtures/big-buck-bunny/bbb_24fps_no_dups.mp4'), null))
16
-
13
+ test('no dups', () => equal(detect('fixtures/big-buck-bunny/bbb_24fps_no_dups.mp4'), null))
17
14
 
18
15
  // These fixtures are badly retimed (non-interpolated, just duplicating a frame)
19
16
 
20
- test('24 to 48 (has dup at n=2)', () =>
21
- equal(detect('fixtures/big-buck-bunny/bbb_24_to_48fps_dup.mp4'), 2))
22
-
23
- test('25 to 50 (has dup at n=2)', () =>
24
- equal(detect('fixtures/big-buck-bunny/bbb_25_to_50fps_dup.mp4'), 2))
25
-
26
-
27
- test('24 to 30 (has dup at n=5)', () =>
28
- equal(detect('fixtures/big-buck-bunny/bbb_24_to_30fps_dup.mp4'), 5))
29
-
30
- test('25 to 30 (has dup at n=6)', () =>
31
- equal(detect('fixtures/big-buck-bunny/bbb_25_to_30fps_dup.mp4'), 6))
17
+ test('24 to 48 (has dup at n=2)', () => equal(detect('fixtures/big-buck-bunny/bbb_24_to_48fps_dup.mp4'), 2))
18
+ test('25 to 50 (has dup at n=2)', () => equal(detect('fixtures/big-buck-bunny/bbb_25_to_50fps_dup.mp4'), 2))
32
19
 
20
+ test('24 to 30 (has dup at n=5)', () => equal(detect('fixtures/big-buck-bunny/bbb_24_to_30fps_dup.mp4'), 5))
21
+ test('25 to 30 (has dup at n=6)', () => equal(detect('fixtures/big-buck-bunny/bbb_25_to_30fps_dup.mp4'), 6))
33
22
 
34
- test('24 to 25 (has dup at n=25)', () =>
35
- equal(detect('fixtures/big-buck-bunny/bbb_24_to_25fps_dup.mp4'), 25))
23
+ test('24 to 25 (has dup at n=25)', () => equal(detect('fixtures/big-buck-bunny/bbb_24_to_25fps_dup.mp4'), 25))
36
24
 
package/src/curltime.sh DELETED
@@ -1,14 +0,0 @@
1
- #!/bin/sh
2
-
3
- # https://stackoverflow.com/a/47944496
4
-
5
- curl -so /dev/null -w "\
6
- DNS Lookup %{time_namelookup}
7
- TCP Handshake %{time_connect}
8
- TLS Handshake %{time_appconnect}
9
- Wait %{time_pretransfer}
10
- Redirect %{time_redirect}
11
- First Byte %{time_starttransfer}
12
- ───────────────────────
13
- TOTAL %{time_total}
14
- " "$@"