node.js - nodejs 将两个视频连接在一起?

标签 node.js video request

所以我正在研究一个概念,虽然我知道我可以使用 FFMPEG 来做我需要做的事情,但我希望有一种方法可以使用 nodejs Request 将视频加入到另一个视频的末尾。

以下代码适用于音频,我使用的视频文件是 MP4(请注意,我正在尝试将同一视频连接在一起,因此应该是 18 秒而不是 9 秒。

URL = https://storage.googleapis.com/ad-system/testfolder/Video/10%20second%20video%20FAIL.mp4

const express = require('express');
request = require('request');


const router = new express.Router();

router.get(':url(*)', (req, res) =>{


    var url = req.params.url.substr(1); 
    res.set({
        "Content-Type": "video/mp4",
        'Transfer-Encoding': 'chunked'
    });


    var clients = [];
    ASystem();
    var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
    console.log;(req.params.url);
    /* START A FUNCTION */
    function ASystem(){

                var remote = "https://storage.googleapis.com/ad-system/testfolder/Video/10%20second%20video%20FAIL.mp4";
                var streama = request.get(remote);
                streama.on("connect", function() {
                    console.error(" connected!");
                    console.error(streama.headers);
                });

                streama.on("end", function() {
                    console.error(" END");
                    console.log(url);
                   if(url !== ""){getVideo();}
                    console.error(streama.headers);
                // test = true;

                });

                // Fired after the HTTP response headers have been received.
                streama.on('response', function(res) {
                console.error(" Completed");
                    console.error(res.headers);
                });


                // When a chunk of data is received on the stream, push it to all connected clients
                streama.on("data", function (chunk) {
                        // console.log(clients.length);
                        if (clients.length > 0){
                            for (client in clients){
                                clients[client].write(chunk);
                            };
                        }

                });
    };
/* END A FUNCTION */
/* FETCHING URLVIDEO */
    function getVideo(){
        var remote = url;   
        var streama = request.get(remote);
        streama.on("connect", function() {
            console.error(" Stream connected!");
            //console.error(stream.headers);
        });

        streama.on("end", function() {
            console.error(" Stream END");
        // setTimeout(function(){ test = true; console.error('yep yep yep')},29000);
            //console.error(stream.headers);
        // test = true;
        //getVideo();
        });

        // Fired after the HTTP response headers have been received.
        streama.on('response', function(res) {
        // console.error("Stream response!");
            console.error(res.headers);
        });


        // When a chunk of data is received on the stream, push it to all connected clients
        streama.on("data", function (chunk) {
                // console.log(clients.length);
                if (clients.length > 0){
                    for (client in clients){
                        clients[client].write(chunk);
                    };
                }

        });

    }
    /* END VIDEO*/

    /* CORE SYSTEM */

      clients.push(res);

    /* END CORE SYSTEM */
});
module.exports = router;

最佳答案

我查看了一下,发现了一些可能有帮助的东西,NPM 上有一个名为 video-stitch 的包。 here's a link

有了它,您可以使用以下代码合并 2 个视频

'use strict';

let videoStitch = require('video-stitch');

let videoMerge = videoStitch.merge;

videoMerge()
  .original({
    "fileName": "FILENAME",
    "duration": "hh:mm:ss"
  })
  .clips([
    {
      "startTime": "hh:mm:ss",
      "fileName": "FILENAME",
      "duration": "hh:mm:ss"
    },
    {
      "startTime": "hh:mm:ss",
      "fileName": "FILENAME",
      "duration": "hh:mm:ss"
    },
    {
      "startTime": "hh:mm:ss",
      "fileName": "FILENAME",
      "duration": "hh:mm:ss"
    }
  ])
  .merge()
  .then((outputFile) => {
    console.log('path to output file', outputFile);
  });

希望这可以帮助!

关于node.js - nodejs 将两个视频连接在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60237687/

相关文章:

video - FFMPEG 视频转换为 MP4 可以在除 iOS Safari/Chrome 之外的任何地方使用

video - FFmpeg:省略 -filter_complex 会导致某些播放器中的视频丢失

java - 通过 Java 的 Odoo 请求

javascript - axios - 从响应对象中获取请求 URI 数据

Node.js - 如何跨平台找到 'desktop'目录路径?

javascript - 如何在 JavaScript/node.js 中删除 HTTP 响应 header 中的无效字符?

url - 使用fiddler抓取video steam url

javascript - 发送 GET 请求并将响应重定向到浏览器以下载文件

node.js - ExpressJS 和 NodeJS 中 Mongoose 响应对象中的排序键

javascript - 方法在创建的钩子(Hook) Vue.js 中不起作用