我有一个 Node.js 应用程序部署到带有
fluent-ffmpeg
、@ffmpeg-installer/ffmpeg
和 @ffprobe-installer/ffmprobe
的 docker 容器。
这是
fluent-ffmpeg
初始化脚本:
import ffmpeg = require('fluent-ffmpeg');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffprobePath = require('@ffprobe-installer/ffprobe').path;
ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg.setFfprobePath(ffprobePath);
export default ffmpeg;
这用于拍摄视频快照并将图像保存到文件中:
ffmpeg('ism manifest here')
.inputOption(`-ss timestamp`)
.outputOptions([
'-vframes 1',
'-vf crop=640:230:320:490,eq=saturation=0:contrast=1000,negate'
])
.output('test.png')
.run();
每当运行 ffmpeg 命令的任何配置时,它几乎立即失败:
Error: ffmpeg was killed with signal SIGSEGV
at ChildProcess.<anonymous> (/app/node_modules/fluent-ffmpeg/lib/processor.js:180:22)
at ChildProcess.emit (node:events:517:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:292:12)
我尝试在 docker-compose 文件中提高服务器的内存和 CPU 使用限制:
server:
container_name: server
build:
context: ./server
target: ${BUILD_TARGET}
env_file: ./.env
ports:
- 3000
depends_on:
- db
volumes:
- ./server/server.ts:/app/server.ts
- ./server/deploy.ts:/app/deploy.ts
- ./server/model:/app/model
tty: true
restart: on-failure
deploy:
resources:
limits:
cpus: '0.75'
memory: 2G
reservations:
cpus: '0.50'
memory: 1G
这是我的服务器 dockerfile:
FROM node:18 as base
RUN apt-get update && apt-get install git python3-dev libxml2-dev libxslt1-dev libz-dev python3-pip --yes
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
FROM base as development
CMD ["npm", "run", "dev"]
FROM base as production
CMD ["npm", "run", "server"]
但没有任何效果。在我的本地计算机上运行它效果很好。帮忙吗?
更新:
我只是尝试在自己的全新容器中运行一个小型的 dockerized ffmpeg 测试脚本。同样的问题。所以,这似乎与我的服务器配置没有任何关系。
在 Docker 中使用
@ffmpeg-installer/ffmpeg
提供的二进制文件似乎存在某种问题。
我走了我在其他地方找到的路线,那就是跑步
RUN apt-get install ffmpeg -y
在 dockerfile 中。这将安装
ffmpeg
并将其添加到 Linux PATH,从而允许 fluent-ffmpeg
自动选择它。或者,您也可以手动运行 ffmpeg.setFfmpegPath('/usr/bin/ffmpeg');
。
ffmpeg
现在就像魅力一样。