@mediaproc/audio 1.0.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.
Files changed (51) hide show
  1. package/README.md +359 -0
  2. package/bin/cli.js +5 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +102 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/convert.d.ts +3 -0
  8. package/dist/commands/convert.d.ts.map +1 -0
  9. package/dist/commands/convert.js +149 -0
  10. package/dist/commands/convert.js.map +1 -0
  11. package/dist/commands/extract.d.ts +3 -0
  12. package/dist/commands/extract.d.ts.map +1 -0
  13. package/dist/commands/extract.js +146 -0
  14. package/dist/commands/extract.js.map +1 -0
  15. package/dist/commands/merge.d.ts +3 -0
  16. package/dist/commands/merge.d.ts.map +1 -0
  17. package/dist/commands/merge.js +141 -0
  18. package/dist/commands/merge.js.map +1 -0
  19. package/dist/commands/normalize.d.ts +3 -0
  20. package/dist/commands/normalize.d.ts.map +1 -0
  21. package/dist/commands/normalize.js +114 -0
  22. package/dist/commands/normalize.js.map +1 -0
  23. package/dist/commands/trim.d.ts +3 -0
  24. package/dist/commands/trim.d.ts.map +1 -0
  25. package/dist/commands/trim.js +143 -0
  26. package/dist/commands/trim.js.map +1 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/register.d.ts +5 -0
  32. package/dist/register.d.ts.map +1 -0
  33. package/dist/register.js +18 -0
  34. package/dist/register.js.map +1 -0
  35. package/dist/types.d.ts +14 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +2 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/utils/ffmpeg.d.ts +38 -0
  40. package/dist/utils/ffmpeg.d.ts.map +1 -0
  41. package/dist/utils/ffmpeg.js +146 -0
  42. package/dist/utils/ffmpeg.js.map +1 -0
  43. package/dist/utils/helpFormatter.d.ts +18 -0
  44. package/dist/utils/helpFormatter.d.ts.map +1 -0
  45. package/dist/utils/helpFormatter.js +28 -0
  46. package/dist/utils/helpFormatter.js.map +1 -0
  47. package/dist/utils/pathValidator.d.ts +74 -0
  48. package/dist/utils/pathValidator.d.ts.map +1 -0
  49. package/dist/utils/pathValidator.js +208 -0
  50. package/dist/utils/pathValidator.js.map +1 -0
  51. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1,359 @@
1
+ # Audio Plugin
2
+
3
+ Professional audio processing plugin for MediaProc CLI. Convert, extract, trim, merge, and normalize audio files with FFmpeg.
4
+
5
+ ## Features
6
+
7
+ - šŸ”„ **Convert** - Convert between audio formats (MP3, AAC, WAV, FLAC, OGG, Opus)
8
+ - šŸŽµ **Extract** - Extract audio tracks from video files
9
+ - āœ‚ļø **Trim** - Cut audio to specific time ranges with fade effects
10
+ - šŸ”— **Merge** - Concatenate multiple audio files with crossfade
11
+ - šŸ“Š **Normalize** - EBU R128 loudness normalization for consistent levels
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install -g @mediaproc/audio
17
+ ```
18
+
19
+ Or via MediaProc CLI:
20
+
21
+ ```bash
22
+ mediaproc add audio
23
+ ```
24
+
25
+ ## Requirements
26
+
27
+ - **FFmpeg** 4.0+ with audio codecs support
28
+ - **Node.js** 18+
29
+
30
+ Check if FFmpeg is installed:
31
+
32
+ ```bash
33
+ ffmpeg -version
34
+ ```
35
+
36
+ ## Commands
37
+
38
+ ### convert - Format Conversion
39
+
40
+ Convert audio files between different formats with quality control.
41
+
42
+ **Supported Formats:** MP3, AAC, WAV, FLAC, OGG, Opus, M4A
43
+
44
+ ```bash
45
+ # Basic conversion
46
+ mediaproc audio convert input.wav -f mp3
47
+
48
+ # High-quality conversion
49
+ mediaproc audio convert input.flac -f mp3 -b 320k
50
+
51
+ # Lossless conversion
52
+ mediaproc audio convert input.wav -f flac -q lossless
53
+
54
+ # Change sample rate and channels
55
+ mediaproc audio convert input.mp3 -f wav -s 48000 -c 2
56
+
57
+ # Batch convert folder
58
+ mediaproc audio convert audio-files/ -f aac -o output/
59
+ ```
60
+
61
+ **Options:**
62
+
63
+ - `-o, --output <path>` - Output file/directory
64
+ - `-f, --format <format>` - Output format (mp3, aac, wav, flac, ogg, opus, m4a)
65
+ - `-b, --bitrate <bitrate>` - Audio bitrate (e.g., 128k, 192k, 320k)
66
+ - `-q, --quality <quality>` - Quality preset: low, medium, high, lossless
67
+ - `-s, --sample-rate <rate>` - Sample rate in Hz (44100, 48000)
68
+ - `-c, --channels <channels>` - Channels: 1 (mono), 2 (stereo)
69
+
70
+ ---
71
+
72
+ ### extract - Audio from Video
73
+
74
+ Extract audio tracks from video files to standalone audio files.
75
+
76
+ **Supported Video Formats:** MP4, MKV, AVI, MOV, WebM, FLV
77
+
78
+ ```bash
79
+ # Extract as MP3 (default)
80
+ mediaproc audio extract video.mp4
81
+
82
+ # Extract as high-quality AAC
83
+ mediaproc audio extract video.mp4 -f aac -b 256k
84
+
85
+ # Extract as lossless FLAC
86
+ mediaproc audio extract video.mkv -f flac -q lossless
87
+
88
+ # Extract as mono for voice
89
+ mediaproc audio extract video.mp4 -f mp3 --channels 1
90
+
91
+ # Batch extract from folder
92
+ mediaproc audio extract videos/ -f mp3 -o audio-tracks/
93
+ ```
94
+
95
+ **Options:**
96
+
97
+ - `-o, --output <path>` - Output file/directory
98
+ - `-f, --format <format>` - Output format (mp3, aac, wav, flac, opus, ogg)
99
+ - `-b, --bitrate <bitrate>` - Audio bitrate
100
+ - `-q, --quality <quality>` - Quality preset
101
+ - `--sample-rate <rate>` - Sample rate
102
+ - `--channels <channels>` - Number of channels
103
+
104
+ ---
105
+
106
+ ### trim - Cut Audio
107
+
108
+ Trim audio files to specific time ranges with optional fade effects.
109
+
110
+ ```bash
111
+ # Trim by time range
112
+ mediaproc audio trim audio.mp3 --start 00:01:00 --end 00:02:00
113
+
114
+ # Extract first 30 seconds
115
+ mediaproc audio trim audio.mp3 --duration 30
116
+
117
+ # Trim from 30s for 60s
118
+ mediaproc audio trim audio.mp3 -s 30 -d 60
119
+
120
+ # Add fade effects
121
+ mediaproc audio trim audio.mp3 -s 60 -d 120 --fade-in 2 --fade-out 3
122
+
123
+ # Fast mode (stream copy, no re-encoding)
124
+ mediaproc audio trim audio.mp3 --start 30 --duration 60 --fast
125
+
126
+ # Batch trim all files
127
+ mediaproc audio trim folder/ -s 10 -d 30 -o output/
128
+ ```
129
+
130
+ **Options:**
131
+
132
+ - `-o, --output <path>` - Output file/directory
133
+ - `-s, --start <time>` - Start time (HH:MM:SS or seconds)
134
+ - `-e, --end <time>` - End time (HH:MM:SS or seconds)
135
+ - `-d, --duration <time>` - Duration from start
136
+ - `--fade-in <seconds>` - Fade-in duration
137
+ - `--fade-out <seconds>` - Fade-out duration
138
+ - `--fast` - Fast mode (stream copy)
139
+
140
+ ---
141
+
142
+ ### merge - Concatenate Audio
143
+
144
+ Join multiple audio files into one continuous file.
145
+
146
+ ```bash
147
+ # Basic merge
148
+ mediaproc audio merge audio1.mp3 audio2.mp3 audio3.mp3
149
+
150
+ # Merge with custom output
151
+ mediaproc audio merge part*.mp3 -o complete.mp3
152
+
153
+ # Merge with crossfade
154
+ mediaproc audio merge song1.mp3 song2.mp3 --crossfade 2
155
+
156
+ # Merge with normalization
157
+ mediaproc audio merge *.wav --normalize -o normalized.wav
158
+
159
+ # Merge to different format
160
+ mediaproc audio merge *.wav -o output.flac --format flac
161
+ ```
162
+
163
+ **Options:**
164
+
165
+ - `-o, --output <path>` - Output file (default: merged.mp3)
166
+ - `--format <format>` - Output format
167
+ - `--bitrate <bitrate>` - Output bitrate
168
+ - `--crossfade <seconds>` - Crossfade duration between files
169
+ - `--normalize` - Normalize audio levels before merging
170
+
171
+ ---
172
+
173
+ ### normalize - Loudness Normalization
174
+
175
+ Normalize audio levels using EBU R128 loudness standard for consistent volume.
176
+
177
+ ```bash
178
+ # Normalize to broadcast standard (-16 LUFS)
179
+ mediaproc audio normalize audio.mp3
180
+
181
+ # Normalize to streaming standard (-23 LUFS)
182
+ mediaproc audio normalize audio.mp3 -t -23
183
+
184
+ # Custom target loudness
185
+ mediaproc audio normalize audio.mp3 -t -16 -l -1.0
186
+
187
+ # Simple peak normalization
188
+ mediaproc audio normalize audio.mp3 -m peak
189
+
190
+ # Batch normalize folder
191
+ mediaproc audio normalize folder/ -o output/
192
+ ```
193
+
194
+ **Options:**
195
+
196
+ - `-o, --output <path>` - Output file/directory
197
+ - `-t, --target <lufs>` - Target loudness in LUFS (default: -16)
198
+ - `-l, --max-level <db>` - Maximum true peak in dB (default: -1.5)
199
+ - `-m, --method <method>` - Method: loudnorm (EBU R128), peak
200
+ - `--format <format>` - Output format
201
+
202
+ **LUFS Standards:**
203
+
204
+ - **-16 LUFS** - Broadcast standard (TV, radio)
205
+ - **-23 LUFS** - Streaming platforms (Spotify, YouTube)
206
+ - **-14 LUFS** - Apple Music, Tidal
207
+
208
+ ---
209
+
210
+ ## Format Support
211
+
212
+ | Format | Extension | Type | Codec | Best For |
213
+ | ------ | -------------- | -------- | ---------- | -------------------------- |
214
+ | MP3 | `.mp3` | Lossy | libmp3lame | Universal compatibility |
215
+ | AAC | `.aac`, `.m4a` | Lossy | aac | Modern devices, streaming |
216
+ | WAV | `.wav` | Lossless | pcm_s16le | Professional editing |
217
+ | FLAC | `.flac` | Lossless | flac | Archival, lossless quality |
218
+ | OGG | `.ogg` | Lossy | libvorbis | Open-source projects |
219
+ | Opus | `.opus` | Lossy | libopus | Voice, low bandwidth |
220
+
221
+ ## Quality Guidelines
222
+
223
+ ### Bitrate Recommendations
224
+
225
+ | Quality | MP3 | AAC | Opus | Use Case |
226
+ | ------- | ---- | ---- | ---- | ------------------------- |
227
+ | Low | 96k | 64k | 48k | Voice, podcasts |
228
+ | Medium | 192k | 128k | 96k | General music |
229
+ | High | 320k | 256k | 128k | High-quality distribution |
230
+
231
+ ### Sample Rates
232
+
233
+ - **44100 Hz** - CD quality (default for most content)
234
+ - **48000 Hz** - Professional audio, video production
235
+ - **96000 Hz** - High-resolution audio
236
+
237
+ ## Common Workflows
238
+
239
+ ### Podcast Production
240
+
241
+ ```bash
242
+ # Extract audio from video recording
243
+ mediaproc audio extract recording.mp4 -f mp3 -b 128k --channels 1
244
+
245
+ # Normalize levels
246
+ mediaproc audio normalize recording-audio.mp3 -t -16
247
+
248
+ # Trim intro/outro
249
+ mediaproc audio trim recording-audio-normalized.mp3 -s 10 --duration 3600
250
+ ```
251
+
252
+ ### Music Production
253
+
254
+ ```bash
255
+ # Convert to lossless for editing
256
+ mediaproc audio convert track.mp3 -f wav -q lossless
257
+
258
+ # Merge multiple takes
259
+ mediaproc audio merge take1.wav take2.wav take3.wav --normalize
260
+
261
+ # Export final master
262
+ mediaproc audio convert merged.wav -f flac -q lossless
263
+ ```
264
+
265
+ ### Video Production
266
+
267
+ ```bash
268
+ # Extract audio from video
269
+ mediaproc audio extract video.mp4 -f wav
270
+
271
+ # Clean up audio
272
+ mediaproc audio normalize video-audio.wav -t -16
273
+
274
+ # Trim to match video
275
+ mediaproc audio trim video-audio-normalized.wav -s 0 -e 00:05:30
276
+ ```
277
+
278
+ ## Advanced Examples
279
+
280
+ ### Batch Processing
281
+
282
+ ```bash
283
+ # Convert all WAV files to MP3
284
+ for file in *.wav; do
285
+ mediaproc audio convert "$file" -f mp3 -b 320k
286
+ done
287
+
288
+ # Or use folder processing
289
+ mediaproc audio convert wav-files/ -f mp3 -b 320k -o mp3-files/
290
+ ```
291
+
292
+ ### Creating Audio Montage
293
+
294
+ ```bash
295
+ # Merge with crossfades and normalization
296
+ mediaproc audio merge \
297
+ intro.mp3 \
298
+ main-content.mp3 \
299
+ outro.mp3 \
300
+ --crossfade 2 \
301
+ --normalize \
302
+ -o final-montage.mp3
303
+ ```
304
+
305
+ ### Format Migration
306
+
307
+ ```bash
308
+ # Migrate entire music library from MP3 to FLAC
309
+ mediaproc audio convert music-library/ \
310
+ -f flac \
311
+ -q lossless \
312
+ -o flac-library/
313
+ ```
314
+
315
+ ## Troubleshooting
316
+
317
+ ### FFmpeg Not Found
318
+
319
+ ```bash
320
+ # macOS
321
+ brew install ffmpeg
322
+
323
+ # Ubuntu/Debian
324
+ sudo apt install ffmpeg
325
+
326
+ # Windows (via Chocolatey)
327
+ choco install ffmpeg
328
+ ```
329
+
330
+ ### Audio Quality Issues
331
+
332
+ - Use lossless formats (WAV, FLAC) for intermediate processing
333
+ - Avoid multiple lossy conversions (MP3 → AAC → OGG)
334
+ - Use higher bitrates (320k) for final distribution
335
+ - Enable normalization for consistent loudness
336
+
337
+ ### Merge Compatibility Issues
338
+
339
+ Different formats may require re-encoding:
340
+
341
+ ```bash
342
+ # Force re-encoding with specific format
343
+ mediaproc audio merge *.* --format mp3 --bitrate 192k
344
+ ```
345
+
346
+ ## Performance Tips
347
+
348
+ - Use `--fast` mode for large trim operations
349
+ - Enable batch processing for multiple files
350
+ - Consider hardware acceleration for video extraction
351
+ - Use appropriate quality settings (avoid overkill)
352
+
353
+ ## License
354
+
355
+ MIT
356
+
357
+ ## Contributing
358
+
359
+ Issues and PRs welcome at [mediaproc-cli](https://github.com/0xshariq/mediaproc-cli)
package/bin/cli.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import('../dist/cli.js').catch((error) => {
3
+ console.error('Fatal error:', error);
4
+ process.exit(1);
5
+ });
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { register } from './register.js';
4
+ const program = new Command();
5
+ program
6
+ .name('mediaproc-audio')
7
+ .description(`
8
+ šŸŽµ Audio Processing Plugin v1.0.0
9
+
10
+ Professional audio processing powered by FFmpeg/FFprobe. Convert, normalize, trim, merge, and extract audio with 5 powerful commands.
11
+
12
+ šŸ“¦ Commands Overview:
13
+
14
+ šŸ”„ convert [input]
15
+ Convert audio between formats with quality control
16
+ • Formats: MP3, AAC, WAV, FLAC, OGG, Opus, M4A, WMA
17
+ • Quality presets: low (96k), medium (192k), high (320k), lossless
18
+ • Custom bitrate, sample rate, and channel control
19
+ • Example: mediaproc-audio convert song.wav -f mp3 -b 320k
20
+
21
+ šŸŽµ extract [input]
22
+ Extract audio tracks from video files
23
+ • Input: MP4, MKV, AVI, MOV, WebM, FLV, WMV, M4V
24
+ • Output: MP3, AAC, WAV, FLAC, Opus, OGG
25
+ • Quality and bitrate control
26
+ • Example: mediaproc-audio extract video.mp4 -f flac -q lossless
27
+
28
+ šŸ“Š normalize [input]
29
+ Normalize audio levels to consistent loudness
30
+ • EBU R128 loudness normalization (loudnorm filter)
31
+ • Peak normalization method
32
+ • Target LUFS: -16 (broadcast), -23 (streaming), -14 (podcasts)
33
+ • True peak limiting to prevent clipping
34
+ • Example: mediaproc-audio normalize podcast.mp3 -t -16 -l -1.5
35
+
36
+ āœ‚ļø trim [input]
37
+ Cut audio segments with precise timing
38
+ • Time-based: HH:MM:SS or seconds (e.g., 00:01:30 or 90)
39
+ • Duration-based: extract specific length
40
+ • Optional fade-in/fade-out effects (0.1-10 seconds)
41
+ • Fast mode: stream copy without re-encoding
42
+ • Example: mediaproc-audio trim song.mp3 -s 30 -d 60 --fade-in 2
43
+
44
+ šŸ”— merge [inputs...]
45
+ Concatenate multiple audio files into one
46
+ • Seamless joining of audio tracks
47
+ • Optional crossfade between files (0-10 seconds)
48
+ • Automatic format normalization
49
+ • Audio level normalization option
50
+ • Example: mediaproc-audio merge part1.mp3 part2.mp3 -o complete.mp3 --crossfade 2
51
+
52
+ šŸŽ¶ Format Support:
53
+ Lossy Formats: MP3, AAC, OGG Vorbis, Opus, M4A (AAC), WMA
54
+ Lossless Formats: WAV (PCM), FLAC (Free Lossless Audio Codec)
55
+ Video Sources: MP4, MKV, AVI, MOV, WebM, FLV, WMV, M4V
56
+
57
+ šŸ“” Audio Quality Guide:
58
+ 96k (low) - Voice recordings, podcasts, audiobooks
59
+ 128k (medium-) - Acceptable music quality, streaming
60
+ 192k (medium) - Good music quality, general use
61
+ 256k (high-) - Very good quality, near-transparent
62
+ 320k (high) - Maximum MP3 quality, transparent to most listeners
63
+ FLAC/WAV - Lossless, archival quality, professional mastering
64
+
65
+ šŸ“Š Loudness Normalization Standards:
66
+ -16 LUFS - EBU R128 broadcast standard (TV, Radio, Streaming)
67
+ -23 LUFS - ATSC A/85 loudness target (Spotify, YouTube, Apple Music)
68
+ -14 LUFS - Podcast and audiobook standard
69
+ -9 LUFS - Mastering reference (loud commercial sound)
70
+
71
+ šŸ”§ Common Workflows:
72
+ # Convert WAV to high-quality MP3
73
+ mediaproc-audio convert master.wav -f mp3 -b 320k -s 48000
74
+
75
+ # Extract lossless audio from video
76
+ mediaproc-audio extract concert.mp4 -f flac -q lossless
77
+
78
+ # Normalize for streaming platforms
79
+ mediaproc-audio normalize song.mp3 -t -23 -m loudnorm
80
+
81
+ # Trim with fade effects
82
+ mediaproc-audio trim interview.mp3 -s 00:05:30 -e 00:15:45 --fade-in 1 --fade-out 2
83
+
84
+ # Merge album tracks with crossfade
85
+ mediaproc-audio merge track*.mp3 -o album.mp3 --crossfade 3 --normalize
86
+
87
+ # Batch convert folder to Opus
88
+ for file in *.wav; do mediaproc-audio convert "$file" -f opus -b 192k; done
89
+
90
+ šŸš€ Quick Start:
91
+ mediaproc-audio <command> [input] [options]
92
+
93
+ šŸ“š Detailed Help:
94
+ Use 'mediaproc-audio <command> --help' for comprehensive documentation on each command.
95
+ `)
96
+ .version('1.0.0');
97
+ register(program);
98
+ program.parse(process.argv);
99
+ if (!process.argv.slice(2).length) {
100
+ program.outputHelp();
101
+ }
102
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAC9B,OAAO;KACJ,IAAI,CAAC,iBAAiB,CAAC;KACvB,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFZ,CAAC;KACD,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,QAAQ,CAAC,OAAO,CAAC,CAAC;AAClB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Command } from 'commander';
2
+ export declare function convertCommand(audioCmd: Command): void;
3
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/commands/convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAczC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAgKtD"}
@@ -0,0 +1,149 @@
1
+ import chalk from 'chalk';
2
+ import { stat } from 'fs/promises';
3
+ import { runFFmpeg, getAudioMetadata, checkFFmpeg, formatFileSize, formatDuration, } from '../utils/ffmpeg.js';
4
+ import { parseInputPaths, resolveOutputPaths, validateOutputPath } from '../utils/pathValidator.js';
5
+ import { createStandardHelp } from '../utils/helpFormatter.js';
6
+ import ora from 'ora';
7
+ export function convertCommand(audioCmd) {
8
+ audioCmd
9
+ .command('convert [input]')
10
+ .description('Convert audio files between different formats')
11
+ .option('-o, --output <path>', 'Output file or directory path')
12
+ .option('-f, --format <format>', 'Output format: mp3, aac, wav, flac, ogg, opus, m4a', 'mp3')
13
+ .option('-b, --bitrate <bitrate>', 'Audio bitrate (e.g., 128k, 192k, 320k)', '192k')
14
+ .option('-s, --sample-rate <rate>', 'Sample rate in Hz (e.g., 44100, 48000)', parseInt)
15
+ .option('-c, --channels <channels>', 'Number of channels: 1 (mono), 2 (stereo)', parseInt)
16
+ .option('-q, --quality <quality>', 'Quality preset: low, medium, high, lossless', 'medium')
17
+ .option('--codec <codec>', 'Audio codec override (libmp3lame, aac, flac, libvorbis, libopus)')
18
+ .option('--dry-run', 'Preview command without executing')
19
+ .option('-v, --verbose', 'Show detailed FFmpeg output')
20
+ .option('-h, --help', 'Display help for convert command')
21
+ .action(async (input, options) => {
22
+ if (options.help || !input) {
23
+ createStandardHelp({
24
+ commandName: 'convert',
25
+ emoji: 'šŸ”„',
26
+ description: 'Convert audio files between formats (MP3, AAC, WAV, FLAC, OGG, Opus). Supports quality presets, bitrate control, and sample rate adjustment.',
27
+ usage: [
28
+ 'convert <input> [options]',
29
+ 'convert audio.wav -f mp3',
30
+ 'convert audio-files/ -f aac -o output/'
31
+ ],
32
+ options: [
33
+ { flag: '-o, --output <path>', description: 'Output file/directory path (default: <input>-converted.<ext>)' },
34
+ { flag: '-f, --format <format>', description: 'Output format: mp3, aac, wav, flac, ogg, opus, m4a (default: mp3)' },
35
+ { flag: '-b, --bitrate <bitrate>', description: 'Audio bitrate: 128k, 192k, 256k, 320k (default: 192k)' },
36
+ { flag: '-s, --sample-rate <rate>', description: 'Sample rate: 44100 (CD quality), 48000 (studio), 96000 (Hi-Res)' },
37
+ { flag: '-c, --channels <channels>', description: 'Audio channels: 1 (mono), 2 (stereo)' },
38
+ { flag: '-q, --quality <quality>', description: 'Quality preset: low (96k), medium (192k), high (320k), lossless' },
39
+ { flag: '--codec <codec>', description: 'Codec override: libmp3lame, aac, flac, libvorbis, libopus' },
40
+ { flag: '--dry-run', description: 'Preview FFmpeg command without executing' },
41
+ { flag: '-v, --verbose', description: 'Show detailed FFmpeg output and progress' }
42
+ ],
43
+ examples: [
44
+ { command: 'convert audio.wav -f mp3', description: 'Convert WAV to MP3' },
45
+ { command: 'convert audio.mp3 -f flac -q lossless', description: 'Convert to lossless FLAC' },
46
+ { command: 'convert audio.flac -f mp3 -b 320k', description: 'Convert FLAC to high-quality MP3' },
47
+ { command: 'convert audio.mp3 -f aac -b 128k', description: 'Convert to AAC with specific bitrate' },
48
+ { command: 'convert audio.wav -f mp3 -s 48000', description: 'Convert with specific sample rate' },
49
+ { command: 'convert folder/ -f mp3 -o output/', description: 'Batch convert all audio files in folder' }
50
+ ],
51
+ });
52
+ return;
53
+ }
54
+ try {
55
+ // Check FFmpeg availability
56
+ const ffmpegAvailable = await checkFFmpeg();
57
+ if (!ffmpegAvailable) {
58
+ console.error(chalk.red('\nāœ— FFmpeg not found. Please install FFmpeg first.'));
59
+ process.exit(1);
60
+ }
61
+ // Parse and validate input/output paths
62
+ const inputPaths = parseInputPaths(input, {
63
+ allowedExtensions: ['.mp3', '.wav', '.flac', '.aac', '.ogg', '.opus', '.m4a', '.wma']
64
+ });
65
+ const outputDir = validateOutputPath(options.output);
66
+ const outputPathsMap = resolveOutputPaths(inputPaths, outputDir, {
67
+ suffix: '-converted',
68
+ newExtension: `.${options.format}`
69
+ });
70
+ const outputPaths = Array.from(outputPathsMap.values());
71
+ // Quality presets
72
+ const qualityMap = {
73
+ low: '96k',
74
+ medium: '192k',
75
+ high: '320k',
76
+ lossless: 'lossless'
77
+ };
78
+ const targetBitrate = qualityMap[options.quality] || options.bitrate;
79
+ // Process each file
80
+ for (let i = 0; i < inputPaths.length; i++) {
81
+ const inputFile = inputPaths[i];
82
+ const outputFile = outputPaths[i];
83
+ console.log(chalk.blue(`\nšŸ”„ Converting: ${inputFile}`));
84
+ // Get metadata
85
+ const metadata = await getAudioMetadata(inputFile);
86
+ const inputStat = await stat(inputFile);
87
+ console.log(chalk.dim(`Duration: ${formatDuration(metadata.duration)} • ` +
88
+ `Sample Rate: ${metadata.sampleRate} Hz • ` +
89
+ `Channels: ${metadata.channels}`));
90
+ // Build FFmpeg args
91
+ const args = ['-i', inputFile, '-y'];
92
+ // Codec selection
93
+ const codecMap = {
94
+ mp3: 'libmp3lame',
95
+ aac: 'aac',
96
+ m4a: 'aac',
97
+ flac: 'flac',
98
+ wav: 'pcm_s16le',
99
+ ogg: 'libvorbis',
100
+ opus: 'libopus',
101
+ };
102
+ const codec = options.codec || codecMap[options.format];
103
+ if (codec) {
104
+ args.push('-c:a', codec);
105
+ }
106
+ // Bitrate
107
+ if (targetBitrate !== 'lossless') {
108
+ args.push('-b:a', targetBitrate);
109
+ }
110
+ // Sample rate
111
+ if (options.sampleRate) {
112
+ args.push('-ar', options.sampleRate.toString());
113
+ }
114
+ // Channels
115
+ if (options.channels) {
116
+ args.push('-ac', options.channels.toString());
117
+ }
118
+ args.push(outputFile);
119
+ // Dry run
120
+ if (options.dryRun) {
121
+ console.log(chalk.yellow('\n[DRY RUN] Would execute:'));
122
+ console.log(chalk.dim(`ffmpeg ${args.join(' ')}`));
123
+ continue;
124
+ }
125
+ // Execute conversion
126
+ const spinner = ora('Converting...').start();
127
+ try {
128
+ await runFFmpeg(args, options.verbose);
129
+ const outputStat = await stat(outputFile);
130
+ spinner.succeed(chalk.green('Conversion complete'));
131
+ console.log(chalk.green(`āœ“ Output: ${outputFile}`));
132
+ console.log(chalk.dim(`Size: ${formatFileSize(inputStat.size)} → ${formatFileSize(outputStat.size)}`));
133
+ }
134
+ catch (error) {
135
+ spinner.fail(chalk.red('Conversion failed'));
136
+ throw error;
137
+ }
138
+ }
139
+ if (inputPaths.length > 1) {
140
+ console.log(chalk.green(`\nāœ“ Converted ${inputPaths.length} files successfully`));
141
+ }
142
+ }
143
+ catch (error) {
144
+ console.error(chalk.red(`\nāœ— Error: ${error.message}`));
145
+ process.exit(1);
146
+ }
147
+ });
148
+ }
149
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/commands/convert.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,UAAU,cAAc,CAAC,QAAiB;IAC9C,QAAQ;SACL,OAAO,CAAC,iBAAiB,CAAC;SAC1B,WAAW,CAAC,+CAA+C,CAAC;SAC5D,MAAM,CAAC,qBAAqB,EAAE,+BAA+B,CAAC;SAC9D,MAAM,CAAC,uBAAuB,EAAE,oDAAoD,EAAE,KAAK,CAAC;SAC5F,MAAM,CAAC,yBAAyB,EAAE,wCAAwC,EAAE,MAAM,CAAC;SACnF,MAAM,CAAC,0BAA0B,EAAE,wCAAwC,EAAE,QAAQ,CAAC;SACtF,MAAM,CAAC,2BAA2B,EAAE,0CAA0C,EAAE,QAAQ,CAAC;SACzF,MAAM,CAAC,yBAAyB,EAAE,6CAA6C,EAAE,QAAQ,CAAC;SAC1F,MAAM,CAAC,iBAAiB,EAAE,kEAAkE,CAAC;SAC7F,MAAM,CAAC,WAAW,EAAE,mCAAmC,CAAC;SACxD,MAAM,CAAC,eAAe,EAAE,6BAA6B,CAAC;SACtD,MAAM,CAAC,YAAY,EAAE,kCAAkC,CAAC;SACxD,MAAM,CAAC,KAAK,EAAE,KAAyB,EAAE,OAAY,EAAE,EAAE;QACxD,IAAI,OAAO,CA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,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC;oBAC7C,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;YAED,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,iBAAiB,UAAU,CAAC,MAAM,qBAAqB,CAAC,CAAC,CAAC;YACpF,CAAC;QAEH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,cAAe,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACnE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Command } from 'commander';
2
+ export declare function extractCommand(audioCmd: Command): void;
3
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/commands/extract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAczC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CA2JtD"}