48 Star 420 Fork 149

AnJoiner / FFmpegCommand

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
KFFmpegInfoActivity.kt 5.29 KB
一键复制 编辑 原始数据 按行查看 历史
AnJoiner 提交于 2023-11-05 23:10 . :art:新增获取媒体的编码信息
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)
}
}
}
Android
1
https://gitee.com/anjoiner/FFmpegCommand.git
git@gitee.com:anjoiner/FFmpegCommand.git
anjoiner
FFmpegCommand
FFmpegCommand
master

搜索帮助