使用PhantomJS&ffmpeg将多个请求记录到/ dev/stdout导致网页流导致ffmpeg错误

All*_*ira 5 ffmpeg node.js phantomjs

首先,抱歉我的英语.

我正在追求几天.我到处研究过,找不到问题的答案.

我在这个场景中使用Nodejs,Phantomjs和ffmpeg:

  • 用户进入该站点,使用Facebook登录,他可以要求提供带有他的名字和一些随机照片的视频(通过/我/通过JSON POST收集);
  • 节点接收用户数据,创建子进程(PhantomJS + ffmpeg)并等待响应以将视频URL发送给用户.

当我运行此请求的单个实例时,一切正常.但是,当两个或多个用户发出请求时,只发送一个视频,其他进程最终出现ffmpeg流错误.

我认为原因是所有ffmpeg进程都使用相同的位置(/ dev/stdout).由于一个进程已在使用它,其他进程将进入"无法访问"错误.但这是一个假设,我不知道/ dev/stdout是如何工作的.

这是我的代码.(我删除了一些行并重命名了一些变量以便更好地理解,抱歉任何错误)

index.js:

var generateVideo = 'phantomjs phantom.js '+videoID+' '+userID+' | ffmpeg -vcodec png -f image2pipe -r 30 -i - -pix_fmt yuv420p public/videos/'+userID+'/'+videoID+'.mp4 -y';

childProcess.exec(generateVideo, function(err, stdout, stderr) {
    var json    = {};
    json.video  = '/videos/'+userID+'/'+videoID+'.mp4';
    res.send(json);
});
Run Code Online (Sandbox Code Playgroud)

phantom.js:

var page            = require('webpage').create();
page.viewportSize   = { width: 1366, height: 768 };
page.settings.resourceTimeout = 10000;

var args            = require('system').args;
var videoID         = args[1];
var userID          = args[2];

page.open('http://localhost:3000/recordvideo/'+videoID, 'post', function(status){
    var frame       = 0;
    var target_fps  = 30;
    var maxframes   = page.evaluate(function () {
                        return getTotalDurationInSeconds();
                    }) * target_fps;

    setInterval(function(){
        page.render('/dev/stdout', { format: "png" });
        if( frame >= maxframes ){
            phantom.exit();
        }
        frame++;
    }, (1000 / target_fps));
});
Run Code Online (Sandbox Code Playgroud)

而错误:

[Error: Command failed: /bin/sh -c phantomjs phantom.js XXXXXXXX XXXXXXXX | ffmpeg -vcodec png -f image2pipe -r 30 -i - -pix_fmt yuv420p public/videos/XXXXXXXX/XXXXXXXX.mp4 -y
www-0 ffmpeg version N-80901-gfebc862 Copyright (c) 2000-2016 the FFmpeg developers
www-0   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
www-0   configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
www-0   libavutil      55. 28.100 / 55. 28.100
www-0   libavcodec     57. 48.101 / 57. 48.101
www-0   libavformat    57. 41.100 / 57. 41.100
www-0   libavdevice    57.  0.102 / 57.  0.102
www-0   libavfilter     6. 47.100 /  6. 47.100
www-0   libavresample   3.  0.  0 /  3.  0.  0
www-0   libswscale      4.  1.100 /  4.  1.100
www-0   libswresample   2.  1.100 /  2.  1.100
www-0   libpostproc    54.  0.100 / 54.  0.100
www-0 [png @ 0x3d7c4a0] Invalid PNG signature 0x46726F6D20506861.
www-0 [image2pipe @ 0x3d72780] decoding for stream 0 failed
www-0 [image2pipe @ 0x3d72780] Could not find codec parameters for stream 0 (Video: png, none(pc)): unspecified size
www-0 Consider increasing the value for the 'analyzeduration' and 'probesize' options
www-0 Input #0, image2pipe, from 'pipe:':
www-0   Duration: N/A, bitrate: N/A
www-0     Stream #0:0: Video: png, none(pc), 30 tbr, 30 tbn, 30 tbc
www-0 [buffer @ 0x3d81540] Unable to parse option value "0x0" as image size
www-0 [buffer @ 0x3d81540] Unable to parse option value "-1" as pixel format
www-0 [buffer @ 0x3d81540] Unable to parse option value "0x0" as image size
www-0 [buffer @ 0x3d81540] Error setting option video_size to value 0x0.
www-0 [graph 0 input from stream 0:0 @ 0x3d72600] Error applying options to the filter.
www-0 Error opening filters!
www-0 ]
Run Code Online (Sandbox Code Playgroud)

我真的希望我能在这里找到答案!对不起,如果已经有答案的话.但我研究了几天.

先感谢您!