media icon indicating copy to clipboard operation
media copied to clipboard

Colours discrepancy when applying overlay

Open mikekudzin opened this issue 7 months ago • 0 comments

Version

Media3 pre-release (alpha, beta or RC not in this list)

More version details

1.4.0-beta01

Devices that reproduce the issue

Pixel 4a Android 13

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Overlaying video with a bitmap.

28 Jun 2024 11_18_34 GMT_overlays

no. 1: Create transparent media items with a BitmapOverlay Code:

    val bitmapOverlayWithText = BitmapOverlay.createStaticBitmapOverlay(overlayBitmap)
    val overlayFrameEMI = EditedMediaItem.Builder(MediaItem.fromUri(frameFile.toUri()))
        .setFrameRate(D_F_RATE)
        .setDurationUs(D_DURATION)
        .setRemoveAudio(true)
        .setEffects(
            Effects(
                listOf(),
                listOf(
                    OverlayEffect(ImmutableList.of(bitmapOverlayWithText)),
                )
            )
        )
        .build()

    val backgroundMI = MediaItem.fromUri(backgroundBitmapFile.toUri())
    val backgroundEMI = EditedMediaItem.Builder(backgroundMI)
        .setFrameRate(D_F_RATE)
        .setDurationUs(D_DURATION)
        .setRemoveAudio(true)
        .build()

    val videoMI = MediaItem.Builder().setUri(baseMediaUri)
        .setClippingConfiguration(
            MediaItem.ClippingConfiguration.Builder()
                .setStartPositionUs(0)
                .setEndPositionUs(D_DURATION)
                .build()
        )
        .build()

    val videoEMI = EditedMediaItem.Builder(videoMI)
        .setEffects(
            Effects(
                listOf(),
                listOf(ScaleAndRotateTransformation.Builder().setRotationDegrees(45f).build())
            )
        )
        .build()

    val composition = Composition.Builder(
        EditedMediaItemSequence(overlayFrameEMI),
        EditedMediaItemSequence(videoEMI),
        EditedMediaItemSequence(backgroundEMI),            
    )
        .build()

    val transformer: Transformer =
        Transformer.Builder(context)
            .setVideoMimeType(MimeTypes.VIDEO_H264)
            .setAudioMimeType(MimeTypes.AUDIO_AAC)
            .build()
    transformer.start(composition, outputFilePath)

Result:

image

no. 2: create MediaItem directly from the file Code diff val overlayFrameEMI = EditedMediaItem.Builder(MediaItem.fromUri(overlayFile.toUri())) .setFrameRate(D_F_RATE) .setDurationUs(D_DURATION) .build()

image

Although, the the last one looks close to origin, there is a significant colours discrepancy between the origin no. 1 and no. 2 I didn't observe no. 1 issue on 1.3.1

Expected result

Colours in the output are the same as in the origin.

Actual result

There is a difference between colours in the origin and BitmapOverlay

Media

Bug Report

  • [X] You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

mikekudzin avatar Jun 28 '24 11:06 mikekudzin