2016-08-15 2 views
0
var fs = require('fs'); 
var child = require('child_process'); 
var http=require('http') 
var input_file = fs.createReadStream('./remo.mp3'); 
http.createServer(function (req,res) { 
var args = ['-ss',120, 
'-i', 'remo.mp3', 
'-f','mp3', 
'pipe:1' // Output on stdout 
]; 
var trans_proc = child.spawn('ffmpeg', args); 
res.writeHead(200, { 
     'Content-Type': 'audio/mpeg' 
    }); 

trans_proc.stdout.pipe(res) 
trans_proc.stderr.on('data',function (err) { 
console.log(err.toString()); 
}) 
}).listen(2000) 

Ich versuche, die mp3 und Streaming an den Browser zu schneiden aber in Browser es beschädigte Datei zeigtmp3 ffmpeg über js Knoten Streaming

Antwort

0

Ich kann nicht sagen, ob Sie über fragen ein YouTube-Video Download als mp3 using node - aber dieser thread tauchte bei Google auf, als ich genau das forschte. Also, wenn nicht, vielleicht kann es dich in die richtige Richtung weisen oder jemandem in der Zukunft helfen ... Mods - Entschuldigung, wenn ich das nicht richtig mache.

Additional StackOverflow Reference

Aber ich bin mit dem folgenden Code Download ein youtube vid als mp3 (Download youtube vid/konvertieren zu mp3/download) zu tun:

module.exports.toMp3 = function(req, res, next){ 
var id = req.params.id; // extra param from front end 
var title = req.params.title; // extra param from front end 
var url = 'https://www.youtube.com/watch?v=' + id; 
var stream = youtubedl(url); //include youtbedl ... var youtubedl = require('ytdl'); 

//set response headers 
res.setHeader('Content-disposition', 'attachment; filename=' + title + '.mp3'); 
res.setHeader('Content-type', 'audio/mpeg'); 

//set stream for conversion 
var proc = new ffmpeg({source: stream}); 

//currently have ffmpeg stored directly on the server, and ffmpegLocation is the path to its location... perhaps not ideal, but what I'm currently settled on. And then sending output directly to response. 
proc.setFfmpegPath(ffmpegLocation); 
proc.withAudioCodec('libmp3lame') 
    .toFormat('mp3') 
    .output(res) 
    .run(); 
proc.on('end', function() { 
    console.log('finished'); 
}); 

};

Verwandte Themen