From 66f56809bf3837a1de2201ce9a47b612fc04a0e6 Mon Sep 17 00:00:00 2001 From: Qiming Date: Thu, 3 Nov 2022 16:13:45 +0800 Subject: [PATCH 1/4] =?UTF-8?q?equalizer=20-=20=E7=AE=80=E5=8C=96=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java index f592cc7..14306ca 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -244,14 +244,9 @@ public class FFmpegUtil { | 10b | 11b | 12b | 13b | 14b | 15b | 16b | 17b | 18b | | 1480 | 2093 | 2960 | 4186 | 5920 | 8372 | 11840 | 16744 | 20000 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ - StringBuilder builder = new StringBuilder(); - for (String band:bandList) { - builder.append(band).append(":"); - } - builder.deleteCharAt(builder.length() - 1); - // "ffmpeg -i %s -af superequalizer=%s -y %s" + String bands = String.join(":", bandList); String equalizerCmd = "ffmpeg -i -af superequalizer=%s -y"; - equalizerCmd = String.format(Locale.getDefault(), equalizerCmd, builder.toString()); + equalizerCmd = String.format(Locale.getDefault(), equalizerCmd, bands); return insert(equalizerCmd.split(" "), 2, inputPath, outputPath); } From 454c18275e5590b1eac69d144cc7ea15788b6d05 Mon Sep 17 00:00:00 2001 From: Qiming Date: Sat, 5 Nov 2022 14:50:34 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=8B=BC=E6=8E=A5ffmpeg?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?:=20Unable=20to=20find=20a=20suitable=20output=20format=20for?= =?UTF-8?q?=20'file.txt'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/frank/ffmpeg/activity/VideoHandleActivity.kt | 9 ++------- app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt index 30e8233..1cb6952 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt @@ -377,15 +377,10 @@ class VideoHandleActivity : BaseActivity() { Log.e(TAG, "width=$width--height=$height") } val transformCmd2 = FFmpegUtil.transformVideoWithEncode(appendPath, width, height, outputPath2) - val fileList = ArrayList() - fileList.add(outputPath1) - fileList.add(outputPath2) + val fileList = listOf(outputPath1, outputPath2) FileUtil.createListFile(listPath, fileList) val jointVideoCmd = FFmpegUtil.jointVideo(listPath, targetPath) - val commandList = ArrayList>() - commandList.add(transformCmd1) - commandList.add(transformCmd2) - commandList.add(jointVideoCmd) + val commandList = listOf(transformCmd1, transformCmd2, jointVideoCmd) ffmpegHandler!!.executeFFmpegCmds(commandList) } diff --git a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java index 14306ca..4a30fcc 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -354,7 +354,7 @@ public class FFmpegUtil { */ public static String[] jointVideo(String fileListPath, String outputPath) { // ffmpeg -f concat -safe 0 -i %s -c copy %s - String jointVideoCmd = "ffmpeg -f concat -safe 0 -i file.txt -c copy %s"; + String jointVideoCmd = "ffmpeg -f concat -safe 0 -i -c copy -y"; return insert(jointVideoCmd.split(" "), 6, fileListPath, outputPath); } From becc4e87739e0ffd0819fd286c536b96d8c856e3 Mon Sep 17 00:00:00 2001 From: Qiming Date: Sun, 6 Nov 2022 10:38:04 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Probe=E4=B8=8D=E6=8A=93=E5=B8=A7=E6=97=B6UI?= =?UTF-8?q?=E4=B8=8A=E6=B8=85=E9=99=A4=E4=B9=8B=E5=89=8D=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E5=9B=BE=E7=89=87=EF=BC=9B=E7=A1=AE=E4=BF=9D=E6=8A=93?= =?UTF-8?q?=E5=B8=A7=E6=97=B6=E9=97=B4=E7=82=B9=E4=B8=8D=E8=B6=85=E8=BF=87?= =?UTF-8?q?duration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frank/ffmpeg/activity/ProbeFormatActivity.kt | 13 +++++++++---- .../frank/ffmpeg/metadata/FFmpegMediaRetriever.java | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/ProbeFormatActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/ProbeFormatActivity.kt index 0119b78..ca3dfe7 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/ProbeFormatActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/ProbeFormatActivity.kt @@ -57,9 +57,8 @@ class ProbeFormatActivity : BaseActivity() { MSG_FINISH -> { progressProbe!!.visibility = View.GONE layoutProbe!!.visibility = View.VISIBLE - val result = msg.obj?: msg.obj - if (result != null) { - val mediaInfo = JsonParseTool.stringFormat(result as MediaBean) + if (msg.obj != null) { + val mediaInfo = JsonParseTool.stringFormat(msg.obj as MediaBean) if (!mediaInfo.isNullOrEmpty() && txtProbeFormat != null) { txtProbeFormat!!.text = mediaInfo } @@ -108,6 +107,7 @@ class ProbeFormatActivity : BaseActivity() { when (view?.id) { R.id.btn_probe_format -> { + findViewById(R.id.img_frame).setImageBitmap(null) doHandleProbe(filePath) } R.id.btn_retrieve_format -> { @@ -188,7 +188,12 @@ class ProbeFormatActivity : BaseActivity() { mHandler.obtainMessage(MSG_INFO, resultBuilder.toString()).sendToTarget() // Retrieve frame with timeUs - val bitmap = retriever.getFrameAtTime(5 * 1000000) + val frameTime = if (duration != null) { + duration.toLong() / 3 * 1000 + } else { + 5 * 1000000 + } + val bitmap = retriever.getFrameAtTime(frameTime) // Retrieve audio thumbnail, if it has embedded // val bitmap = retriever.audioThumbnail if (bitmap != null) { diff --git a/app/src/main/java/com/frank/ffmpeg/metadata/FFmpegMediaRetriever.java b/app/src/main/java/com/frank/ffmpeg/metadata/FFmpegMediaRetriever.java index f24796d..405d466 100755 --- a/app/src/main/java/com/frank/ffmpeg/metadata/FFmpegMediaRetriever.java +++ b/app/src/main/java/com/frank/ffmpeg/metadata/FFmpegMediaRetriever.java @@ -31,7 +31,7 @@ public class FFmpegMediaRetriever { public FFmpegMediaRetriever() { native_init(); - native_setup(); + native_setup(); } public void setDataSource(String path) { From ee61c639f3d01ed523e9b45bd4e775053f38413c Mon Sep 17 00:00:00 2001 From: Qiming Date: Tue, 8 Nov 2022 18:12:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?AudioEffect=20-=20Fixed=20a=20typo;=20Kotli?= =?UTF-8?q?n=E9=A3=8E=E6=A0=BC=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AudioEffectController.kt | 2 +- .../listener/AudioEffectCallback.kt | 2 +- .../ffmpeg/activity/AudioEffectActivity.kt | 39 ++++++++++--------- .../ffmpeg/activity/EqualizerActivity.kt | 4 +- .../frank/ffmpeg/adapter/EqualizerAdapter.kt | 6 +-- ...SeeBarListener.kt => OnSeekBarListener.kt} | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) rename app/src/main/java/com/frank/ffmpeg/listener/{OnSeeBarListener.kt => OnSeekBarListener.kt} (72%) diff --git a/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt b/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt index 6f7db41..7bac240 100644 --- a/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt +++ b/AndroidMedia/src/main/java/com/frank/androidmedia/controller/AudioEffectController.kt @@ -91,7 +91,7 @@ open class AudioEffectController(audioEffectCallback: AudioEffectCallback) { override fun onItemSelected(arg0: AdapterView<*>, arg1: View, arg2: Int, arg3: Long) { try { mEqualizer!!.usePreset(arg2.toShort()) - val seekBarList: List? = mAudioEffectCallback?.getSeeBarList() + val seekBarList: List? = mAudioEffectCallback?.getSeekBarList() if (mBands > 0 && seekBarList != null && mEqualizer != null) { for (band in 0 until mBands) { seekBarList[band].progress = mEqualizer!!.getBandLevel(band.toShort()) - minEQLevel diff --git a/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt b/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt index 1b61d08..74a661f 100644 --- a/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt +++ b/AndroidMedia/src/main/java/com/frank/androidmedia/listener/AudioEffectCallback.kt @@ -12,7 +12,7 @@ import java.util.ArrayList */ interface AudioEffectCallback { - fun getSeeBarList(): List? + fun getSeekBarList(): List? fun setEqualizerList(maxProgress: Int, equalizerList: ArrayList>) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt index e9f38cd..82ea033 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioEffectActivity.kt @@ -15,7 +15,7 @@ import com.frank.androidmedia.controller.AudioEffectController import com.frank.androidmedia.listener.AudioEffectCallback import com.frank.ffmpeg.R import com.frank.ffmpeg.adapter.EqualizerAdapter -import com.frank.ffmpeg.listener.OnSeeBarListener +import com.frank.ffmpeg.listener.OnSeekBarListener import com.frank.ffmpeg.util.FileUtil import com.frank.ffmpeg.view.VisualizerView import java.io.IOException @@ -25,11 +25,11 @@ import java.util.ArrayList * Audio effect: equalizer, enhancer, visualizer, bassBoost * Created by frank on 2020/10/20. */ -class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallback { +class AudioEffectActivity : BaseActivity(), OnSeekBarListener, AudioEffectCallback { companion object { - private val audioPath = Environment.getExternalStorageDirectory().path + "/tiger.mp3" + private var audioPath = Environment.getExternalStorageDirectory().path + "/tiger.mp3" } private var mPlayer: MediaPlayer? = null @@ -48,12 +48,13 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac Manifest.permission.MODIFY_AUDIO_SETTINGS) private val onPreparedListener = MediaPlayer.OnPreparedListener { - mAudioEffectController = AudioEffectController(this) - mAudioEffectController?.setupEqualizer(mPlayer!!.audioSessionId) - mAudioEffectController?.setupPresetStyle(this@AudioEffectActivity, spinnerStyle!!) - mAudioEffectController?.setupBassBoost(mPlayer!!.audioSessionId, barBassBoost!!) - mAudioEffectController?.setLoudnessEnhancer(mPlayer!!.audioSessionId, barEnhancer!!) - mAudioEffectController?.setupVisualizer(mPlayer!!.audioSessionId) + mAudioEffectController = AudioEffectController(this).apply { + setupEqualizer(mPlayer!!.audioSessionId) + setupPresetStyle(this@AudioEffectActivity, spinnerStyle!!) + setupBassBoost(mPlayer!!.audioSessionId, barBassBoost!!) + setLoudnessEnhancer(mPlayer!!.audioSessionId, barEnhancer!!) + setupVisualizer(mPlayer!!.audioSessionId) + } mPlayer!!.start() } @@ -95,10 +96,11 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac return } try { - mPlayer = MediaPlayer() - mPlayer!!.setDataSource(audioPath) - mPlayer!!.setOnPreparedListener(onPreparedListener) - mPlayer!!.prepareAsync() + mPlayer = MediaPlayer().apply { + setDataSource(audioPath) + setOnPreparedListener(onPreparedListener) + prepareAsync() + } } catch (e: IOException) { Log.e("AudioEffect", "play error=$e") } @@ -113,17 +115,18 @@ class AudioEffectActivity : BaseActivity(), OnSeeBarListener, AudioEffectCallbac } override fun onSelectedFile(filePath: String) { - + audioPath = filePath + initPlayer() } override fun setEqualizerList(maxProgress: Int, equalizerList: ArrayList>) { - if (equalizerAdapter != null) { - equalizerAdapter!!.setMaxProgress(maxProgress) - equalizerAdapter!!.setEqualizerList(equalizerList) + equalizerAdapter?.let { + it.setMaxProgress(maxProgress) + it.setEqualizerList(equalizerList) } } - override fun getSeeBarList(): List? { + override fun getSeekBarList(): List? { return equalizerAdapter?.getSeekBarList() } diff --git a/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt index 083a299..12cea5a 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt @@ -12,12 +12,12 @@ import androidx.recyclerview.widget.RecyclerView import com.frank.ffmpeg.AudioPlayer import com.frank.ffmpeg.R import com.frank.ffmpeg.adapter.EqualizerAdapter -import com.frank.ffmpeg.listener.OnSeeBarListener +import com.frank.ffmpeg.listener.OnSeekBarListener import com.frank.ffmpeg.view.VisualizerView import java.lang.StringBuilder import java.util.ArrayList -class EqualizerActivity : BaseActivity(), OnSeeBarListener { +class EqualizerActivity : BaseActivity(), OnSeekBarListener { // unit: Hz gain:0-20 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt b/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt index 307504f..9af0e7f 100644 --- a/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt +++ b/app/src/main/java/com/frank/ffmpeg/adapter/EqualizerAdapter.kt @@ -10,7 +10,7 @@ import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.frank.ffmpeg.R -import com.frank.ffmpeg.listener.OnSeeBarListener +import com.frank.ffmpeg.listener.OnSeekBarListener import java.util.ArrayList @@ -20,7 +20,7 @@ import java.util.ArrayList * @desc Adapter of equalizer */ -class EqualizerAdapter(private val context: Context, private val onSeeBarListener: OnSeeBarListener?) : RecyclerView.Adapter() { +class EqualizerAdapter(private val context: Context, private val onSeekBarListener: OnSeekBarListener?) : RecyclerView.Adapter() { private var equalizerList: List>? = ArrayList() private val seekBarList = ArrayList() @@ -51,7 +51,7 @@ class EqualizerAdapter(private val context: Context, private val onSeeBarListene } override fun onStopTrackingTouch(seekBar: SeekBar) { - onSeeBarListener?.onProgress(i, seekBar.progress) + onSeekBarListener?.onProgress(i, seekBar.progress) } }) } diff --git a/app/src/main/java/com/frank/ffmpeg/listener/OnSeeBarListener.kt b/app/src/main/java/com/frank/ffmpeg/listener/OnSeekBarListener.kt similarity index 72% rename from app/src/main/java/com/frank/ffmpeg/listener/OnSeeBarListener.kt rename to app/src/main/java/com/frank/ffmpeg/listener/OnSeekBarListener.kt index 73fa736..611ed97 100644 --- a/app/src/main/java/com/frank/ffmpeg/listener/OnSeeBarListener.kt +++ b/app/src/main/java/com/frank/ffmpeg/listener/OnSeekBarListener.kt @@ -1,5 +1,5 @@ package com.frank.ffmpeg.listener -interface OnSeeBarListener { +interface OnSeekBarListener { fun onProgress(index: Int, progress: Int) } \ No newline at end of file