forked from transitive-bullshit/ffmpeg-concat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f400557
commit 6a82d48
Showing
9 changed files
with
7,449 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ dist | |
.env.test.local | ||
.env.production.local | ||
.cache | ||
.vscode | ||
|
||
temp | ||
out.mp4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const ffmpeg = require('fluent-ffmpeg') | ||
|
||
module.exports = (opts) => { | ||
const { | ||
log, | ||
videoPath, | ||
outputFileName, | ||
start, | ||
duration | ||
} = opts | ||
|
||
return new Promise((resolve, reject) => { | ||
const cmd = ffmpeg(videoPath) | ||
.noVideo() | ||
.audioCodec('libmp3lame') | ||
.on('start', cmd => log({ cmd })) | ||
.on('end', () => resolve(outputFileName)) | ||
.on('error', (err) => reject(err)) | ||
if (start) { | ||
cmd.seekInput(start) | ||
} | ||
if (duration) { | ||
cmd.duration(duration) | ||
} | ||
cmd.save(outputFileName) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
const fs = require('fs-extra') | ||
const path = require('path') | ||
const ffmpeg = require('fluent-ffmpeg') | ||
|
||
module.exports = async (opts) => { | ||
const { | ||
log, | ||
scenes, | ||
outputDir, | ||
fileName | ||
} = opts | ||
|
||
return new Promise((resolve, reject) => { | ||
const concatListPath = path.join(outputDir, 'audioConcat.txt') | ||
const toConcat = scenes.filter(scene => scene.sourceAudioPath).map(scene => `file '${scene.sourceAudioPath}'`) | ||
const outputFileName = path.join(outputDir, fileName) | ||
fs.outputFile(concatListPath, toConcat.join('\n')).then(() => { | ||
log(`created ${concatListPath}`) | ||
const cmd = ffmpeg() | ||
.input(concatListPath) | ||
.inputOptions(['-f concat', '-safe 0']) | ||
.on('start', cmd => log(cmd)) | ||
.on('end', () => resolve(outputFileName)) | ||
.on('error', (err, stdout, stderr) => { | ||
if (err) { | ||
console.error('failed to concat audio', err, stdout, stderr) | ||
} | ||
reject(err) | ||
}) | ||
cmd.save(outputFileName) | ||
}).catch(err => { | ||
console.error(`failed to concat audio ${err}`) | ||
reject(err) | ||
}) | ||
}) | ||
} |
Binary file not shown.
Oops, something went wrong.