Skip to content

Commit

Permalink
Merge pull request #32 from adfleshner/main
Browse files Browse the repository at this point in the history
Removing AppCompatActivity in the CallQuery method
  • Loading branch information
ShwetaChauhan18 authored Feb 23, 2022
2 parents 4e7bc9d + c1dc5fb commit 7dee37a
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 177 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FFmpeg Android runs on the following architectures:

```
dependencies {
implementation 'com.github.SimformSolutionsPvtLtd:SSffmpegVideoOperation:1.0.7'
implementation 'com.github.SimformSolutionsPvtLtd:SSffmpegVideoOperation:1.0.8'
}
```

Expand All @@ -88,7 +88,7 @@ This is all you have to do to load the FFmpeg library.
In this sample code we will run the FFmpeg -version command in background call.
```java
val query:Array<String> = "-i, input,....,...., outout"
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun statisticsProcess(statistics: Statistics) {
Log.i("FFMPEG LOG : ", statistics.videoFrameNumber)
}
Expand All @@ -115,7 +115,7 @@ In this sample code we will run the FFmpeg -version command in background call.
val startTimeString = "00:01:00" (HH:MM:SS)
val endTimeString = "00:02:00" (HH:MM:SS)
val query:Array<String> = FFmpegQueryExtension().cutVideo(inputPath, startTimeString, endTimeString, outputPath)
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun statisticsProcess(statistics: Statistics) {
Log.i("FFMPEG LOG : ", statistics.videoFrameNumber)
}
Expand Down
2 changes: 1 addition & 1 deletion SSffmpegVideoOperation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ afterEvaluate {
from components.release
groupId = 'com.simform.videooperations'
artifactId = 'videooperations'
version = '1.0.7'
version = '1.0.8'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.simform.videooperations

import android.os.Handler
import android.os.Looper
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.arthenica.mobileffmpeg.Config
import com.arthenica.mobileffmpeg.FFmpeg
import java.util.concurrent.CyclicBarrier
Expand All @@ -10,13 +11,13 @@ import java.util.concurrent.CyclicBarrier
* Created by Ashvin Vavaliya on 22,January,2021
* Simform Solutions Pvt Ltd.
*/
public class CallBackOfQuery {
fun callQuery(context: AppCompatActivity, query: Array<String>, fFmpegCallBack: FFmpegCallBack) {
class CallBackOfQuery {
fun callQuery(query: Array<String>, fFmpegCallBack: FFmpegCallBack) {
val gate = CyclicBarrier(2)
object : Thread() {
override fun run() {
gate.await()
process(context, query, fFmpegCallBack)
process(query, fFmpegCallBack)
}
}.start()
gate.await()
Expand All @@ -34,29 +35,47 @@ public class CallBackOfQuery {
FFmpeg.cancel()
}

private fun process(context: AppCompatActivity, query: Array<String>, ffmpegCallBack: FFmpegCallBack) {
private fun process(query: Array<String>, ffmpegCallBack: FFmpegCallBack) {
val processHandler = Handler(Looper.getMainLooper())
Config.enableLogCallback { logMessage ->
val logs = LogMessage(logMessage.executionId, logMessage.level, logMessage.text)
ffmpegCallBack.process(logs)
processHandler.post {
ffmpegCallBack.process(logs)
}
}
Config.enableStatisticsCallback { statistics ->
val statisticsLog =
Statistics(statistics.executionId, statistics.videoFrameNumber, statistics.videoFps, statistics.videoQuality, statistics.size, statistics.time, statistics.bitrate, statistics.speed)
ffmpegCallBack.statisticsProcess(statisticsLog)
Statistics(
statistics.executionId,
statistics.videoFrameNumber,
statistics.videoFps,
statistics.videoQuality,
statistics.size,
statistics.time,
statistics.bitrate,
statistics.speed
)
processHandler.post {
ffmpegCallBack.statisticsProcess(statisticsLog)
}
}
when (FFmpeg.execute(query)) {
Config.RETURN_CODE_SUCCESS -> {
context.runOnUiThread {
processHandler.post {
ffmpegCallBack.success()
}
}
Config.RETURN_CODE_CANCEL -> {
ffmpegCallBack.cancel()
FFmpeg.cancel()
processHandler.post {
ffmpegCallBack.cancel()
FFmpeg.cancel()
}
}
else -> {
ffmpegCallBack.failed()
Config.printLastCommandOutput(Log.INFO)
processHandler.post {
ffmpegCallBack.failed()
Config.printLastCommandOutput(Log.INFO)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AudiosMergeActivity : BaseActivity(R.layout.activity_audios_merge, R.strin

val query = ffmpegQueryExtension.mergeAudios(pathsList, DURATION_FIRST, outputPath)

CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -79,11 +79,9 @@ class AudiosMergeActivity : BaseActivity(R.layout.activity_audios_merge, R.strin
}

private fun processStop() {
runOnUiThread {
btnAudioPath.isEnabled = true
btnMerge.isEnabled = true
mProgressView.visibility = View.GONE
}
btnAudioPath.isEnabled = true
btnMerge.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ChangeAudioVolumeActivity : BaseActivity(R.layout.activity_change_audio_va
private fun mergeAudioProcess() {
val outputPath = Common.getFilePath(this, Common.MP3)
val query = ffmpegQueryExtension.audioVolumeUpdate(tvInputPathAudio.text.toString(), volume = 0.1f, output = outputPath)
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -66,11 +66,9 @@ class ChangeAudioVolumeActivity : BaseActivity(R.layout.activity_change_audio_va
}

private fun processStop() {
runOnUiThread {
btnAudioPath.isEnabled = true
btnChange.isEnabled = true
mProgressView.visibility = View.GONE
}
btnAudioPath.isEnabled = true
btnChange.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CompressAudioActivity : BaseActivity(R.layout.activity_compress_audio, R.s
private fun compressAudioProcess() {
val outputPath = Common.getFilePath(this, Common.MP3)
val query = ffmpegQueryExtension.compressAudio(inputAudioPath = tvInputPathAudio.text.toString(), bitrate = BITRATE_128, output = outputPath)
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -67,11 +67,9 @@ class CompressAudioActivity : BaseActivity(R.layout.activity_compress_audio, R.s
}

private fun processStop() {
runOnUiThread {
btnAudioPath.isEnabled = true
btnChange.isEnabled = true
mProgressView.visibility = View.GONE
}
btnAudioPath.isEnabled = true
btnChange.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class CropAudioActivity : BaseActivity(R.layout.activity_crop_audio, R.string.cr
private fun cutProcess() {
val outputPath = Common.getFilePath(this, Common.MP3)
val query = ffmpegQueryExtension.cutAudio(tvInputPath.text.toString(), startTimeString, endTimeString, outputPath)
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -168,13 +168,11 @@ class CropAudioActivity : BaseActivity(R.layout.activity_crop_audio, R.string.cr
}

private fun processStop() {
runOnUiThread {
btnAudioPath.isEnabled = true
btnSelectStartTime.isEnabled = true
btnSelectEndTime.isEnabled = true
btnConvert.isEnabled = true
mProgressView.visibility = View.GONE
}
btnAudioPath.isEnabled = true
btnSelectStartTime.isEnabled = true
btnSelectEndTime.isEnabled = true
btnConvert.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FastAndSlowAudioActivity : BaseActivity(R.layout.activity_fast_and_slow_au
atempo = 0.5
}
val query = ffmpegQueryExtension.audioMotion(tvInputPathAudio.text.toString(), outputPath, atempo)
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand Down Expand Up @@ -84,11 +84,9 @@ class FastAndSlowAudioActivity : BaseActivity(R.layout.activity_fast_and_slow_au
}

private fun processStop() {
runOnUiThread {
btnAudioPath.isEnabled = true
btnMotion.isEnabled = true
mProgressView.visibility = View.GONE
}
btnAudioPath.isEnabled = true
btnMotion.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class MergeGIFActivity : BaseActivity(R.layout.activity_merge_gif, R.string.merg
}
val query = ffmpegQueryExtension.mergeGIF(pathsList, xPos, yPos, widthScale, heightScale, outputPath)

CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -131,11 +131,9 @@ class MergeGIFActivity : BaseActivity(R.layout.activity_merge_gif, R.string.merg
}

private fun processStop() {
runOnUiThread {
btnGifPath.isEnabled = true
btnMerge.isEnabled = true
mProgressView.visibility = View.GONE
}
btnGifPath.isEnabled = true
btnMerge.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AddTextOnVideoActivity : BaseActivity(R.layout.activity_add_text_on_video,
}
val fontPath = getFileFromAssets(this, "little_lord.ttf").absolutePath
val query = ffmpegQueryExtension.addTextOnVideo(tvInputPathVideo.text.toString(), edtText.text.toString(), xPos, yPos, fontPath = fontPath, isTextBackgroundDisplay = true, fontSize = 28, fontcolor = "red", output = outputPath)
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -96,11 +96,9 @@ class AddTextOnVideoActivity : BaseActivity(R.layout.activity_add_text_on_video,
}

private fun processStop() {
runOnUiThread {
btnVideoPath.isEnabled = true
btnAdd.isEnabled = true
mProgressView.visibility = View.GONE
}
btnVideoPath.isEnabled = true
btnAdd.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class AddWaterMarkOnVideoActivity : BaseActivity(R.layout.activity_add_water_mar
(edtYPos.text.toString().toFloat().times(it)).div(100)
}
val query = ffmpegQueryExtension.addVideoWaterMark(tvInputPathVideo.text.toString(), tvInputPathImage.text.toString(), xPos, yPos, outputPath)
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -131,12 +131,10 @@ class AddWaterMarkOnVideoActivity : BaseActivity(R.layout.activity_add_water_mar
}

private fun processStop() {
runOnUiThread {
btnVideoPath.isEnabled = true
btnImagePath.isEnabled = true
btnAdd.isEnabled = true
mProgressView.visibility = View.GONE
}
btnVideoPath.isEnabled = true
btnImagePath.isEnabled = true
btnAdd.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AspectRatioActivity : BaseActivity(R.layout.activity_aspect_ratio, R.strin
val outputPath = Common.getFilePath(this, Common.VIDEO)
val query = ffmpegQueryExtension.applyRatio(tvInputPathVideo.text.toString(), RATIO_1, outputPath)

CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand Down Expand Up @@ -84,11 +84,9 @@ class AspectRatioActivity : BaseActivity(R.layout.activity_aspect_ratio, R.strin
}

private fun processStop() {
runOnUiThread {
btnVideoPath.isEnabled = true
btnAspectRatio.isEnabled = true
mProgressView.visibility = View.GONE
}
btnVideoPath.isEnabled = true
btnAspectRatio.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CombineImageAndVideoActivity : BaseActivity(R.layout.activity_merge_image_

val query = ffmpegQueryExtension.combineImagesAndVideos(paths, width, height, edtSecond.text.toString(), outputPath)

CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand All @@ -128,12 +128,10 @@ class CombineImageAndVideoActivity : BaseActivity(R.layout.activity_merge_image_
}

private fun processStop() {
runOnUiThread {
btnVideoPath.isEnabled = true
btnImagePath.isEnabled = true
btnCombine.isEnabled = true
mProgressView.visibility = View.GONE
}
btnVideoPath.isEnabled = true
btnImagePath.isEnabled = true
btnCombine.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ class CombineImagesActivity : BaseActivity(R.layout.activity_combine_images, R.s
}

private fun processStop() {
runOnUiThread {
btnImagePath.isEnabled = true
btnCombine.isEnabled = true
mProgressView.visibility = View.GONE
}
btnImagePath.isEnabled = true
btnCombine.isEnabled = true
mProgressView.visibility = View.GONE
}

private fun processStart() {
Expand All @@ -91,7 +89,7 @@ class CombineImagesActivity : BaseActivity(R.layout.activity_combine_images, R.s

val query = ffmpegQueryExtension.combineImagesAndVideos(pathsList, 640, 480, edtSecond.text.toString(), outputPath)

CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun process(logMessage: LogMessage) {
tvOutputPath.text = logMessage.text
}
Expand Down
Loading

0 comments on commit 7dee37a

Please sign in to comment.