1

我对视频流真的很陌生,这让我很困惑

前端:Video.js

<video id="example_video_1" controls="" preload="auto" width="854" height="480" poster="/thumb/1405003437328.mp4-thumbnail-1-undefinedxundefined.jpg" data-setup="{&quot;example_option&quot;:true}" class="video-js vjs-default-skin">
  <source src="/stream/53bea6ad7ff1919812067e74">
</video>

这个视频我有两条路线

第一条路线

 /video/video._id/videoname.mp4
 I use this route to render the video streaming html which include a video tag

 exports.get = function(req, res) {
    Video.findById(req.params._id, function(err, video) {
        if (err) {
            res.send(500, {
                error: err
            })
        }
        res.render('video', {
            video: video
        })
    })
 }

第二条路线

 /stream/video._id
 I use this video for streaming

 exports.stream = function(req, res) {
     Video.findById(req.params._id, function(err, video) {
        if (err) {
            throw err
        }
        console.log(video)
        var videopath = path.join(__dirname, '../../userUpload/', video.src);
        console.log(videopath)

        res.contentType('flv');
    // make sure you set the correct path to your video file storage

        var proc =new  ffmpeg({source: videopath})
            // use the 'flashvideo' preset (located in /lib/presets/flashvideo.js)
            .usingPreset('flashvideo')
            // 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
            .writeToStream(res, {
                end: true
            });
        })
    }

我使用 fluent-ffmpeg 流式传输视频,上面的代码在它的示例中

提供第一条路线时,它会请求 /stream/video._id 路线,但是当我点击网络上的播放按钮时,什么也没发生,请帮助我理解视频流!

谢谢

4

0 回答 0