美文网首页
fluent-ffmpeg express fmp4

fluent-ffmpeg express fmp4

作者: 此昵称已被狗抢占 | 来源:发表于2018-04-26 04:54 被阅读0次
    const fs = require('fs');
    const ffmpegPath = require('ffmpeg-static').path;
    const ffmpeg = require('fluent-ffmpeg');
    ffmpeg.setFfmpegPath(ffmpegPath);
    
    
    const express = require('express');
    const app = express();
    
    app.use(express.static(__dirname + '/public'));
    
    app.get('/', function (req, res) {
      res.send('index.html');
    });
    
    app.get('/video/:filename', function (req, res) {
      res.contentType('mp4');
      // make sure you set the correct path to your video file storage
      var pathToMovie = 'public/' + req.params.filename;
      var proc = ffmpeg(pathToMovie)
        // use the 'flashvideo' preset (located in /lib/presets/flashvideo.js)
        .outputOptions('-movflags','frag_keyframe+empty_moov')
        .noAudio()
        .videoCodec('copy')
        .format('mp4')
        // setup event handlers
        .on('end', function () {
          console.log('file has been converted succesfully');
        })
        .on('error', function (err) {
          console.log('an error happened: ' + err.message);
        })
        // save to stream
        .pipe(res, { end: true });
    });
    
    app.listen(4000);
    

    相关文章

      网友评论

          本文标题:fluent-ffmpeg express fmp4

          本文链接:https://www.haomeiwen.com/subject/cnnulftx.html