const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpeg = require('fluent-ffmpeg');
const process = require('process');
const args = process.argv.slice(2);
if (args.length !== 4) {
console.error('Incorrect number of arguments');
process.exit(1);
}
const startTime = args[0];
const timeDuration = args[1];
const inputFile = args[2];
const outputFile=args[3];
ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg(inputFile)
.setStartTime(startTime)
.setDuration(timeDuration)
.output(outputFile)
.on('end', function(err) {
if(!err) { console.log('conversion Done') }
})
.on('error', function(err){
console.log('error: ', err)
}).run();
Here is my index.js file which can create clips from any video file (mkv,mp4,ts,etc.).
I run
node index.js 0:15 20 ../../video/sample.mp4 ../../video/output.mp4
This command creates a new file in a specific folder of my choice. I am running slice method to remove first two arguments and extract the last 4 args to create a clip.
But I don't know how to create a clip from a m3u8 file such as
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:13
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:12.960000,
test0.ts
#EXTINF:8.760000,
test1.ts
#EXTINF:10.520000,
test2.ts
#EXTINF:9.800000,
test3.ts
#EXTINF:10.000000,
test4.ts
#EXTINF:10.240000,
test5.ts
#EXT-X-ENDLIST
let's say I wanna create a 20 seconds file that starts the 15th second so it will start from test1.ts at 3s and then will move to the next file test2.ts and then it will take only the first 5 seconds of test3.ts to create a total 20s file and give output.
I'm pretty much stuck in this. Is there a way to do that like I'm doing using arguments???
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…