google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

Play videos with 90 degree rotation #10835

Open Manli123 opened 1 year ago

Manli123 commented 1 year ago

ExoPlayer Version

2.18.2

Devices that reproduce the issue

I tested on android 8.1

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

EDIT copied from title by @marcbachinger: "I set playerview.setRotation and i recorded video using native camera in portrait mode so its rotation degree is 90.Then I play in exoplayer it plays correctly in portrait mode again I play same video it rotates automatically.I set portrait in manifest for same activity.vide"

Any native camera recorded video Exoplayer does not rotate but video does when scroll up and down multiple times in viewpager.

  DefaultRenderersFactory rf = new DefaultRenderersFactory(mContext)
                .setExtensionRendererMode(EXTENSION_RENDERER_MODE_PREFER).setMediaCodecSelector(
                        new MediaCodecSelector() {
                            @Override
                            public List<MediaCodecInfo> getDecoderInfos(String mimeType,
                                                                        boolean requiresSecureDecoder, boolean requiresTunnelingDecoder)
                                    throws MediaCodecUtil.DecoderQueryException {
                                List<MediaCodecInfo> decoderInfos = MediaCodecSelector.DEFAULT
                                        .getDecoderInfos(mimeType, requiresSecureDecoder, requiresTunnelingDecoder);
                                if (MimeTypes.VIDEO_H264.equals(mimeType)) {
                                    // copy the list because MediaCodecSelector.DEFAULT returns an unmodifiable list
                                    decoderInfos = new ArrayList<>(decoderInfos);
                                    Collections.reverse(decoderInfos);
                                }
                                return decoderInfos;
                            }
                        });

exoPlayer = new ExoPlayer.Builder(holder.mVideoView.getContext(),rf).setLoadControl(loadControl).build();

holder.mVideoView.setPlayer(exoPlayer);
holder.mVideoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
holder.mVideoView.setShutterBackgroundColor(Color.TRANSPARENT);
holder.mVideoView.setKeepContentOnPlayerReset(true);
exoPlayer.seekTo(0);
exoPlayer.setRepeatMode(Player.REPEAT_MODE_ONE);

 mediaSource = new ProgressiveMediaSource.Factory(
        new CacheDataSource.Factory()
                .setCache(SimpleMediaPlayer.getInstance(mContext))
                .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory()
                        .setUserAgent(mContext.getString(R.string.app_name)))
                .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
).createMediaSource(MediaItem.fromUri(videoItem.videoURL));

exoPlayer.addMediaSource(mediaSource);

exoPlayer.prepare();

exoPlayer.setPlayWhenReady(true);
exoPlayer.play();

Expected result

All videos should play in portrait.

Actual result

video sideways

Media

Any native camera recorded video

Bug Report

marcbaechinger commented 1 year ago

Sorry but I'm not sure I understand what you are trying to achieve. setRotation is method that belongs to the super class View of the PlayerView and is not a library specific.

Can you play your video in the demo app and then explain starting from there? Like how it does display in the demo app and how you would want it to be displayed and how you try to achieve this?

Manli123 commented 1 year ago

I want to play all videos in portrait mode only .Here my screen is Portrait but video rotate like landspace. video is 1280*960,rotaion 90. Exoplayer swaps this width, height to shows video in portrait correctly but when i scroll up video shows by rotating 90 degree sideways on android 8.1.

video which has 90 degree rotation, portrait mode i had recorded. I am trying to play this video in l viewpager with recyclerview adapter like tiktok. first time it plays correctly but when scroll up down multiple times it rotates by 90 right degree. Why?..Is there any solution please please provide me solution.

I think exoplayer does not rotate but video actually rotated by 90 right degree. but please tell any solution i added my code above also . Is there any changes should i make?

And unappliedrotationdegree is returning always 0 in onVideoSizeChanged.I tested on android 8.1. So I am not able to find out when video rotated? Unfortunately, as of now, there's no easy way to determine whether a decoder has actually applied the rotation.

Let me know u got my point?

you can check my code above.

On Tue, Dec 6, 2022, 6:37 PM Marc Baechinger @.***> wrote:

Sorry but I'm not sure I understand what you are trying to achieve. setRotation is method that belongs to the super class View of the PlayerView and is not a library specific.

Can you play your video in the demo app and then explain starting from there? Like how it does display in the demo app https://exoplayer.dev/demo-application.html and how you would want it to be displayed and how you try to achieve this?

— Reply to this email directly, view it on GitHub https://github.com/google/ExoPlayer/issues/10835#issuecomment-1339317764, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHWFQR7ZMPZRI6OSKVMCKKTWL4275ANCNFSM6AAAAAASVDSHOM . You are receiving this because you authored the thread.Message ID: @.***>

Manli123 commented 1 year ago

is there any solution as I have no time to wait.Project is going to live.Please give me solution for this.This is very urgent. video are storing cache and playing .Again I am saying it plays corrctly first time but when i scroll multiple times,It get rotate.This issue is only with video which 90 degree metadata. I am playing videos in viewpager with recycler adapter like tiktok. This is on Android 8.1. Please reply fast.

Manli123 commented 1 year ago

@ojw28 Just a small remark - the automatic applying of video orientation while decoding to a surface is true only for the default hardware decoder - when using software decoding for example (using OMX.google.h264.decoder) it does not apply rotation even on Lollipop+. So people using custom decoders (software or other) might still need the orientation parameter even on Lollipop+ (So maybe the orientation param should always be included and ignored on Lollipop+?)

I found this. Issue--#91 OMX.google.h264.decoder this is used to decode same video. And sometimes it rotates.

Note--Video does not rotated every time but it rotates when scroll up or scoroll multiple time. All videos are playing from cache.

Please reopen #91.

Please check where is exact issue and tell how i can solve this now.

marcbaechinger commented 1 year ago

Thanks for the info. I'm not sure if this is a player issue, because the behaviour involves calling setRotation on a View and scrolling within the UI. I don't understand how this is related to ExoPlayer because I think the player is not aware of this rotation which is part of your workaround.

However, sorry for not being quick enough for your expectations. I understand that you are under time pressure, but unfortunately we can't give you 1:1 support with this I'm afraid.

One way to speed up things would be to post a URI to such a video, so we can investigate in the demo app. To see whether something is wrong. However, I don't think we can give you support for your workaround for the sw decoder problem you are seeing with rotation.

Manli123 commented 1 year ago

Then where is problem? I found this bahaviour on Android 8.1 vivo 1811.On Android 11 I did not found this issue yet. Android 7.1 yesterday did not found this issue but today I got this bug on same device. I am badly stuck here.Please help me. exoplayer rotate video on android 8.1 sometime wrong direction for rare case. Note--video does not rotate every time.It plays correct but sometime not. please check.

This is video url. you can check. Play it multiple times using cache memory in scroll behaviour then video will rotate. I used viewpager with recycler adapter like tiktok.

Manli123 commented 1 year ago

Yesterday I checked on android 7.1.It did not rotate video. It played correctly.But Just now I checked again It is rotating sometimes . I did not found any solution for this yet. My project is ready.Last moment what can i do? Badly stuck. Sir please help me. Why this is rotating sometimes, sometimes it is playing correctly.

Note: Videos are playing from cache.Video Link I shared in previous comment.

Manli123 commented 1 year ago

If don't think so Problem is in decoder bacause I think video decoding happen only once then videos are playing from cache memory. If problem is in decoder then first time I ll get this issue na but first time video plays correctly. When video plays from cache then video plays in rotated form. This happens most of times on android 8.1.

Manli123 commented 1 year ago

This is bug. I created separate project and tried.It is rotating Sometimes. What I observe that if i dont initialise exoplayer with DefaultRendersFactory video does not rotated but 3k,4k Videos fetch error decoder initialise failed.Then what should do?Any solution.. I am initialising and releasing player correctly.

This is my code. public void initialisePlayer() {

    DefaultRenderersFactory rf = new DefaultRenderersFactory(Videoview.this)
          .setExtensionRendererMode(EXTENSION_RENDERER_MODE_PREFER).setMediaCodecSelector(
                    new MediaCodecSelector() {
                        @Override
                        public List<MediaCodecInfo> getDecoderInfos(String mimeType,
                                                boolean requiresSecureDecoder, boolean requiresTunnelingDecoder)
                                throws MediaCodecUtil.DecoderQueryException {
                            List<MediaCodecInfo> decoderInfos = MediaCodecSelector.DEFAULT
                             .getDecoderInfos(mimeType, requiresSecureDecoder, requiresTunnelingDecoder);
                            if (MimeTypes.VIDEO_H264.equals(mimeType)) {
                             // copy the list because MediaCodecSelector.DEFAULT returns an unmodifiable list
                                decoderInfos = new ArrayList<>(decoderInfos);
                                Collections.reverse(decoderInfos);
                            }
                            return decoderInfos;
                        }
                    });

    player = new ExoPlayer.Builder(Videoview.this,rf).build();

    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(Videoview.this);

    MediaSource   mediaSource = new ProgressiveMediaSource.Factory(
            new CacheDataSource.Factory()
                    .setCache(SimpleMediaPlayer.getInstance(Videoview.this))
                    .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory()
                            .setUserAgent(Videoview.this.getString(R.string.app_name)))
                    .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
    ).createMediaSource(MediaItem.fromUri(uri));

    exoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);

    player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
    player.seekTo(0);
    player.setRepeatMode(Player.REPEAT_MODE_ONE);
    player.setMediaSource(mediaSource);
    player.prepare();

    player.setPlayWhenReady(true);
    player.play();
    exoPlayerView.setPlayer(player);

}
Manli123 commented 1 year ago

why this issue has closed.I want solution sir. I found cause of issue in those days.I found that this rotation because of default renders factory.YOU can easily test on android 8.1 with any recorded video also i mentionedmy code above.first time it plays correctly.When you play it multiple time,you will get. please provide me solution.

marcbaechinger commented 1 year ago

The issue is not yet closed.

I have tested your stream that you sent me and it plays fine on Android 8.1 with API 27. I have applied your changes of the renderers factory to the demo app. The video is played multiple times in a loop that is implemented with our without recreating the player and with stopping and re-preparing. Whatever I do, I can not reproduce the problem I'm afraid. It plays in portrait mode as it should.

When I respond to your comments and ask questions, you don't seem to respond to my questions but instead send a new comment with code snippet and a new guess. You open multiple issues with the same code and the same issue. You use caps-lock. Shortly and with all my respect, the reports you are doing are not really encouraging to spend time with in technical as well as in psychological terms. That's the background in front of which you can think about how to file further issues and comments.

I created separate project and tried.

A separate project is a good approach. Please put the project into a Github repository so that the app can be installed easily and I can test with it.

Manli123 commented 1 year ago

First sorry for my this behaviour. Actually I was little bit panic so. But thanks for you are trying to solve my problem and you are trying your best. Here I am sharing separate project which I have created for testing purpose. Please Check this on Android 8.1 vivo 1811. I am sure You will easily find my issue with this zip file(android project). then can you provide me solution(Instant fix).

Project github code:

I request you please help me.please.I am badly stuck here. I hope you will help me.

Project Zip file:

here is output I have attached a screenshot.

Note--you need to check when app is in background then restart again.

Manli123 commented 1 year ago

Sir did you check this? Actually its urgent so I am asking. Hope you got issue and solution. Please.

Manli123 commented 1 year ago

Any update? please

Manli123 commented 1 year ago

any solution sir please?

Manli123 commented 1 year ago

did you get issue? sir please help.

Manli123 commented 1 year ago

Instead of spam comment you can reply na.did you check github project and played video in multiple time with close and start on android 8.1?

I am facing this issue then there is na.BUT how to fix this. Can you suggestion?

Manli123 commented 1 year ago

I am stuck here sir. This happens on vivo 1811 android 8.1.0 device. Video automatically plays sideways .Sometimes correct sometimes not. you can check when activity is pause means released player and then create again player in resume method and play and issue comes. and onVideoSizeChanged returns 0 even though video plays in sideways.no way to know when video plays in sideways even recorded in potrait so cant fix. This is separate project I have created. Please check please please

marcbaechinger commented 1 year ago

This is a device specific issue and I can't really help you with that I'm afraid. There may be workarounds that you can apply for that very device, but I can't tell you from the top of my head what to do. Besides not having such a device, I'd have to investigate and experiment myself for which I don't have time.

I'll leave this issue open for a while in case some else from the community has something to share.

Manli123 commented 1 year ago

yes thank you for considering my issue.I saw this on andrid 11 and 7 but only once and on vivo 1811 8.1 continuously. My manager is asking that other apps are playing videos correctly then why this not.I am blank at this point.

please try my project once(github link). how much time it will take to solve this issue from team? can you tell?

Manli123 commented 1 year ago

Can you tell temporary how i can fix this?..Because I did not find at which point video is playing wrongly because onVideoSize always returns 0 in unapplied rotation even if video is rotated wrongly. Please help.

Manli123 commented 1 year ago

Sometimes other devices are also facing same issue.Surely issue is in rendersFactory.

I observed that video rotate which has int32_t rotation degree=90 . Can you check once my code (github project above link) and rendersFactory code.Please sir my project is fully done bcoz of only this issue I can not submit.

please help me.

cahantar commented 8 months ago

Any solution? İ am facing the same problem?

tiagogbarbosa commented 2 months ago

same problem here, video wont rotate, all other views rotate correct