2016-02-25 72 views
0

我嘗試包括在NA視頻流字幕(SRT)與節點JS和FFmpeg的......我試試這個遠:字幕與和的NodeJS流利的FFmpeg中阿比視頻

var command = ffmpeg(file.createReadStream()) 
    .input("C:\\code.srt").videoCodec('copy') 
    .videoCodec('libvpx').audioCodec('libvorbis').format('webm') 
    .audioBitrate(128) 
    .videoBitrate(1024) 
    .inputFPS(75) 
    .outputOptions([ 
    '-deadline realtime', 
    '-error-resilient 1' 
    ]) 

而且我得到了這個錯誤:

[Error: ffmpeg exited with code 1: Encoder (codec none) not found for output stream #0:2 

試試這也與FFmpeg的了文件的--vf subititles =和我得到這個錯誤:

var command = ffmpeg(file.createReadStream()) 
     .videoCodec('libvpx').audioCodec('libvorbis').format('webm') 
     .audioBitrate(128) 
     .videoBitrate(1024) 
     .inputFPS(75) 
     .outputOptions([ 
     '-deadline realtime', 
     '-vf subtitles=C:\\code.srt', 
     '-error-resilient 1' 
     ]) 

Error: ffmpeg exited with code 1: Error opening filters! 

有人ķ使用Node.JS中的FFMpeg Fluent Api消除嵌入式字幕

對不起我的英語,我是巴西人!感謝這麼多

+0

「FFmpeg的流暢API」 是[節點流利-的ffmpeg](https://github.com/fluent-ffmpeg/node-fluent-ffmpeg)封裝。請按照[錯誤處理]文檔(https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#error-transcoding-error)獲取有關更多詳細信息的「stdout」消息。 –

回答

1

我解決了這個通過將任務分爲兩個部分

  1. 添加字幕和本地保存的視頻 代碼:

    var addSubtitles = function(key, callback) { 
        console.log("inside addSubtitles"); 
        ffmpeg('./' + key + '.mp4') 
         .videoCodec('libx264') 
         .audioCodec('libmp3lame') 
         .outputOptions(
          '-vf subtitles=./jellies.srt' 
         ) 
         .on('error', function(err) { 
          callback(true, err) 
         }) 
         .save('./moviewithsubtitle.mp4') 
         .on('end', function() { 
          callback(false, "done"); 
         }) 
    } 
    
  2. 發送視頻與字幕

    var streaming = function(req, res, newpath) { 
        var path = './' + newpath + '.mp4'; 
        var stat = fs.statSync(path); 
        var total = stat.size; 
        if (req.headers['range']) { 
         var range = req.headers.range; 
         var parts = range.replace(/bytes=/, "").split("-"); 
         var partialstart = parts[0]; 
         var partialend = parts[1]; 
    
         var start = parseInt(partialstart, 10); 
         var end = partialend ? parseInt(partialend, 10) : total - 1; 
         var chunksize = (end - start) + 1; 
         console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize); 
    
         var file = fs.createReadStream(path, { 
          start: start, 
          end: end 
         }); 
         res.writeHead(206, { 
          'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 
          'Accept-Ranges': 'bytes', 
          'Content-Length': chunksize, 
          'Content-Type': 'video/mp4' 
         }); 
         file.pipe(res); 
        } else { 
         console.log('ALL: ' + total); 
         res.writeHead(200, { 
          'Content-Length': total, 
          'Content-Type': 'video/mp4' 
         }); 
         fs.createReadStream(path).pipe(res); 
        } 
    } 
    

所以現在我的整個程序變得

var ffmpeg = require('fluent-ffmpeg'); 
    var fs = require('fs'); 
    var express = require('express'); 
    var app = express(); 
    var uuid = require('node-uuid'); 
    var port = 8000; 


    var addSubtitles = function(key, callback) { 
     console.log("inside addSubtitles"); 
     ffmpeg('./' + key + '.mp4') 
      .videoCodec('libx264') 
      .audioCodec('libmp3lame') 
      .outputOptions(
       '-vf subtitles=./jellies.srt' 
      ) 
      .on('error', function(err) { 
       callback(true, err) 
      }) 
      .save('./moviewithsubtitle.mp4') 
      .on('end', function() { 
       callback(false, "done"); 
      }) 
    } 

    var streaming = function(req, res, newpath) { 
     var path = './' + newpath + '.mp4'; 
     var stat = fs.statSync(path); 
     var total = stat.size; 
     if (req.headers['range']) { 
      var range = req.headers.range; 
      var parts = range.replace(/bytes=/, "").split("-"); 
      var partialstart = parts[0]; 
      var partialend = parts[1]; 

      var start = parseInt(partialstart, 10); 
      var end = partialend ? parseInt(partialend, 10) : total - 1; 
      var chunksize = (end - start) + 1; 
      console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize); 

      var file = fs.createReadStream(path, { 
       start: start, 
       end: end 
      }); 
      res.writeHead(206, { 
       'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 
       'Accept-Ranges': 'bytes', 
       'Content-Length': chunksize, 
       'Content-Type': 'video/mp4' 
      }); 
      file.pipe(res); 
     } else { 
      console.log('ALL: ' + total); 
      res.writeHead(200, { 
       'Content-Length': total, 
       'Content-Type': 'video/mp4' 
      }); 
      fs.createReadStream(path).pipe(res); 
     } 
    } 



    app.get('/subs', function(req, res) { 
     addSubtitles("movie", function(error, newpath) { 
      if (error) { 
       res.send("error : " + error) 
      } else { 
       console.log("done"); 
       res.end(); 
      } 
     }) 
    }) 


    app.get('/', function(req, res) { 
     streaming(req, res, "moviewithsubtitle"); 
    }) 

    app.listen(port); 
    console.log("the server is running at port :", port);