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

transformer.getProgress get wrong progress in version 1.3.1/1.4.1 but it play well in version 1.1.1/1.2.1 #1804

Open
1 task done
yifanLon opened this issue Oct 14, 2024 · 1 comment

Comments

@yifanLon
Copy link

yifanLon commented Oct 14, 2024

Version

Media3 1.4.1

More version details

it can Reproduce bug on version 1.3.1 and 1.4.1

Devices that reproduce the issue

OnePlus PGZ110 running android 14

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

I tried to to use media3 to compress video,and i tried to get compress Progress,
it play well on version1.1.1/1.2.1
but on version 1.3.1/1.4.1, the progress seems can't upto 60, when i get probably 60% the transform is complete, and the video compressed is normal. so i tried many video and many times. it reproduce everytime

this is my demo code to reproduce this bug

   String localVideoPath = "/storage/emulated/0/Movies/CameraX-Video/2024-03-01-17-37-18-143.mp4";
    String videoPath = getFilesDir().getAbsolutePath() + File.separator + "outPutVideo"+File.separator + "compressVideo.mp4";
    try {
        File file = new File(videoPath);
        if(file.exists()){
            file.delete();
        }
        if (file.getParent() != null && !new File(file.getParent()).exists()) {
            new File(file.getParent()).mkdirs();
        }
        if (!file.exists()) {
            file.createNewFile();
        }
    }catch (Exception e){}
MediaItem mediaItem = MediaItem.fromUri(localVideoPath);
ImmutableList<AudioProcessor> audioProcessors = ImmutableList.of();
ImmutableList.Builder<Effect> effectBuilder = new ImmutableList.Builder<>();

ScaleAndRotateTransformation scaleAndRotateTransformation = new ScaleAndRotateTransformation.Builder()
        .setScale(0.5f,0.5f)
        .build();
effectBuilder.add(scaleAndRotateTransformation);
//effectBuilder.add(Presentation.createForHeight(1080));
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).setEffects(new Effects(audioProcessors,effectBuilder.build())).build();
Transformer transformer = new Transformer.Builder(this)
        .addListener(new Transformer.Listener() {
            @Override
            public void onCompleted(Composition composition, ExportResult exportResult) {
                Transformer.Listener.super.onCompleted(composition, exportResult);
                ThreadHelper.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        r.progressBar.setProgress(100);
                    }
                });
            }

            @Override
            public void onError(Composition composition, ExportResult exportResult, ExportException exportException) {
                ThreadHelper.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.d("test2",""+exportResult.exportException.getMessage());
                    
                    }
                });
            }
        }).build();
transformer.start(editedMediaItem,videoPath);

ProgressHolder progressHolder = new ProgressHolder();
mainHandler.post(
        new Runnable() {
            @OptIn(markerClass = UnstableApi.class) @Override
            public void run() {
                @Transformer.ProgressState int progressState = transformer.getProgress(progressHolder);
                updateProgressInUi(progressState, progressHolder);
                if (progressState != PROGRESS_STATE_NOT_STARTED) {
                    mainHandler.postDelayed(/* r= */ this, /* delayMillis= */ 33L);
                }
            }
        });

Expected result

get progress correctly

Actual result

get progress not correct, seems can't up to 60%

Media

Not applicable

Bug Report

  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.
@droid-girl
Copy link
Contributor

@yifanLon could you clarify if the output file produced is a valid file. The problem is only in the progress calculation, is it correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants