diff --git a/app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegInfoActivity.kt b/app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegInfoActivity.kt
index eac47cd..d6d5fc2 100644
--- a/app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegInfoActivity.kt
+++ b/app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegInfoActivity.kt
@@ -8,6 +8,7 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
+import com.coder.ffmpeg.annotation.CodecProperty
import com.coder.ffmpeg.annotation.MediaAttribute
import com.coder.ffmpeg.jni.FFmpegCommand
import com.coder.ffmpegtest.R
@@ -76,6 +77,8 @@ class KFFmpegInfoActivity : AppCompatActivity() {
5 -> getChannels()
6 -> getSampleRate()
7 -> getAudioBitRate()
+ 8 -> getVideoCodec()
+ 9 -> getAudioCodec()
}
}
})
@@ -138,6 +141,18 @@ class KFFmpegInfoActivity : AppCompatActivity() {
tvContent?.text = result
}
+ private fun getVideoCodec() {
+ val codecInfo = FFmpegCommand.getCodecInfo(mVideoPath, CodecProperty.VIDEO)
+ val result =codecInfo?.toString()?:""
+ tvContent?.text = result
+ }
+
+ private fun getAudioCodec() {
+ val codecInfo = FFmpegCommand.getCodecInfo(mVideoPath, CodecProperty.AUDIO)
+ val result =codecInfo?.toString()?:""
+ tvContent?.text = result
+ }
+
companion object{
fun start(context: Context){
val intent = Intent(context,KFFmpegInfoActivity::class.java)
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 8d41ce0..7db1fb4 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -9,6 +9,8 @@
- 音频声道数
- 音频采样率
- 音频比特率
+ - 视频Codec
+ - 音频Codec
diff --git a/ffmpeg/src/main/java/com/coder/ffmpeg/annotation/CodecProperty.kt b/ffmpeg/src/main/java/com/coder/ffmpeg/annotation/CodecProperty.kt
new file mode 100644
index 0000000..bac6e1d
--- /dev/null
+++ b/ffmpeg/src/main/java/com/coder/ffmpeg/annotation/CodecProperty.kt
@@ -0,0 +1,17 @@
+package com.coder.ffmpeg.annotation
+
+import androidx.annotation.IntDef
+
+/**
+ * @author: AnJoiner
+ * @datetime: 2023-11-05
+ * 解码器类型
+ */
+@IntDef(CodecProperty.VIDEO,
+ CodecProperty.AUDIO)
+annotation class CodecProperty {
+ companion object {
+ const val VIDEO = 1 // 视频解码格式
+ const val AUDIO = 2 // 音频解码格式
+ }
+}
\ No newline at end of file
diff --git a/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCmd.kt b/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCmd.kt
index 8533f3a..3c1f1cc 100644
--- a/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCmd.kt
+++ b/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCmd.kt
@@ -2,9 +2,11 @@ package com.coder.ffmpeg.jni
import android.util.Log
import com.coder.ffmpeg.annotation.CodecAttribute
+import com.coder.ffmpeg.annotation.CodecProperty
import com.coder.ffmpeg.annotation.FormatAttribute
import com.coder.ffmpeg.annotation.MediaAttribute
import com.coder.ffmpeg.call.IFFmpegCallBack
+import com.coder.ffmpeg.model.CodecInfo
import java.util.*
/**
@@ -129,6 +131,19 @@ internal class FFmpegCmd private constructor() {
* @param type information type.
*/
private external fun info(videoPath: String?, type: Int): Int
+ /**
+ * Provide method to get codec info .
+ * @param property property type.
+ */
+ fun getCodecProperty(videoPath: String?,@CodecProperty property: Int): CodecInfo? {
+ return codec(videoPath, property)
+ }
+ /**
+ * Call native to get media information.
+ * @param videoPath media path
+ * @param type information type.
+ */
+ private external fun codec(videoPath: String?, type: Int): CodecInfo?
/**
* Provide method to get format info .
diff --git a/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCommand.kt b/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCommand.kt
index 752515e..daaf431 100644
--- a/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCommand.kt
+++ b/ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCommand.kt
@@ -1,9 +1,11 @@
package com.coder.ffmpeg.jni
import com.coder.ffmpeg.annotation.CodecAttribute
+import com.coder.ffmpeg.annotation.CodecProperty
import com.coder.ffmpeg.annotation.FormatAttribute
import com.coder.ffmpeg.annotation.MediaAttribute
import com.coder.ffmpeg.call.IFFmpegCallBack
+import com.coder.ffmpeg.model.CodecInfo
/**
* @author: AnJoiner
@@ -32,6 +34,18 @@ object FFmpegCommand {
return FFmpegCmd.instance?.getMediaInfo(path, type)
}
+ /**
+ * Get media codec info
+ *
+ * @param path media path
+ * @param type media property type [CodecProperty]
+ * @return media codec info [CodecInfo]
+ */
+ @JvmStatic
+ fun getCodecInfo(path: String?, @CodecProperty type: Int): CodecInfo? {
+ return FFmpegCmd.instance?.getCodecProperty(path, type)
+ }
+
/**
* Get support for unpacking format
*
diff --git a/ffmpeg/src/main/java/com/coder/ffmpeg/model/CodecInfo.kt b/ffmpeg/src/main/java/com/coder/ffmpeg/model/CodecInfo.kt
new file mode 100644
index 0000000..47efeb9
--- /dev/null
+++ b/ffmpeg/src/main/java/com/coder/ffmpeg/model/CodecInfo.kt
@@ -0,0 +1,7 @@
+package com.coder.ffmpeg.model
+
+data class CodecInfo(val id:Int, val name:String, val type:Int){
+ override fun toString(): String {
+ return "id = $id, name = $name, type = $type"
+ }
+}
\ No newline at end of file
diff --git a/ffmpeg/src/main/jniLibs/arm64-v8a/libffmpeg-command.so b/ffmpeg/src/main/jniLibs/arm64-v8a/libffmpeg-command.so
index b40d57b..82689de 100755
Binary files a/ffmpeg/src/main/jniLibs/arm64-v8a/libffmpeg-command.so and b/ffmpeg/src/main/jniLibs/arm64-v8a/libffmpeg-command.so differ
diff --git a/ffmpeg/src/main/jniLibs/armeabi-v7a/libffmpeg-command.so b/ffmpeg/src/main/jniLibs/armeabi-v7a/libffmpeg-command.so
index c004b24..487c077 100755
Binary files a/ffmpeg/src/main/jniLibs/armeabi-v7a/libffmpeg-command.so and b/ffmpeg/src/main/jniLibs/armeabi-v7a/libffmpeg-command.so differ