Skip to content

Commit

Permalink
🎨 新增获取媒体的编码信息
Browse files Browse the repository at this point in the history
  • Loading branch information
AnJoiner committed Nov 5, 2023
1 parent 793f8f5 commit 62b5989
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/com/coder/ffmpegtest/ui/KFFmpegInfoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +77,8 @@ class KFFmpegInfoActivity : AppCompatActivity() {
5 -> getChannels()
6 -> getSampleRate()
7 -> getAudioBitRate()
8 -> getVideoCodec()
9 -> getAudioCodec()
}
}
})
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<item>音频声道数</item>
<item>音频采样率</item>
<item>音频比特率</item>
<item>视频Codec</item>
<item>音频Codec</item>
</string-array>

<string-array name="formats">
Expand Down
17 changes: 17 additions & 0 deletions ffmpeg/src/main/java/com/coder/ffmpeg/annotation/CodecProperty.kt
Original file line number Diff line number Diff line change
@@ -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 // 音频解码格式
}
}
15 changes: 15 additions & 0 deletions ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCmd.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

/**
Expand Down Expand Up @@ -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 .
Expand Down
14 changes: 14 additions & 0 deletions ffmpeg/src/main/java/com/coder/ffmpeg/jni/FFmpegCommand.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions ffmpeg/src/main/java/com/coder/ffmpeg/model/CodecInfo.kt
Original file line number Diff line number Diff line change
@@ -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"
}
}
Binary file modified ffmpeg/src/main/jniLibs/arm64-v8a/libffmpeg-command.so
Binary file not shown.
Binary file modified ffmpeg/src/main/jniLibs/armeabi-v7a/libffmpeg-command.so
Binary file not shown.

0 comments on commit 62b5989

Please sign in to comment.