Skip to content

Commit f91e157

Browse files
committed
🎨 更新MediaCodec使用文档
1 parent b197ace commit f91e157

2 files changed

Lines changed: 84 additions & 74 deletions

File tree

README-CN.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,29 @@
3737
## 主要功能
3838
[![](https://jitpack.io/v/AnJoiner/FFmpegCommand.svg)](https://jitpack.io/#AnJoiner/FFmpegCommand)[![License](https://img.shields.io/badge/license-Apache%202-informational.svg)](https://www.apache.org/licenses/LICENSE-2.0)[ ![FFmpeg](https://img.shields.io/badge/FFmpeg-6.0-orange.svg)](https://ffmpeg.org/releases/ffmpeg-6.0.tar.xz)[ ![X264](https://img.shields.io/badge/X264-20191217.2245-yellow.svg)](http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20191217-2245-stable.tar.bz2)[ ![mp3lame](https://img.shields.io/badge/mp3lame-3.100-critical.svg)](https://sourceforge.net/projects/lame/files/latest/download)[ ![fdk-aac](https://img.shields.io/badge/fdkaac-2.0.1-ff69b4.svg)](https://downloads.sourceforge.net/opencore-amr/fdk-aac-2.0.1.tar.gz)[ ![fdk-aac](https://img.shields.io/badge/opencoreamr-1.1.5-critical.svg)](https://sourceforge.net/projects/opencore-amr/files/opencore-amr/opencore-amr-0.1.5.tar.gz)
3939

40-
| 特色功能 | 支持 | 描述 |
41-
|------|--------------------|------------------------|
42-
| ffmpeg命令 | :white_check_mark: | 支持所有的ffmpeg命令 |
43-
| 进度回调 | :white_check_mark: | 支持所有命令的回调 |
44-
| 命令取消 | :white_check_mark: | 支持在命令执行过程中取消命令执行 |
45-
| debug模式 | :white_check_mark: | 支持开启/关闭调试模式 |
46-
| 获取媒体信息 | :white_check_mark: | 获取媒体信息(宽、高...) |
47-
| 支持GPU | :white_check_mark: | 支持MediaCodec(v1.2.3) |
48-
49-
* **支持视频格式转换 mp4->flv**
50-
* **支持音频编解码 mp3->pcm pcm->mp3 pcm->aac**
51-
* **支持音频转码 mp3->aac mp3->amr**
52-
* **支持视频编解码 mp4->yuv yuv->h264**
53-
* **支持视频转码 mp4->flv mp4->avi**
54-
* **支持音视频的剪切、拼接**
55-
* **支持视频转图片 mp4->png mp4->gif**
56-
* **支持音频声音大小控制以及混音(比如朗读的声音加上背景音乐)**
57-
* **支持部分滤镜 音频淡入、淡出效果、视频亮度和对比度以及添加水印**
58-
* **支持生成静音音频**
59-
* **支持获取媒体文件信息**
60-
* **支持连续执行FFmpeg命令**
40+
| 特色功能 | 支持 | 描述 |
41+
|---------------|--------------------|-------------------------|
42+
| ffmpeg命令 | :white_check_mark: | 支持所有的ffmpeg命令 |
43+
| 进度回调 | :white_check_mark: | 支持所有命令的回调 |
44+
| 命令取消 | :white_check_mark: | 支持在命令执行过程中取消命令执行 |
45+
| debug模式 | :white_check_mark: | 支持开启/关闭调试模式 |
46+
| 获取媒体信息 | :white_check_mark: | 获取媒体信息(宽、高...) |
47+
| MediaCodec编解码 | :white_check_mark: | 支持MediaCodec(从 v1.3.0) |
48+
| 平台架构 |:white_check_mark:| 支持 armeabi-v7a, arm64-v8a |
49+
| 独立so |:white_check_mark:| 将多个so合并成一个 `ffmpeg-or.so` |
50+
51+
大致的功能如下:
52+
* 支持视频格式转换 mp4->flv
53+
* 支持音频编解码 mp3->pcm pcm->mp3 pcm->aac
54+
* 支持音频转码 mp3->aac mp3->amr
55+
* 支持视频编解码 mp4->yuv yuv->h264
56+
* 支持视频转码 mp4->flv mp4->avi
57+
* 支持音视频的剪切、拼接
58+
* 支持视频转图片 mp4->png mp4->gif
59+
* 支持音频声音大小控制以及混音(比如朗读的声音加上背景音乐)
60+
* 支持部分滤镜 音频淡入、淡出效果、视频亮度和对比度以及添加水印
61+
* 支持生成静音音频
62+
* 支持获取媒体文件信息
6163

6264
| 执行FFmpeg | 获取媒体信息 |
6365
|----------------------------------------------------------|---------------------------------------------------------|
@@ -160,28 +162,32 @@ var progress = pts/duration!!
160162
### 自定义FFmpeg命令
161163

162164
这里只是演示了音频剪切,很多如上述功能请自行查阅[FFmpegUtils](ffmpeg/src/main/java/com/coder/ffmpeg/utils/FFmpegUtils.java)
163-
如果其中不满足需求,可添加自己的FFmpeg命令.例如
165+
如果其中不满足需求,可添加自己的FFmpeg命令.以下是一个自定义使用`MediaCodec`进行转格式的例子
164166

165167
```kotlin
168+
// shell 命令: ffmpeg -y -c:v h264_mediacodec -i inputPath -c:v h264_mediacodec outputPath
166169
val command = CommandParams()
170+
.append("-c:v")
171+
.append("h264_mediacodec")
167172
.append("-i")
168-
.append(srcFile)
169-
.append("-vn")
170-
.append("-c:a")
171-
.append("copy")
172-
.append("-ss")
173-
.append(startTime)
174-
.append("-t")
175-
.append(duration)
176-
.append(targetPath)
173+
.append(inputPath)
174+
.append("-b") // 硬编码一般需要设置视频的比特率(bitrate)
175+
.append("1500k")
176+
.append("-c:v")
177+
.append("h264_mediacodec")
178+
.append(outputPath)
177179
.get()
178180

179-
GlobalScope.launch {
180-
FFmpegCommand.runCmd(command, callback("音频剪切完成", targetPath))
181+
MainScope().launch(Dispatchers.IO) {
182+
FFmpegCommand.runCmd(command, callback("格式转换成功", targetPath))
181183
}
182-
183184
```
184-
最好使用`CommandParams`构建我们的命令参数,这样能保证参数不被路径中空格影响,导致命令执行不成功。也可以使用如下方式构造我们的参数
185+
需要注意:
186+
* 在使用`MediaCodec`进行编码的时候,必须同时配置`MediaCodec`解码,如上例子所示,不然会造成失败!!!
187+
* H264编解码器是`h264_mediacodec`,H265的编解码器是`hevc_mediacodec`。同时可以使用H264解码和H265编码。
188+
* 硬编码一般需要设置视频的比特率,否则会出现画面模糊不清晰的情况。
189+
* 最好使用`CommandParams`构建我们的命令参数,这样能保证参数不被路径中空格影响,导致命令执行不成功。也可以使用如下方式构造我们的参数。
190+
185191
```kotlin
186192
val command = arrayOf("ffmpeg","-y","-i",inputPath,outputPath)
187193
```
@@ -228,8 +234,6 @@ FFmpegCommand.cancel()
228234

229235
**[【常见问题】](ffmpeg-wiki/常见问题.md)**
230236

231-
**[【版本更新】](UPDATE.md)**
232-
233237
## 参考
234238

235239
**[【KFFmpegCommandActivity-命令使用参考】](app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegCommandActivity.kt)**

README.md

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In our development, audio and video related content is often used, generally we
2222
If you can’t access all the information, please go to[【国内镜像】](https://gitee.com/anjoiner/FFmpegCommand)
2323

2424
## Cross Compile
25-
* Macos 13.2 + GCC + Cmake + NDK 21
25+
* Macos 13.2 + GCC + Cmake + NDK 21 (支持MediaCodec 编解码)
2626

2727
| 第三方库 | 版本 | 下载地址 |
2828
|------------|--------------------|------------------------------------------------------------------------------------------------------|
@@ -36,28 +36,29 @@ If you can’t access all the information, please go to[【国内镜像】](http
3636
## The main function
3737
[![](https://jitpack.io/v/AnJoiner/FFmpegCommand.svg)](https://jitpack.io/#AnJoiner/FFmpegCommand)[![License](https://img.shields.io/badge/license-Apache%202-informational.svg)](https://www.apache.org/licenses/LICENSE-2.0)[ ![FFmpeg](https://img.shields.io/badge/FFmpeg-6.0-orange.svg)](https://ffmpeg.org/releases/ffmpeg-6.0.tar.xz)[ ![X264](https://img.shields.io/badge/X264-20191217.2245-yellow.svg)](http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20191217-2245-stable.tar.bz2)[ ![mp3lame](https://img.shields.io/badge/mp3lame-3.100-critical.svg)](https://sourceforge.net/projects/lame/files/latest/download)[ ![fdk-aac](https://img.shields.io/badge/fdkaac-2.0.1-ff69b4.svg)](https://downloads.sourceforge.net/opencore-amr/fdk-aac-2.0.1.tar.gz)[ ![fdk-aac](https://img.shields.io/badge/opencoreamr-1.1.5-critical.svg)](https://sourceforge.net/projects/opencore-amr/files/opencore-amr/opencore-amr-0.1.5.tar.gz)
3838

39-
| 特色功能 | 支持 | 描述 |
40-
|---------------------------|--------------------|-------------------------------------------|
41-
| ffmpeg commands | :white_check_mark: | Support all FFmpeg commands |
42-
| progress callback | :white_check_mark: | Support callback of ffmpeg commands |
43-
| cancel commands | :white_check_mark: | Support cancel the commands that is doing |
44-
| debug model | :white_check_mark: | Support debug model for develop |
45-
| get media info | :white_check_mark: | Support to get media info |
46-
| gpu hardware acceleration | :white_check_mark: | Support MediaCodec of android gpu(v1.2.3) |
47-
48-
* **Support all FFmpeg commands**
49-
* **Support video format conversion : mp4->flv**
50-
* **Support audio codec : mp3->pcm pcm->mp3 pcm->aac**
51-
* **Support audio transcoding : mp3->aac mp3->amr**
52-
* **Support video codec : mp4->yuv yuv->h264**
53-
* **Support video transcoding : mp4->flv mp4->avi**
54-
* **Support cutting and splicing of audio and video**
55-
* **Support video to picture : mp4->png mp4->gif**
56-
* **Support audio sound size control and mixing (such as reading sound plus background music)**
57-
* **Support some filters, audio fade in, fade out effects, video brightness and contrast, and add watermark**
58-
* **Support for generating silent audio**
59-
* **Support for obtaining media file information**
60-
* **Support continuous execution of FFmpeg commands**
39+
| Special feature | Support | Description |
40+
|----------------------|--------------------|--------------------------------------------------|
41+
| ffmpeg commands | :white_check_mark: | Support all FFmpeg commands |
42+
| progress callback | :white_check_mark: | Support callback of ffmpeg commands |
43+
| cancel commands | :white_check_mark: | Support cancel the commands that is doing |
44+
| debug model | :white_check_mark: | Support debug model for develop |
45+
| get media info | :white_check_mark: | Support to get media info |
46+
| mediacodec codec | :white_check_mark: | Support MediaCodec of android gpu( since v1.3.0) |
47+
| android architecture |:white_check_mark:| Support armeabi-v7a, arm64-v8a |
48+
| one so |:white_check_mark:| Merge multiple so into one `ffmpeg-or.so` |
49+
50+
The general functions are as follows:
51+
* Support all FFmpeg commands
52+
* Support video format conversion : mp4->flv
53+
* Support audio codec : mp3->pcm pcm->mp3 pcm->aac
54+
* Support audio transcoding : mp3->aac mp3->amr
55+
* Support video codec : mp4->yuv yuv->h264
56+
* Support video transcoding : mp4->flv mp4->avi
57+
* Support cutting and splicing of audio and video
58+
* Support video to picture : mp4->png mp4->gif
59+
* Support audio sound size control and mixing (such as reading sound plus background music)
60+
* Support some filters, audio fade in, fade out effects, video brightness and contrast, and add watermark
61+
* Support for generating silent audio
6162

6263
|Run FFmpeg|Get media information|
6364
|---------| ----------------------------------|
@@ -158,26 +159,33 @@ var progress = pts/duration!!
158159
### Custom FFmpeg command
159160

160161
This is just a demonstration of audio cutting, many functions such as the above, please refer to it yourself [FFmpegUtils](ffmpeg/src/main/java/com/coder/ffmpeg/utils/FFmpegUtils.java)
161-
If the requirements are not met, you can add your own FFmpeg command, E.g:
162+
If the requirements are not met, you can add your own FFmpeg command, The following is an example of customizing conversion using `MediaCodec`:
162163

163164
```kotlin
165+
// shell command: ffmpeg -y -c:v h264_mediacodec -i inputPath -c:v h264_mediacodec outputPath
164166
val command = CommandParams()
167+
.append("-c:v")
168+
.append("h264_mediacodec")
165169
.append("-i")
166-
.append(srcFile)
167-
.append("-vn")
168-
.append("-c:a")
169-
.append("copy")
170-
.append("-ss")
171-
.append(startTime)
172-
.append("-t")
173-
.append(duration)
174-
.append(targetPath)
170+
.append(inputPath)
171+
.append("-c:v")
172+
.append("h264_mediacodec")
173+
.append(outputPath)
175174
.get()
176175

177-
GlobalScope.launch {
178-
FFmpegCommand.runCmd(command, callback("Audio cut is complete", targetPath))
176+
MainScope().launch(Dispatchers.IO) {
177+
FFmpegCommand.runCmd(command, callback("Format conversion successful", targetPath))
179178
}
180179
```
180+
requires attention:
181+
* When using `MediaCodec` for encoding, `MediaCodec` decoding must be configured at the same time, as shown in the above example, otherwise it will cause failure! ! !
182+
* The H264 codec is `h264_mediacodec`, and the H265 codec is `hevc_mediacodec`. H264 decoding and H265 encoding can be used at the same time.
183+
* Hard coding generally requires setting the bitrate of the video, otherwise the picture will be blurry and unclear.
184+
* It is best to use `CommandParams` to construct our command parameters. This can ensure that the parameters are not affected by spaces in the path, causing the command execution to fail. We can also construct our parameters as follows
185+
186+
```kotlin
187+
val command = arrayOf("ffmpeg","-y","-i",inputPath,outputPath)
188+
```
181189

182190
### Multi-process execution
183191
Since the bottom layer is temporarily unable to implement multithreading (after all, C is a process-oriented language), if you need to push the stream at the same time, it is impossible to execute other commands at the same time.
@@ -221,8 +229,6 @@ FFmpegCommand.cancel()
221229

222230
**[【common problem】](ffmpeg-wiki/常见问题.md)**
223231

224-
**[【new version update】](UPDATE.md)**
225-
226232
## Reference
227233

228234
**[【KFFmpegCommandActivity-Command reference】](app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegCommandActivity.kt)**

0 commit comments

Comments
 (0)