Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 vap CLI,便于命令行调用 #301

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Android/PlayerProj/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/*

!build/libs/
22 changes: 22 additions & 0 deletions Android/PlayerProj/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
vap-cli
---

# 使用教程
1. 获取 jar

- 方法一:[下载执行文件](https://github.com/Tencent/vap/raw/master/Android/PlayerProj/cli/build/libs/cli-1.0.jar)

- 方法2️二:使用 gradle 编译出 jar 产物
> 要提前编译 animtool
>
> jar 产物默认在 `Android/PlayerProj/cli/build/libs/cli-1.0.jar`

2. 执行 jar

示例:
```bash
java -jar cli-1.0.jar \
--ffmpeg /path/to/mac/ffmpeg \
--mp4edit /path/to/mac/mp4edit \
-i /path/to/test_demo/simple_demo
```
31 changes: 31 additions & 0 deletions Android/PlayerProj/cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id 'java'
}

group 'org.example'
version '1.0'

repositories {
mavenCentral()
}

dependencies {
implementation project(path: ':animtool')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'info.picocli:picocli:4.7.1'
}

test {
useJUnitPlatform()
}

jar {
manifest {
attributes "Main-Class": "com.tencent.vapcli.Main"
}

from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Binary file added Android/PlayerProj/cli/build/libs/cli-1.0.jar
Binary file not shown.
118 changes: 118 additions & 0 deletions Android/PlayerProj/cli/src/main/java/com/tencent/vapcli/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Tencent is pleased to support the open source community by making vap available.
*
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* 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.
*/
package com.tencent.vapcli;
utc8 marked this conversation as resolved.
Show resolved Hide resolved

import com.tencent.qgame.playerproj.animtool.AnimTool;
import com.tencent.qgame.playerproj.animtool.CommonArg;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import java.util.concurrent.Callable;


@Command(name = "vapcli", mixinStandardHelpOptions = true, version = "1.0",
description = "Vap CLI")
public class Main implements Callable<Integer> {

@Option(names = {"--ffmpeg"}, description = "ffmpeg命令路径,如 /path/to/ffmpeg", required = true)
private String ffmpegBin = "ffmpeg";

@Option(names = {"--mp4edit"}, description = "mp4edit命令路径,如 /path/to/mp4edit", required = true)
private String mp4editBin = "mp4edit";

@Option(names = {"--h265"}, description = "是否开启h265")
private boolean enableH265 = false;

@Option(names = {"--enableCrf"}, description = "是否开启可变码率")
private boolean enableCrf = false;

@Option(names = {"--fps"}, description = "fps")
private int fps = 24;

@Option(names = {"-i", "--input-dir"}, description = "素材文件夹路径", required = true)
private String inputDir;

@Option(names = {"--scale"}, description = "alpha 区域缩放大小 (0.5 - 1)")
private float scale = 0.5f;

@Option(names = {"--bitrate"}, description = "码率")
private int bitrate = 2000;

@Option(names = {"--crf"}, description = "0(无损) - 50(最大压缩)")
private int crf = 29;

@Override
public Integer call() throws Exception {
final CommonArg commonArg = new CommonArg();

commonArg.ffmpegCmd = this.ffmpegBin;
commonArg.mp4editCmd = this.mp4editBin;
commonArg.enableH265 = this.enableH265;
commonArg.fps = this.fps;
commonArg.inputPath = this.inputDir;
commonArg.scale = this.scale;
commonArg.bitrate = this.bitrate;
commonArg.crf = this.crf;

System.out.println("all args:");
for(String str: commonArg.toString().replaceFirst("CommonArg\\{", "").split(", ")) {
System.out.println("\t" + str);
}

AnimTool animTool = new AnimTool();

animTool.setToolListener(new AnimTool.IToolListener() {
@Override
public void onProgress(float progress) {
int p = (int)(progress * 100f);
System.out.println("onProgress: " + (Math.min(p, 99)) + "%");
}

@Override
public void onWarning(String msg) {
System.err.println("onWarning: " + msg);
}

@Override
public void onError() {
System.err.println("onError!!!!!!!!");
System.exit(1);
}

@Override
public void onComplete() {
System.out.println("onComplete: " + commonArg.outputPath);
System.exit(0);
}
});

try {
animTool.create(commonArg, true);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}

return 0;
}

public static void main(String[] args) {
System.out.println("Vap CLI START");

new CommandLine(new Main()).execute(args);
}
}
2 changes: 1 addition & 1 deletion Android/PlayerProj/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':animtool', ':animplayer'
include ':app', ':animtool', ':animplayer', ":cli"