File tree Expand file tree Collapse file tree 8 files changed +70
-0
lines changed
java/com/coder/ffmpegtest/ui Expand file tree Collapse file tree 8 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import android.widget.TextView
88import androidx.appcompat.app.AppCompatActivity
99import androidx.recyclerview.widget.GridLayoutManager
1010import androidx.recyclerview.widget.RecyclerView
11+ import com.coder.ffmpeg.annotation.CodecProperty
1112import com.coder.ffmpeg.annotation.MediaAttribute
1213import com.coder.ffmpeg.jni.FFmpegCommand
1314import 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)
Original file line number Diff line number Diff line change 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" >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ package com.coder.ffmpeg.jni
22
33import android.util.Log
44import com.coder.ffmpeg.annotation.CodecAttribute
5+ import com.coder.ffmpeg.annotation.CodecProperty
56import com.coder.ffmpeg.annotation.FormatAttribute
67import com.coder.ffmpeg.annotation.MediaAttribute
78import com.coder.ffmpeg.call.IFFmpegCallBack
9+ import com.coder.ffmpeg.model.CodecInfo
810import 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 .
Original file line number Diff line number Diff line change 11package com.coder.ffmpeg.jni
22
33import com.coder.ffmpeg.annotation.CodecAttribute
4+ import com.coder.ffmpeg.annotation.CodecProperty
45import com.coder.ffmpeg.annotation.FormatAttribute
56import com.coder.ffmpeg.annotation.MediaAttribute
67import 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 *
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments