Skip to content

Commit 11890d8

Browse files
authored
[release] 🔧 Montage maker perf improvements
2 parents 851a46a + 25f27d7 commit 11890d8

6 files changed

Lines changed: 218 additions & 171 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.5.2
4+
5+
- Improved montage maker performance
6+
37
## 1.5.1
48

59
- Added option to rescan all faces in the project.

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ plugins {
2323
}
2424

2525
val appName = "Momentum"
26-
val appVersionCode = 1510
27-
val appVersionName = "1.5.1"
26+
val appVersionCode = 1520
27+
val appVersionName = "1.5.2"
2828
val appNameSpace = "shub39.momentum"
2929

3030
val gitHash = execute("git", "rev-parse", "HEAD").take(7)

app/src/main/assets/changelog.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
[
2+
{
3+
"version": "1.5.2",
4+
"changes": [
5+
"Improved montage maker performance"
6+
]
7+
},
28
{
39
"version": "1.5.1",
410
"changes": [

common/montage/src/main/kotlin/shub39/montage/FrameBuilder.kt

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package shub39.montage
1919
import android.content.Context
2020
import android.content.res.AssetFileDescriptor
2121
import android.graphics.Bitmap
22-
import android.graphics.BitmapFactory
2322
import android.graphics.Canvas
2423
import android.media.MediaCodec
2524
import android.media.MediaCodecInfo
@@ -33,35 +32,33 @@ import java.io.IOException
3332
import java.nio.ByteBuffer
3433

3534
internal class FrameBuilder(
36-
private val context: Context,
35+
context: Context,
3736
private val muxerConfig: MuxerConfiguration,
38-
@param:RawRes private val audioTrackResource: Int?,
37+
@property:RawRes audioTrackResource: Int?,
3938
) {
4039

4140
companion object {
4241
private const val TAG = "FrameBuilder"
4342
private const val TIMEOUT_USEC = 10_000L
4443
}
4544

46-
private val mediaFormat: MediaFormat =
47-
MediaFormat.createVideoFormat(
48-
muxerConfig.mimeType,
49-
muxerConfig.videoWidth,
50-
muxerConfig.videoHeight,
51-
)
52-
.apply {
53-
setInteger(
54-
MediaFormat.KEY_COLOR_FORMAT,
55-
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface,
56-
)
57-
setInteger(MediaFormat.KEY_BIT_RATE, muxerConfig.bitrate)
58-
setInteger(MediaFormat.KEY_FRAME_RATE, muxerConfig.framesPerSecond.toInt())
59-
setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, muxerConfig.iFrameInterval)
60-
setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_FULL)
61-
setInteger(MediaFormat.KEY_COLOR_STANDARD, MediaFormat.COLOR_STANDARD_BT709)
62-
setInteger(MediaFormat.KEY_COLOR_TRANSFER, MediaFormat.COLOR_TRANSFER_SDR_VIDEO)
63-
}
64-
45+
private val mediaFormat: MediaFormat = MediaFormat.createVideoFormat(
46+
muxerConfig.mimeType,
47+
muxerConfig.videoWidth,
48+
muxerConfig.videoHeight,
49+
)
50+
.apply {
51+
setInteger(
52+
MediaFormat.KEY_COLOR_FORMAT,
53+
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface,
54+
)
55+
setInteger(MediaFormat.KEY_BIT_RATE, muxerConfig.bitrate)
56+
setInteger(MediaFormat.KEY_FRAME_RATE, muxerConfig.framesPerSecond.toInt())
57+
setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, muxerConfig.iFrameInterval)
58+
setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_FULL)
59+
setInteger(MediaFormat.KEY_COLOR_STANDARD, MediaFormat.COLOR_STANDARD_BT709)
60+
setInteger(MediaFormat.KEY_COLOR_TRANSFER, MediaFormat.COLOR_TRANSFER_SDR_VIDEO)
61+
}
6562
private val mediaCodec: MediaCodec
6663
private val bufferInfo = MediaCodec.BufferInfo()
6764
private var surface: Surface? = null
@@ -71,6 +68,7 @@ internal class FrameBuilder(
7168
private var pushedFrames: Long = 0
7269

7370
init {
71+
7472
val codecs = MediaCodecList(MediaCodecList.REGULAR_CODECS)
7573
val codecName =
7674
codecs.findEncoderForFormat(mediaFormat)
@@ -95,21 +93,11 @@ internal class FrameBuilder(
9593
drainCodec(false)
9694
}
9795

98-
fun createFrame(image: Any) {
96+
fun createFrame(bitmap: Bitmap) {
9997
for (i in 0 until muxerConfig.framesPerImage) {
10098
val canvas = lockCanvas() ?: continue
101-
when (image) {
102-
is Int -> {
103-
val bitmap = BitmapFactory.decodeResource(context.resources, image)
104-
canvas.drawBitmap(bitmap, 0f, 0f, null)
105-
}
106-
is Bitmap -> canvas.drawBitmap(image, 0f, 0f, null)
107-
else -> Log.e(TAG, "Unsupported image type: ${image::class.java}")
108-
}
109-
99+
canvas.drawBitmap(bitmap, 0f, 0f, null)
110100
postCanvasFrame(canvas)
111-
112-
Thread.sleep(1)
113101
}
114102
}
115103

0 commit comments

Comments
 (0)