【问题标题】:ffmpeg mp3 streaming via node jsffmpeg mp3 通过节点 js 流式传输
【发布时间】:2016-12-21 12:02:40
【问题描述】:
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)

我正在尝试剪切 mp3 并流式传输到浏览器,但在浏览器中它显示损坏的文件

【问题讨论】:

    标签: node.js ffmpeg node-streams fluent-ffmpeg


    【解决方案1】:

    我不知道您是否在询问是否使用节点下载 youtube 视频作为 mp3 格式 - 但是当我正在研究该主题时,此主题突然出现在 google 之上。所以,如果不是,也许它可以为您指明正确的方向或在未来帮助某人...... Mods - 抱歉,如果我做的不对。

    Additional StackOverflow Reference

    但我正在使用以下代码将 youtube vid 下载为 mp3(下载 youtube vid/转换为 mp3/下载):

    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');
    });
    

    };

    【讨论】:

      猜你喜欢
      • 2012-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-10
      • 2015-07-09
      • 2016-03-19
      • 2011-03-06
      • 2014-03-19
      相关资源
      最近更新 更多