Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using lib in WPAndroid video compression scenario #652

Merged
merged 13 commits into from
May 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Using ComposerProvider in photo editor.
develric committed Mar 14, 2021
commit 99c7f27f7f3d75b52e14d2434a3745d4f76b514a
39 changes: 29 additions & 10 deletions photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt
Original file line number Diff line number Diff line change
@@ -47,7 +47,10 @@ import com.automattic.photoeditor.views.filter.CustomEffect
import com.automattic.photoeditor.views.filter.PhotoFilter
import com.bumptech.glide.Glide
import com.daasuu.mp4compose.FillMode
import com.daasuu.mp4compose.composer.Mp4Composer
import com.daasuu.mp4compose.composer.ComposerProvider
import com.daasuu.mp4compose.composer.ComposerUseCase.SaveVideoAsFile
import com.daasuu.mp4compose.composer.ComposerUseCase.SaveVideoFromBgAsFile
import com.daasuu.mp4compose.composer.Listener
import com.daasuu.mp4compose.filter.GlFilter
import com.daasuu.mp4compose.filter.GlFilterGroup
import com.daasuu.mp4compose.filter.GlGifWatermarkFilter
@@ -788,9 +791,16 @@ class PhotoEditor private constructor(builder: Builder) :
}
}

Mp4Composer(videoInputPath, videoOutputPath)
.with(context)
.addedHeaders(authenticationHeadersInterface?.getAuthHeaders(videoInputPath.toString()))
val composer = ComposerProvider.getComposerForUseCase(
SaveVideoAsFile(
videoInputPath,
videoOutputPath,
context,
authenticationHeadersInterface?.getAuthHeaders(videoInputPath.toString())
)
)

composer
// .size(width, height)
// IMPORTANT: as we aim at a WYSIWYG UX, we need to produce a video of size equal to that of the phone
// screen, given the user may be seeing a letterbox landscape video and placing emoji / text around
@@ -801,7 +811,7 @@ class PhotoEditor private constructor(builder: Builder) :
.fillMode(FillMode.PRESERVE_ASPECT_FIT)
.filter(if (customAddedViews.isNotEmpty()) GlFilterGroup(filterCollection) else null)
.mute(muteAudio)
.listener(object : Mp4Composer.Listener {
.listener(object : Listener {
override fun onProgress(progress: Double) {
Log.d(TAG, "onProgress = $progress")
onSaveListener.onProgress(progress)
@@ -821,6 +831,10 @@ class PhotoEditor private constructor(builder: Builder) :
Log.e(TAG, "onFailed()", exception)
onSaveListener.onFailure(exception)
}

override fun onStart() {
Log.d(TAG, "onStart()")
}
})
.start()
}
@@ -945,11 +959,13 @@ class PhotoEditor private constructor(builder: Builder) :
// take the static background image
val bmp = createBitmapFromView(parentView.source)

Mp4Composer(bmp, videoOutputPath)
.size(bmp.width, bmp.height) // FIXME check whether these are the right values or not
val composer = ComposerProvider.getComposerForUseCase(SaveVideoFromBgAsFile(bmp, videoOutputPath))

composer
.size(Size(bmp.width, bmp.height)) // FIXME check whether these are the right values or not
.fillMode(FillMode.PRESERVE_ASPECT_FIT)
.filter(GlFilterGroup(filterCollection))
.listener(object : Mp4Composer.Listener {
.listener(object : Listener {
override fun onProgress(progress: Double) {
Log.d(TAG, "onProgress = $progress")
// TODO: show progress to user
@@ -969,8 +985,11 @@ class PhotoEditor private constructor(builder: Builder) :
Log.e(TAG, "onFailed()", exception)
onSaveListener.onFailure(exception)
}
})
.start()

override fun onStart() {
Log.d(TAG, "onStart()")
}
}).start()
}

// TODO to be used in conjunction with mp4composer