diff --git a/Android/PlayerProj/cli/.gitignore b/Android/PlayerProj/cli/.gitignore new file mode 100644 index 00000000..4f48c811 --- /dev/null +++ b/Android/PlayerProj/cli/.gitignore @@ -0,0 +1,3 @@ +build/* + +!build/libs/ diff --git a/Android/PlayerProj/cli/README.md b/Android/PlayerProj/cli/README.md new file mode 100644 index 00000000..d4e08b30 --- /dev/null +++ b/Android/PlayerProj/cli/README.md @@ -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 +``` diff --git a/Android/PlayerProj/cli/build.gradle b/Android/PlayerProj/cli/build.gradle new file mode 100644 index 00000000..9ed5bd57 --- /dev/null +++ b/Android/PlayerProj/cli/build.gradle @@ -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) } + } +} \ No newline at end of file diff --git a/Android/PlayerProj/cli/build/libs/cli-1.0.jar b/Android/PlayerProj/cli/build/libs/cli-1.0.jar new file mode 100644 index 00000000..87b0c141 Binary files /dev/null and b/Android/PlayerProj/cli/build/libs/cli-1.0.jar differ diff --git a/Android/PlayerProj/cli/src/main/java/com/tencent/vapcli/Main.java b/Android/PlayerProj/cli/src/main/java/com/tencent/vapcli/Main.java new file mode 100644 index 00000000..6c49780a --- /dev/null +++ b/Android/PlayerProj/cli/src/main/java/com/tencent/vapcli/Main.java @@ -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; + +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 { + + @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); + } +} diff --git a/Android/PlayerProj/settings.gradle b/Android/PlayerProj/settings.gradle index 409b3750..d6c98a4a 100644 --- a/Android/PlayerProj/settings.gradle +++ b/Android/PlayerProj/settings.gradle @@ -1 +1 @@ -include ':app', ':animtool', ':animplayer' +include ':app', ':animtool', ':animplayer', ":cli"