-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ganxia.cx
committed
Jan 4, 2023
1 parent
258a8b8
commit 15bb685
Showing
12 changed files
with
718 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tmp | ||
.s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
async function preInit(inputObj) { | ||
console.log(`\n _______ _______ __ __ _______ _______ _______ | ||
| || || |_| || || || | | ||
| ___|| ___|| || _ || ___|| ___| | ||
| |___ | |___ | || |_| || |___ | | __ | ||
| ___|| ___|| || ___|| ___|| || | | ||
| | | | | ||_|| || | | |___ | |_| | | ||
|___| |___| |_| |_||___| |_______||_______| | ||
`) | ||
} | ||
|
||
async function postInit(inputObj) { | ||
console.log(`\n Welcome to the ffmpeg-app application | ||
This application requires to open these services: | ||
FC : https://fc.console.aliyun.com/ | ||
OSS: https://oss.console.aliyun.com/ | ||
ACR: https://cr.console.aliyun.com/ | ||
* 关于项目的介绍,可以参考:https://github.com/devsapp/start-ffmpeg/blob/master/headless-ffmpeg/src | ||
* 项目初始化完成,您可以直接进入项目目录下 | ||
1. 对s.yaml进行升级,例如填充好environmentVariables中的部分变量值(OSS存储桶相关信息) | ||
2. 开通容器镜像服务,并创建相关的实例、命名空间,并将内容对应填写到image字段中 | ||
3. 进行构建:s build --use-docker --dockerfile ./code/Dockerfile | ||
4. 项目部署:s deploy --use-local -y | ||
* 最后您还可以验证项目的正确性,例如通过invoke调用(这里video_url等,可以考虑换成自己的测试mp4): | ||
s invoke -e '{"record_time":"35","video_url":"https://dy-vedio.oss-cn-hangzhou.aliyuncs.com/video/a.mp4","output_file":"record/test.mp4"}' | ||
\n`) | ||
} | ||
|
||
module.exports = { | ||
postInit, | ||
preInit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
Type: Application | ||
Name: Ffmpeg-online | ||
Provider: | ||
- 阿里云 | ||
Version: 0.0.5 | ||
Description: 快速部署一个ffmpeg-online应用到阿里云函数计算 | ||
HomePage: https://github.com/devsapp/start-ffmpeg/tree/master/headless-ffmpeg | ||
Tags: | ||
- 视频在线处理 | ||
Category: 音视频处理 | ||
Service: | ||
函数计算: | ||
Authorities: | ||
- AliyunFCFullAccess | ||
- AliyunContainerRegistryFullAccess | ||
Parameters: | ||
type: object | ||
additionalProperties: false # 不允许增加其他属性 | ||
required: # 必填项 | ||
- region | ||
- serviceName | ||
- functionName | ||
- roleArn | ||
- acrRegistry | ||
- ossBucket | ||
- timeZone | ||
properties: | ||
region: | ||
title: 地域 | ||
type: string | ||
default: cn-hangzhou | ||
description: 创建应用所在的地区 | ||
enum: | ||
- cn-beijing | ||
- cn-hangzhou | ||
- cn-shanghai | ||
- cn-qingdao | ||
- cn-zhangjiakou | ||
- cn-huhehaote | ||
- cn-shenzhen | ||
- cn-chengdu | ||
- cn-hongkong | ||
- ap-southeast-1 | ||
- ap-southeast-2 | ||
- ap-southeast-3 | ||
- ap-southeast-5 | ||
- ap-northeast-1 | ||
- eu-central-1 | ||
- eu-west-1 | ||
- us-west-1 | ||
- us-east-1 | ||
- ap-south-1 | ||
serviceName: | ||
title: 服务名 | ||
type: string | ||
default: ffmpeg_online-${default-suffix} | ||
pattern: '^[a-zA-Z_][a-zA-Z0-9-_]{0,127}$' | ||
description: 服务名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-128 之间 | ||
functionName: | ||
title: 函数名 | ||
type: string | ||
default: ffmpeg_online | ||
description: 函数名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-64 之间 | ||
roleArn: | ||
title: RAM角色ARN | ||
type: string | ||
default: '' | ||
pattern: '^acs:ram::[0-9]*:role/.*$' | ||
description: 应用所属的函数计算服务配置的 role | ||
required: true | ||
x-role: | ||
name: fcacrrole | ||
service: fc | ||
authorities: | ||
- AliyunContainerRegistryFullAccess | ||
- AliyunFCDefaultRolePolicy | ||
acrRegistry: | ||
title: 阿里云容器镜像 | ||
type: string | ||
examples: [ 'registry.cn-hangzhou.aliyuncs.com/fc-demo/headless-ffmpeg:v1' ] | ||
description: 阿里云容器镜像服务 image 的名字 | ||
x-acr: | ||
type: 'select' | ||
ossBucket: | ||
title: OSS 存储桶名 | ||
type: string | ||
default: '' | ||
description: OSS 存储桶名 | ||
x-bucket: | ||
dependency: | ||
- region | ||
timeZone: | ||
title: 时区 | ||
type: string | ||
default: Asia/Shanghai | ||
description: 创建的应用函数执行时候所在实例的时区, 详情参考 https://docs.oracle.com/middleware/12211/wcs/tag-ref/MISC/TimeZones.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Ffmpeg online 帮助文档 | ||
|
||
<p align="center" class="flex justify-center"> | ||
<a href="https://www.serverless-devs.com" class="ml-1"> | ||
<img src="http://editor.devsapp.cn/icon?package=headless-ffmpeg&type=packageType"> | ||
</a> | ||
<a href="http://www.devsapp.cn/details.html?name=headless-ffmpeg" class="ml-1"> | ||
<img src="http://editor.devsapp.cn/icon?package=headless-ffmpeg&type=packageVersion"> | ||
</a> | ||
<a href="http://www.devsapp.cn/details.html?name=headless-ffmpeg" class="ml-1"> | ||
<img src="http://editor.devsapp.cn/icon?package=headless-ffmpeg&type=packageDownload"> | ||
</a> | ||
</p> | ||
|
||
<description> | ||
|
||
> ***快速部署一个在线ffmpeg应用到阿里云函数计算*** | ||
</description> | ||
|
||
<table> | ||
|
||
</table> | ||
|
||
<codepre id="codepre"> | ||
|
||
</codepre> | ||
|
||
<deploy> | ||
|
||
## 部署 & 体验 | ||
|
||
<appcenter> | ||
|
||
- :fire: 通过 [Serverless 应用中心](https://fcnext.console.aliyun.com/applications/create?template=PanoramicPageRecording) , | ||
[![Deploy with Severless Devs](https://img.alicdn.com/imgextra/i1/O1CN01w5RFbX1v45s8TIXPz_!!6000000006118-55-tps-95-28.svg)](https://fcnext.console.aliyun.com/applications/create?template=PanoramicPageRecording) | ||
该应用。 | ||
|
||
</appcenter> | ||
|
||
- 通过 [Serverless Devs Cli](https://www.serverless-devs.com/serverless-devs/install) 进行部署: | ||
- [安装 Serverless Devs Cli 开发者工具](https://www.serverless-devs.com/serverless-devs/install) | ||
,并进行[授权信息配置](https://www.serverless-devs.com/fc/config) ; | ||
- 初始化项目:`s init PanoramicPageRecording -d PanoramicPageRecording` | ||
- 进入项目,并进行项目部署:`cd PanoramicPageRecording && s deploy -y` | ||
|
||
</deploy> | ||
|
||
<appdetail id="flushContent"> | ||
|
||
# 调用函数 | ||
|
||
``` bash | ||
# deploy | ||
$ s deploy -y --use-local | ||
# Invoke | ||
$ s invoke -e '{"input_file":"record/test.mp4","video_format":"mp4","start_time":"10","duration":"16","output_file":"record/result.mp4","commands":["-r 30","-f avi"]}' | ||
``` | ||
|
||
调用成功后, 会在对应的 bucket 下, 产生 record/result.mp4 大约 16 秒的每秒 30 帧的处理后的视频。 | ||
|
||
# 入参示例 | ||
|
||
```JSON | ||
{ | ||
"input_file": "path/to/your/video.mp4", | ||
"output_file": "path/to/save/processed.mp4", | ||
"video_format": "mp4", | ||
"start_time": "10", | ||
"duration": "16", | ||
|
||
"commands": [ | ||
"-r 25", | ||
"-f mp4" | ||
] | ||
} | ||
|
||
``` | ||
|
||
## 参数说明 | ||
参数分为两部分,一部分是应用支持到参数,具体包括: | ||
- video_format | ||
- codec | ||
- video_bit_rate | ||
- audio_bit_rate | ||
- video_frame_rate | ||
- duration | ||
- video_aspect_ratio | ||
- start_time | ||
- video_size | ||
- audio_codec | ||
- audio_frequency | ||
- audio_quality | ||
如果上述参数不能满足您的视频处理需求,可自行在commands中传入 | ||
处理字符传,范式为'-option param',示例如同'-r 30' | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
```bash | ||
# 如果有镜像有代码更新, 重新build 镜像 | ||
$ docker build -t ffmpeg-online -f ./code/Dockerfile ./code | ||
``` | ||
|
||
# 原理 | ||
|
||
将欲处理的视频下载到custom container载通过底层调用ffmpeg进行处理,最后上传到OSS | ||
|
||
[PushObjectCache](https://next.api.aliyun.com/api/Cdn/2018-05-10/PushObjectCache?lang=NODEJS&sdkStyle=old¶ms={}) | ||
|
||
|
||
|
||
</appdetail> | ||
|
||
<devgroup> | ||
|
||
## 开发者社区 | ||
|
||
您如果有关于错误的反馈或者未来的期待,您可以在 [Serverless Devs repo Issues](https://github.com/serverless-devs/serverless-devs/issues) | ||
中进行反馈和交流。如果您想要加入我们的讨论组或者了解 FC 组件的最新动态,您可以通过以下渠道进行: | ||
|
||
<p align="center"> | ||
|
||
| <img src="https://serverless-article-picture.oss-cn-hangzhou.aliyuncs.com/1635407298906_20211028074819117230.png" width="130px" > | <img src="https://serverless-article-picture.oss-cn-hangzhou.aliyuncs.com/1635407044136_20211028074404326599.png" width="130px" > | <img src="https://serverless-article-picture.oss-cn-hangzhou.aliyuncs.com/1635407252200_20211028074732517533.png" width="130px" > | | ||
|--- | --- | --- | | ||
| <center>微信公众号:\`serverless\`</center> | <center>微信小助手:\`xiaojiangwh\`</center> | <center>钉钉交流群:\`33947367\`</center> | | ||
|
||
</p> | ||
|
||
</devgroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/headless-ffmpeg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# https://hub.docker.com/r/aliyunfc/headless-ffmpeg | ||
FROM aliyunfc/headless-ffmpeg | ||
|
||
# set time zone (current is Shanghai, China) | ||
ENV TZ=Asia/Shanghai | ||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | ||
RUN dpkg-reconfigure -f noninteractive tzdata | ||
|
||
ENV LANG zh_CN.UTF-8 | ||
ENV LANGUAGE zh_CN:zh | ||
ENV LC_ALL zh_CN.UTF-8 | ||
# set Xvfb auth file | ||
ENV XAUTHORITY=/tmp/Xauthority | ||
|
||
WORKDIR /code | ||
|
||
ENV PUPPETEER_SKIP_DOWNLOAD=true | ||
RUN npm install express \ | ||
ali-oss \ | ||
fluent-ffmpeg \ | ||
--registry http://registry.npm.taobao.org | ||
|
||
COPY ./control.js ./control.js | ||
|
||
RUN mkdir -p /var/output | ||
|
||
EXPOSE 9000 | ||
|
||
ENTRYPOINT ["node", "control.js"] |
Oops, something went wrong.