-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathKFFmpegInfoActivity.kt
162 lines (140 loc) · 5.29 KB
/
KFFmpegInfoActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.coder.ffmpegtest.ui
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
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
import com.coder.ffmpegtest.model.CommandBean
import com.coder.ffmpegtest.ui.adapter.FFmpegCommandAdapter
import com.coder.ffmpegtest.utils.FileUtils
import java.io.File
import java.util.*
/**
*
* @author: AnJoiner
* @datetime: 20-4-8
*/
class KFFmpegInfoActivity : AppCompatActivity() {
private var mAudioPath: String? = null
private var mVideoPath: String? = null
private var tvContent: TextView? = null
private var mRecyclerView: RecyclerView? = null
private var mAdapter: FFmpegCommandAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_ffmpeg_info)
init()
}
private fun init() {
initView()
initData()
initListener()
}
private fun initView() {
mRecyclerView = findViewById(R.id.rv)
tvContent = findViewById(R.id.tv_content)
}
private fun initData() {
FileUtils.copy2Memory(this, "test.mp3")
FileUtils.copy2Memory(this, "test.mp4")
mAudioPath = File(externalCacheDir, "test.mp3").absolutePath
mVideoPath = File(externalCacheDir, "test.mp4").absolutePath
val commands = this.resources.getStringArray(R.array.infos)
val beans: MutableList<CommandBean> = ArrayList()
for (i in commands.indices) {
beans.add(CommandBean(commands[i], i))
}
mAdapter = FFmpegCommandAdapter(beans)
mRecyclerView!!.layoutManager = GridLayoutManager(this, 3)
mRecyclerView!!.adapter = mAdapter
}
private fun initListener() {
mAdapter!!.setItemClickListener (object : FFmpegCommandAdapter.ItemClickListener {
override fun itemClick(id: Int) {
when (id) {
0 -> getDuration()
1 -> getWidth()
2 -> getHeight()
3 -> getVideoBitRate()
4 -> getVideoFPS()
5 -> getChannels()
6 -> getSampleRate()
7 -> getAudioBitRate()
8 -> getVideoCodec()
9 -> getAudioCodec()
}
}
})
}
private fun getDuration() {
val AV_TIME_BASE = 1000000;
val duration = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.DURATION)
Log.d("FFmpeg", "duration: $duration")
var secs = duration?.div(AV_TIME_BASE)
val us = duration?.rem(AV_TIME_BASE)
var mins = secs?.div(60)
secs = secs?.rem(60)
val hours = mins?.div(60)
mins = mins?.rem(60)
val result = String.format("%02d:%02d:%02d.%02d", hours, mins, secs, (100 * us!!) / AV_TIME_BASE)
tvContent?.text = result
}
private fun getWidth() {
val width = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.WIDTH)
val result = String.format("width = %s", width)
tvContent?.text = result
}
private fun getHeight() {
val height = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.HEIGHT)
val result = String.format("height = %s", height)
tvContent?.text = result
}
private fun getVideoBitRate() {
val bitRate = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.VIDEO_BIT_RATE)
val result = String.format("bitRate = %s", bitRate)
tvContent?.text = result
}
private fun getVideoFPS() {
val fps = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.FPS)
val result = String.format("fps = %s", fps)
tvContent?.text = result
}
private fun getChannels() {
val channels = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.CHANNELS)
val result = String.format("channels = %s", channels)
tvContent?.text = result
}
private fun getSampleRate() {
val sampleRate = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.SAMPLE_RATE)
val result = String.format("sampleRate = %s", sampleRate)
tvContent?.text = result
}
private fun getAudioBitRate() {
val bitRate = FFmpegCommand.getMediaInfo(mVideoPath, MediaAttribute.AUDIO_BIT_RATE)
val result = String.format("bitRate = %s", bitRate)
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)
context.startActivity(intent)
}
}
}