Skip to content

Commit 62b5989

Browse files
committed
🎨 新增获取媒体的编码信息
1 parent 793f8f5 commit 62b5989

File tree

8 files changed

+70
-0
lines changed

8 files changed

+70
-0
lines changed

app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegInfoActivity.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.widget.TextView
88
import androidx.appcompat.app.AppCompatActivity
99
import androidx.recyclerview.widget.GridLayoutManager
1010
import androidx.recyclerview.widget.RecyclerView
11+
import com.coder.ffmpeg.annotation.CodecProperty
1112
import com.coder.ffmpeg.annotation.MediaAttribute
1213
import com.coder.ffmpeg.jni.FFmpegCommand
1314
import com.coder.ffmpegtest.R
@@ -76,6 +77,8 @@ class KFFmpegInfoActivity : AppCompatActivity() {
7677
5 -> getChannels()
7778
6 -> getSampleRate()
7879
7 -> getAudioBitRate()
80+
8 -> getVideoCodec()
81+
9 -> getAudioCodec()
7982
}
8083
}
8184
})
@@ -138,6 +141,18 @@ class KFFmpegInfoActivity : AppCompatActivity() {
138141
tvContent?.text = result
139142
}
140143

144+
private fun getVideoCodec() {
145+
val codecInfo = FFmpegCommand.getCodecInfo(mVideoPath, CodecProperty.VIDEO)
146+
val result =codecInfo?.toString()?:""
147+
tvContent?.text = result
148+
}
149+
150+
private fun getAudioCodec() {
151+
val codecInfo = FFmpegCommand.getCodecInfo(mVideoPath, CodecProperty.AUDIO)
152+
val result =codecInfo?.toString()?:""
153+
tvContent?.text = result
154+
}
155+
141156
companion object{
142157
fun start(context: Context){
143158
val intent = Intent(context,KFFmpegInfoActivity::class.java)

app/src/main/res/values/arrays.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<item>音频声道数</item>
1010
<item>音频采样率</item>
1111
<item>音频比特率</item>
12+
<item>视频Codec</item>
13+
<item>音频Codec</item>
1214
</string-array>
1315

1416
<string-array name="formats">
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.coder.ffmpeg.annotation
2+
3+
import androidx.annotation.IntDef
4+
5+
/**
6+
* @author: AnJoiner
7+
* @datetime: 2023-11-05
8+
* 解码器类型
9+
*/
10+
@IntDef(CodecProperty.VIDEO,
11+
CodecProperty.AUDIO)
12+
annotation class CodecProperty {
13+
companion object {
14+
const val VIDEO = 1 // 视频解码格式
15+
const val AUDIO = 2 // 音频解码格式
16+
}
17+
}

ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCmd.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package com.coder.ffmpeg.jni
22

33
import android.util.Log
44
import com.coder.ffmpeg.annotation.CodecAttribute
5+
import com.coder.ffmpeg.annotation.CodecProperty
56
import com.coder.ffmpeg.annotation.FormatAttribute
67
import com.coder.ffmpeg.annotation.MediaAttribute
78
import com.coder.ffmpeg.call.IFFmpegCallBack
9+
import com.coder.ffmpeg.model.CodecInfo
810
import java.util.*
911

1012
/**
@@ -129,6 +131,19 @@ internal class FFmpegCmd private constructor() {
129131
* @param type information type.
130132
*/
131133
private external fun info(videoPath: String?, type: Int): Int
134+
/**
135+
* Provide method to get codec info .
136+
* @param property property type.
137+
*/
138+
fun getCodecProperty(videoPath: String?,@CodecProperty property: Int): CodecInfo? {
139+
return codec(videoPath, property)
140+
}
141+
/**
142+
* Call native to get media information.
143+
* @param videoPath media path
144+
* @param type information type.
145+
*/
146+
private external fun codec(videoPath: String?, type: Int): CodecInfo?
132147

133148
/**
134149
* Provide method to get format info .

ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCommand.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.coder.ffmpeg.jni
22

33
import com.coder.ffmpeg.annotation.CodecAttribute
4+
import com.coder.ffmpeg.annotation.CodecProperty
45
import com.coder.ffmpeg.annotation.FormatAttribute
56
import com.coder.ffmpeg.annotation.MediaAttribute
67
import com.coder.ffmpeg.call.IFFmpegCallBack
8+
import com.coder.ffmpeg.model.CodecInfo
79

810
/**
911
* @author: AnJoiner
@@ -32,6 +34,18 @@ object FFmpegCommand {
3234
return FFmpegCmd.instance?.getMediaInfo(path, type)
3335
}
3436

37+
/**
38+
* Get media codec info
39+
*
40+
* @param path media path
41+
* @param type media property type [CodecProperty]
42+
* @return media codec info [CodecInfo]
43+
*/
44+
@JvmStatic
45+
fun getCodecInfo(path: String?, @CodecProperty type: Int): CodecInfo? {
46+
return FFmpegCmd.instance?.getCodecProperty(path, type)
47+
}
48+
3549
/**
3650
* Get support for unpacking format
3751
*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coder.ffmpeg.model
2+
3+
data class CodecInfo(val id:Int, val name:String, val type:Int){
4+
override fun toString(): String {
5+
return "id = $id, name = $name, type = $type"
6+
}
7+
}
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)