@@ -19,7 +19,6 @@ package shub39.montage
1919import android.content.Context
2020import android.content.res.AssetFileDescriptor
2121import android.graphics.Bitmap
22- import android.graphics.BitmapFactory
2322import android.graphics.Canvas
2423import android.media.MediaCodec
2524import android.media.MediaCodecInfo
@@ -33,35 +32,33 @@ import java.io.IOException
3332import java.nio.ByteBuffer
3433
3534internal 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