ffmpeg nodejs中使用

2021-07-01 15:03

阅读:404

var exec = require(‘child_process‘).exec;
var Ffmpeg = require(‘fluent-ffmpeg‘);
var config = require(‘../config‘)
// module.exports = {
function generatTsfile (activity,sourceFile) {
// var source
// var commandStr = ‘ffmpeg -i ‘;
// commandStr += config.videodirectory + videoFile ;
// commandStr += ‘ -y -vcodec copy -acodec copy -map 0 -f segment -segment_list ‘;
// commandStr +=+ config.videodirectory + ‘‘
var commandStr = ‘ffmpeg -i D:/desktop/testfile/1.flv -y -vcodec copy -acodec copy -map 0 -f segment -segment_list D:/desktop/testfile/test1.m3u8 -segment_time 10 D:/desktop/testfile/test-%03d.ts‘

var command = Ffmpeg(‘D:/desktop/testfile/454224124c08470a90a9eaa0b3cb885a/123224124c08470a90a9eaa0b3cb6666/sourceVideo/1080p_3_2.mp4‘)
.save(‘D:/desktop/testfile/454224124c08470a90a9eaa0b3cb885a/123224124c08470a90a9eaa0b3cb6666/ts/1080p_3_2-%03d.ts‘)
.outputOptions([
‘-y‘,
‘-vcodec copy‘,
‘-acodec copy‘,
‘-map 0‘,
‘-f segment‘,
‘-segment_list D:/desktop/testfile/454224124c08470a90a9eaa0b3cb885a/123224124c08470a90a9eaa0b3cb6666/sourceVideo/1080p_3_2.m3u8‘,
‘-segment_time 10‘]
)

// .takeScreenshots({ timemarks: [ ‘00:00:02.000‘ ],
// size: ‘150x100‘,
// filename:‘thumbnail-at-%s-%00i-seconds.jpg‘
// }
// , ‘D:/desktop/testfile‘);

command
.on(‘progress‘, function(info) {
console.log(‘progress ‘ + info.percent + ‘%‘);
})
.on(‘filenames‘, function(filenames) {
console.log(‘screenshots are ‘ + filenames.join(‘, ‘));
})
.on(‘error‘, function(err) {
console.log(‘An error occurred: ‘ + err.message);
})
.on(‘end‘, function() {
console.log(‘Merging finished !‘);
})
}

var num = 0;
function generateImage(i) {

console.log(i,num++);
// var commandStr = ‘ffmpeg -i D:/desktop/testfile/1.mp4 -f image2 -vf fps=fps=1/2 -q:v 0 D:/desktop/testfile/test-%02d.jpg‘;

var command = Ffmpeg(‘D:/desktop/testfile/454224124c08470a90a9eaa0b3cb885a/123224124c08470a90a9eaa0b3cb6666/ts/1080p_3_2-‘+i+‘.ts‘)
.save(‘D:/desktop/testfile/454224124c08470a90a9eaa0b3cb885a/123224124c08470a90a9eaa0b3cb6666/thumbnailtmp/1080p_3_2-‘+i+‘-%02d.jpg‘)
.outputOptions([
‘-y‘,
‘-f image2‘,
‘-vf fps=fps=1/2‘,
‘-q:v 0‘
])
// .videoFilter(‘fps=fps=1/2‘)
// .takeScreenshots({
// //timemarks: [ ‘00:00:02.000‘ ],
// size: ‘150x100‘,
// filename:‘thumbnail-at-%s-%00i-seconds.jpg‘
// }
// , ‘D:/desktop/testfile‘);

command
.on(‘progress‘, function(info) {
//console.log(‘progress ‘ + info.percent + ‘%‘);
})
.on(‘filenames‘, function(filenames) {
//console.log(‘screenshots are ‘ + filenames.join(‘, ‘));
})
.on(‘error‘, function(err) {
//console.log(‘An error occurred: ‘ + err.message);
})
.on(‘end‘, function() {
//console.log(‘Merging finished !‘);
})


}
// generatTsfile()

//
var count = 0;
function generate() {
// setTimeout(function () {

var str = count.toString().length === 1 ? ‘00‘+count : ‘0‘+count;
generateImage(str)
count ++;
console.log(count,str);
if(count generate();

// },10000)
}

generate();

// //切片生成图片
// var exec = require(‘child_process‘).exec;
// var commandStr = ‘ffmpeg -i D:/desktop/testfile/1.mp4 -f image2 -vf fps=fps=1/2 D:/desktop/testfile/test-%02d.jpg&exit‘;
// var time = new Date();
// exec(commandStr,function (err,data,data1) {
// console.log(new Date() - time);
// })


// var tsStr = ‘ffmpeg -i D:/desktop/testfile/1.mp4 -c:v libx264 -c:a aac -strict -2 -f hls output.m3u8‘;
//
//生成切片
// var generalTsStr = ‘ffmpeg -i D:/desktop/testfile/1.flv -y -vcodec copy -acodec copy -map 0 -f segment -segment_list D:/desktop/testfile/test1.m3u8 -segment_time 10 D:/desktop/testfile/test-%03d.ts‘
//
// var time = new Date();
// exec(generalTsStr,function (error, stdout, stderr) {
// console.log(new Date() - time);
// })

// var spawn = require(‘child_process‘).spawn;

//Set the path to where FFmpeg is installed
//proc.setFfmpegPath("D:\\ffmpeg-3.0\\vs2013_build\\bin\\ffmpeg.exe"); //I forgot to include "ffmpeg.exe"


// ffmpeg(‘D:/desktop/testfile/1.mp4‘)
// .videoCodec(‘libx264‘)
// .audioCodec(‘libmp3lame‘)
// .size(‘320x240‘)
// .on(‘error‘, function(err) {
// console.log(‘An error occurred: ‘ + err.message);
// })
// .on(‘end‘, function() {
// console.log(‘Processing finished !‘);
// })
// .save(‘D:/desktop/testfile/output.mp4‘);

// ffmpeg(‘D:/desktop/testfile/1.mp4‘)
// .on(‘stderr‘, function(stderrLine) {
// console.log(‘Stderr output: ‘ + stderrLine);
// })
// .on(‘progress‘, function(progress) {
// console.log(‘Processing: ‘ + progress.percent + ‘% done‘);
// })
// .on(‘error‘, function(err, stdout, stderr) {
// console.log(‘Cannot process video: ‘ + err.message);
// })
// .on(‘end‘, function(stdout, stderr) {
// console.log(‘Transcoding succeeded !‘);
// });;;

// var command = ffmpeg(‘D:/desktop/testfile/1.mp4‘)
// .audioCodec(‘libfaac‘)
// .videoCodec(‘libx264‘)
// .format(‘mp4‘);
//
// command.clone()
// .size(‘320x200‘)
// .save(‘D:/desktop/testfile/11.mp4‘);


// ffmpeg(‘D:/desktop/testfile/1.mp4‘)
// .screenshots({
// timestamps: [30.5, ‘50%‘, ‘00:10.123‘],
// filename: ‘thumbnail-at-%s-seconds.png‘,
// folder: ‘D:/desktop/testfile/output‘,
// size: ‘320x240‘
// });
// //


评论


亲,登录后才可以留言!