我用node-js和fluent-ffmpeg编写了一个node-js api:
'use strict';
require('babel-register');
const path = require('path');
const ffmpeg = require('fluent-ffmpeg');
[...]
var infs = new ffmpeg
infs.addInput(doc.data().url).outputOptions([
'-preset slow', '-g 48', '-sc_threshold 0',
'-map 0:0', '-map 0:1', '-map 0:0', '-map 0:1',
'-s:v:0 1280x720', '-c:v:0 libx264', '-b:v:0 2000k',
// "-var_stream_map", "'v:0,a:0 v:1,a:1'",
'-master_pl_name ./' + req.params.id + '/master' + req.params.id + '.m3u8',
'-f hls', '-hls_time 6', '-hls_list_size 0',
'-hls_segment_filename ./' + req.params.id + '/fileSequence|' + req.params.id + '|%d|v%v.ts',
'-max_muxing_queue_size 1024',
]).output('./' + req.params.id + '/video' + req.params.id + '.m3u8')
.on('start', function (commandLine) {
console.log('Spawned Ffmpeg with command: ' + commandLine);
})
.on('error', function (err, stdout, stderr) {
console.log('An error occurred: ' + err.message, err, stderr);
})
.on('progress', function (progress) {
console.log('Processing: ' + progress.percent + '% done')
})
.on('end', function (err, stdout, stderr) {
console.log('Finished processing!' /*, err, stdout, stderr*/)
})
.run()
res.status(200).send('GG').end();
}
});
[...]
可以和
一起使用节点app.js
在我的Macbook Pro上,但是在我这样做时
gcloud应用部署
我叫公共网址,我有这个日志:
Processing: undefined% done
An error occurred: ffmpeg was killed with signal SIGABRT Error: ffmpeg was killed with signal SIGABRT
这是我的app.yaml:
# Copyright 2017, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START gae_flex_quickstart_yaml]
runtime: nodejs
env: flex
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 6
disk_size_gb: 30
# [END gae_flex_quickstart_yaml]
如何在Google App Engine上正确部署我的node-js api?
先谢谢了。
杰里米。
答案 0 :(得分:-1)
我们没有关于doc.data().url
的确切信息,但这是您从数据库文档中获得的信息。因此,我猜测addInput
documentation必须是一些本地文件名。本地文件名也是output
方法的参数。
这将在您的本地环境中起作用,但是当您在App Engine中处理文件时,您必须使用一些here中所述的存储服务。
答案 1 :(得分:-1)
为了能够使用此模块,请确保您具有ffmpeg 安装在系统上(包括所有必需的编码库) 像libmp3lame或libx264)。
根据app.yaml
,检查默认节点容器(您正在使用的容器),不确定the right dependencies是否已预安装。
您可以通过转到已部署的实例进行检查,启用调试并通过SSH进入该实例。您可以按照the docs中详细介绍的过程进行操作。
如果未预先安装所有必需的依赖项,则必须build a custom container才能使用GAE flex。
由于节点库fluent-ffmpeg
仅在运行本地命令(you can check in the code of the library),因此可能是您的本地计算机已安装了所有内容,但是在生成的映像中缺少组件。
您正在使用node app.js
(即不是在构建容器中,而是在本地节点中)进行测试的事实,使这种想法更加可信。