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.
@@ -0,0 +1,91 @@
1
+ import { runSilently } from './subprocess.js'
2
+
3
+ /**
4
+ * Describes disposition flags that define how the video stream should be treated
5
+ * by players or downstream consumers.
6
+ * @typedef {Object} VideoStreamDisposition
7
+ * @prop {number} default Is whether this stream is the default selection.
8
+ * @prop {number} dub is dubbed?
9
+ * @prop {number} original is original?
10
+ * @prop {number} comment contains commentary?
11
+ * @prop {number} lyrics has lyrics?
12
+ * @prop {number} karaoke is karaoke?
13
+ * @prop {number} forced must always be rendered?
14
+ * @prop {number} hearing_impaired targets hearing-impaired audiences?
15
+ * @prop {number} visual_impaired targets visually-impaired audiences?
16
+ * @prop {number} clean_effects removes certain effects or noise?
17
+ * @prop {number} attached_pic represents embedded artwork?
18
+ * @prop {number} timed_thumbnails timed thumbnail data?
19
+ * @prop {number} non_diegetic non-diegetic content?
20
+ * @prop {number} captions has captions?
21
+ * @prop {number} descriptions has audio descriptions?
22
+ * @prop {number} metadata has supplemental metadata?
23
+ * @prop {number} dependent depends on another stream?
24
+ * @prop {number} still_image still-image video content?
25
+ * @prop {number} multilayer multilayer stream content?
26
+ */
27
+
28
+ /**
29
+ * Describes metadata tags associated with a video stream.
30
+ * @typedef {Object} VideoStreamTags
31
+ * @prop {string} language stream language.
32
+ * @prop {string} handler_name handler or track label.
33
+ * @prop {string} vendor_id vendor for the encoder or container.
34
+ */
35
+
36
+ /**
37
+ * Full set of attributes returned by ffprobe for a single video stream.
38
+ * @typedef {Object} VideoStream
39
+ * @prop {number} index Numerical index of the stream within the container.
40
+ * @prop {string} codec_name Short codec identifier used by FFmpeg.
41
+ * @prop {string} codec_long_name Descriptive codec name.
42
+ * @prop {string} profile Codec profile used during encoding.
43
+ * @prop {string} codec_type The media type, typically "video".
44
+ * @prop {string} codec_tag_string Codec tag string declared in the container.
45
+ * @prop {string} codec_tag Numeric codec tag in hexadecimal form.
46
+ * @prop {number} width Video width in pixels.
47
+ * @prop {number} height Video height in pixels.
48
+ * @prop {number} coded_width Internal coded width, which may differ from output width.
49
+ * @prop {number} coded_height Internal coded height.
50
+ * @prop {number} has_b_frames Number of B-frames used by the encoder.
51
+ * @prop {string} sample_aspect_ratio Pixel aspect ratio declared in the stream.
52
+ * @prop {string} display_aspect_ratio Display aspect ratio after scaling.
53
+ * @prop {string} pix_fmt Pixel format used by the video stream.
54
+ * @prop {number} level Codec level used during encoding.
55
+ * @prop {string} chroma_location The chroma sample position pattern.
56
+ * @prop {string} field_order Field order (progressive, top-field-first, etc.).
57
+ * @prop {number} refs Number of reference frames used by the encoder.
58
+ * @prop {string} is_avc Indicates whether the stream uses AVC-style NAL units.
59
+ * @prop {string} nal_length_size Length of NAL unit size prefixes.
60
+ * @prop {string} id Stream identifier within the container.
61
+ * @prop {string} r_frame_rate Raw frame rate reported by the demuxer.
62
+ * @prop {string} avg_frame_rate Average frame rate.
63
+ * @prop {string} time_base The fundamental time base of the stream.
64
+ * @prop {number} start_pts Presentation timestamp where the stream begins.
65
+ * @prop {string} start_time Wall-clock start time in seconds.
66
+ * @prop {number} duration_ts Duration expressed in time-base units.
67
+ * @prop {string} duration Stream duration in seconds.
68
+ * @prop {string} bit_rate Declared bit rate of the video stream.
69
+ * @prop {string} bits_per_raw_sample Bit depth of the raw samples.
70
+ * @prop {string} nb_frames Number of frames according to the container.
71
+ * @prop {number} extradata_size Size of the extra codec data.
72
+ * @prop {VideoStreamDisposition} disposition Disposition flags describing playback intent.
73
+ * @prop {VideoStreamTags} tags Metadata tags for the stream.
74
+ */
75
+
76
+
77
+ /**
78
+ * Extracts full metadata for the primary video stream (v:0) using ffprobe.
79
+ * @param {string} video Path to the video file.
80
+ * @returns {Promise<VideoStream>} All video stream attributes.
81
+ */
82
+ export async function videoAttrs(v) {
83
+ const { stdout } = await runSilently('ffprobe', [
84
+ '-v', 'error',
85
+ '-select_streams', 'v:0',
86
+ '-show_entries', 'stream',
87
+ '-of', 'json',
88
+ v
89
+ ])
90
+ return JSON.parse(stdout).streams?.[0] || {}
91
+ }
package/src/vsplit.js CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  import { readFileSync } from 'node:fs'
3
2
  import { resolve, parse, join } from 'node:path'
4
3
 
@@ -35,7 +34,7 @@ SEE ALSO
35
34
  `.trim()
36
35
 
37
36
 
38
- async function main() {
37
+ export default async function main() {
39
38
  await assertUserHasFFmpeg()
40
39
 
41
40
  const { values, files } = await parseOptions({
@@ -79,7 +78,7 @@ function parseCSV(csvPath) {
79
78
  return clips
80
79
  }
81
80
 
82
- async function vsplit(videoPath, clips) {
81
+ export async function vsplit(videoPath, clips) {
83
82
  const { dir, name, ext } = parse(videoPath)
84
83
  const seqLen = Math.log10(clips.length) + 1 | 0
85
84
 
@@ -97,8 +96,3 @@ async function vsplit(videoPath, clips) {
97
96
  ])
98
97
  }
99
98
  }
100
-
101
- main().catch(err => {
102
- console.error(err.message || err)
103
- process.exit(1)
104
- })
package/src/vtrim.js CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  import { resolve, parse } from 'node:path'
3
2
  import { parseOptions } from './utils/parseOptions.js'
4
3
  import { ffmpeg, assertUserHasFFmpeg } from './utils/subprocess.js'
@@ -14,14 +13,13 @@ DESCRIPTION
14
13
  OPTIONS
15
14
  -s, --start <time> Start time (e.g. 10, 00:00:10, 1:23.5). Default: beginning.
16
15
  -e, --end <time> End time (e.g. 30, 00:00:30, 2:45.0). Default: end of video.
17
- -h, --help
18
16
 
19
17
  SEE ALSO
20
18
  mediasnacks vsplit
21
19
  `.trim()
22
20
 
23
21
 
24
- async function main() {
22
+ export default async function main() {
25
23
  await assertUserHasFFmpeg()
26
24
 
27
25
  const { values, files } = await parseOptions({
@@ -39,10 +37,14 @@ async function main() {
39
37
  throw new Error('No video specified. See mediasnacks vtrim --help')
40
38
 
41
39
  for (const file of files)
42
- await vtrim(resolve(file), values.start, values.end)
40
+ await vtrim({
41
+ video: resolve(file),
42
+ start: values.start,
43
+ end: values.end
44
+ })
43
45
  }
44
46
 
45
- async function vtrim(video, start, end) {
47
+ export async function vtrim({ video, start, end }) {
46
48
  const { dir, name, ext } = parse(video)
47
49
  await ffmpeg([
48
50
  '-v', 'error',
@@ -54,8 +56,3 @@ async function vtrim(video, start, end) {
54
56
  resolve(dir, `${name}.trim${ext}`)
55
57
  ].flat())
56
58
  }
57
-
58
- main().catch(err => {
59
- console.error(err.message || err)
60
- process.exit(1)
61
- })