Rudimentary ffmpeg thumbnail

This commit is contained in:
Matthieu 2022-06-10 23:41:29 +02:00
parent 1a518ad492
commit 1f03f96d7a
8 changed files with 95 additions and 16 deletions

View File

@ -133,7 +133,7 @@ dependencies {
// Use the most recent version of CameraX
def cameraX_version = '1.1.0-rc01'
def cameraX_version = '1.1.0-rc02'
implementation "androidx.camera:camera-core:$cameraX_version"
implementation "androidx.camera:camera-camera2:$cameraX_version"
// CameraX Lifecycle library
@ -142,8 +142,6 @@ dependencies {
// CameraX View class
implementation "androidx.camera:camera-view:$cameraX_version"
implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
@ -155,6 +153,8 @@ dependencies {
* ----------------------------------------------------------
*/
implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
implementation 'com.arthenica:ffmpeg-kit-full:4.5.1-1.LTS'
implementation 'com.google.android.material:material:1.6.1'

View File

@ -26,6 +26,11 @@
android:name=".posts.AlbumActivity"
android:exported="false"
android:theme="@style/AppTheme.ActionBar.Transparent"/>
<activity
android:name=".postCreation.photoEdit.VideoEditActivity"
android:exported="false"
android:theme="@style/AppTheme.ActionBar.Transparent"/>
<activity
android:name=".posts.MediaViewerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"

View File

@ -37,6 +37,9 @@ import org.pixeldroid.app.utils.api.objects.Attachment
import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity
import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
import okhttp3.MultipartBody
import org.pixeldroid.app.postCreation.photoEdit.VideoEditActivity
import org.pixeldroid.app.posts.PostActivity
import org.pixeldroid.app.utils.api.objects.Status
import retrofit2.HttpException
import java.io.File
import java.io.FileNotFoundException
@ -447,16 +450,14 @@ class PostCreationActivity : BaseActivity() {
}
private fun edit(position: Int) {
if(photoData[position].video){
AlertDialog.Builder(this).apply {
setMessage(R.string.video_edit_not_yet_supported)
setNegativeButton(android.R.string.ok) { _, _ -> }
}.show()
} else {
val intent = Intent(this, PhotoEditActivity::class.java)
.putExtra(PhotoEditActivity.PICTURE_URI, photoData[position].imageUri)
.putExtra(PhotoEditActivity.PICTURE_POSITION, position)
editResultContract.launch(intent)
}
val intent = Intent(
this,
if(photoData[position].video) VideoEditActivity::class.java else PhotoEditActivity::class.java
)
.putExtra(PhotoEditActivity.PICTURE_URI, photoData[position].imageUri)
.putExtra(PhotoEditActivity.PICTURE_POSITION, position)
editResultContract.launch(intent)
}
}

View File

@ -0,0 +1,57 @@
package org.pixeldroid.app.postCreation.photoEdit
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.core.net.toUri
import com.arthenica.ffmpegkit.*
import com.arthenica.ffmpegkit.MediaInformation.KEY_DURATION
import com.bumptech.glide.Glide
import org.pixeldroid.app.databinding.ActivityVideoEditBinding
import org.pixeldroid.app.utils.BaseActivity
import java.io.File
class VideoEditActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityVideoEditBinding.inflate(layoutInflater)
setContentView(binding.root)
val uri = intent.getParcelableExtra(PhotoEditActivity.PICTURE_URI) as Uri?
val videoPosition = intent.getIntExtra(PhotoEditActivity.PICTURE_POSITION, -1)
val inputVideoPath =if(uri.toString().startsWith("content://")) FFmpegKitConfig.getSafParameterForRead(this, uri) else uri.toString()
val inputVideoPath2 =if(uri.toString().startsWith("content://")) FFmpegKitConfig.getSafParameterForRead(this, uri) else uri.toString()
val mediaInformation: MediaInformation? = FFprobeKit.getMediaInformation(inputVideoPath).mediaInformation
val duration: Long? = mediaInformation?.getNumberProperty(KEY_DURATION)
val file = File.createTempFile("temp_img", ".png").toUri()
val outputImagePath =if(file.toString().startsWith("content://")) FFmpegKitConfig.getSafParameterForWrite(this, file) else file.toString()
val session = FFmpegKit.execute(
"-i $inputVideoPath2 -filter_complex \"select='not(mod(n,1000))',scale=240:-1,tile=layout=4x1\" -vframes 1 -q:v 2 -y $outputImagePath"
)
if (ReturnCode.isSuccess(session.returnCode)) {
Glide.with(this).load(file).into(binding.thumbnails)
// SUCCESS
} else if (ReturnCode.isCancel(session.returnCode)) {
// CANCEL
} else {
// FAILURE
Log.d("VideoEditActivity",
String.format("Command failed with state %s and rc %s.%s",
session.state,
session.returnCode,
session.failStackTrace))
}
}
companion object {
const val VIDEO_TAG = "VideoEditTag"
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<ImageView
android:id="@+id/thumbnails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/thumbnail_reel_video_edit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -262,4 +262,5 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="no_storage_permission">Storage permission not granted, grant the permission in settings if you want to let PixelDroid show the thumbnail</string>
<string name="play_video">Play video</string>
<string name="video_edit_not_yet_supported">Video editing is not yet supported</string>
<string name="thumbnail_reel_video_edit">Reel showing thumbnails of the video you are editing</string>
</resources>

View File

@ -7,7 +7,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

View File

@ -1,6 +1,6 @@
#Tue Jun 07 20:42:16 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME