https://github.com/sugiruu/media-split
Split media files
https://github.com/sugiruu/media-split
cli ffmpeg media mp3 nodejs split video
Last synced: 10 months ago
JSON representation
Split media files
- Host: GitHub
- URL: https://github.com/sugiruu/media-split
- Owner: sugiruu
- License: mit
- Created: 2016-12-16T13:05:13.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-10T18:09:18.000Z (about 4 years ago)
- Last Synced: 2025-04-03T23:02:10.541Z (10 months ago)
- Topics: cli, ffmpeg, media, mp3, nodejs, split, video
- Language: JavaScript
- Homepage:
- Size: 2.44 MB
- Stars: 22
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Media-split
[](https://github.com/skiptirengu/media-split/actions)
Split audio (and video) files
## Install
Make sure you have [ffmpeg](https://ffmpeg.org/) installed and added to your path then run:
```bash
npm install [-g] media-split
```
If you don't have ffmpeg installed, you can install [this](https://www.npmjs.com/package/ffmpeg-static) or [this](https://www.npmjs.com/package/@ffmpeg-installer/ffmpeg) package which
comes with a bundled ffmpeg, and media-split will automatically detect and use it.
```bash
npm install [-g] ffmpeg-static
```
or
```bash
npm install [-g] @ffmpeg-installer/ffmpeg
```
## CLI
media-split comes with a built in CLI tool. Type `media-split -h` to list all options and see an usage example.
For input you can use either a YouTube link or a local file.
The template file should be in the following format.
For more info, checkout [ffmpeg's duration syntax](https://ffmpeg.org/ffmpeg-utils.html#Time-duration) page.
```
[([hh:]mm:ss[.ms...]) [ - ([hh:]mm:ss[.ms...])]] My Music Name
```
A template file usually looks like this:
```
[00:00] eli filosov [ p h i l o ] - oneofone_rwrk
[01:30] Swishers [SwuM x bsd.u]
[03:28] sweetbn _ i held you so close i forgot the world
[05:52 - 07:49] emune - Gretchen
[07:52 - 09:50] jhfly - sheets
[10:00] arbour - elusive
[11:30] tomppabeats - will you stay here with me
[12:40] tomppabeats - lonely but not when you hold me
[13:31 - 15:30] Bassti - To All The Ladys In The Place
[15:37] wish you still felt this way [ sophie meiers x 90sFlav ]
```
## Known issues
Sometimes, when downloading videos from YouTube, media-split can fail with the error message "Too many redirects".
This is caused by a third party library and is already being tracked [here](https://github.com/fent/node-ytdl-core/issues/212).
## Library
You can also use media-split as a library.
```js
let MediaSplit = require('media-split');
let split = new MediaSplit({ input: 'myaudio.mp3', sections: ['[01:30] My audio'] });
split.parse().then((sections) => {
for (let section of sections) {
console.log(section.name); // filename
console.log(section.start); // section start
console.log(section.end); // section end
console.log(section.trackName); // track name
}
});
```
### new MediaSplit(options)
**Returns**: MediaSplit
| Param | Type | Description |
| --- | --- | --- |
| options | object | |
| options.downloadCover | boolean | Whether to download the cover from the YouTube video |
| options.input | string | The input file. Can be either a file path or a YouTube url |
| options.concurrency | number | Number of parallel workers MediaSplit will spawn at once |
| options.sections | Array.<string> | Sections to extract from the input source. Supported formats are `[01:30 - 03:50] File` or `[01:30] File` |
| options.output | string | Output path |
| options.format | string | Output format (mp3, m4a, flac, etc) |
| options.audioonly | boolean | Force download only audio files when using a url as input |
| options.quality | string | The download quality when downloading from YouTube (highest/lowest/highestaudio/lowestaudio/highestvideo/lowestvideo) |
| options.inputParams | Array.<string> | Additional input parameters for FFMpeg
| options.outputParams | Array.<string> | Additional output parameters for FFMpeg
### MediaSplit.parse() ⇒ Promise.<Array.<object>>
Split the media
### "url" (input, info, cached)
URL event. This event is emitted only once.
| Param | Type | Description |
| --- | --- | --- |
| input | string | The input file |
| info | object | The video info |
| cached | boolean | Whether the file was cached or not |
### "data" (sections)
Data event. This event is emitted only once.
| Param | Type | Description |
| --- | --- | --- |
| sections | Array.<object> | Array with the parsed sections |
### "beforeSplit" (info, index)
Emitted before a section is split.
| Param | Type | Description |
| --- | --- | --- |
| info | object | Section info |
| index | number | Index |
### "afterSplit" (info, index)
Emitted after a section is split.
| Param | Type | Description |
| --- | --- | --- |
| info | object | Section info |
| index | number | Section index |
### "downloadProgress" (chunk, downloaded, total)
Download progress.
| Param | Type | Description |
| --- | --- | --- |
| chunk | number | Chunk length in bytes |
| downloaded | number | Total downloaded in bytes |
| total | number | Total download length in bytes |
### "downloadLength" (length)
Total download length. This event is emitted only once.
| Param | Type | Description |
| --- | --- | --- |
| length | number | Length in bytes |
## License
Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence)
[MIT license](http://creativecommons.org/licenses/MIT/)