英文:
Android ExoPlayer 2 - How to improve fps when rendering many videos?
问题
我正在使用ExoPlayer 2在Android上创建一个应用程序,同时渲染和播放多个视频。然而,当显示的视频数量超过一定限制时(在我的小米Note 11 Pro上为3-4个视频),视频开始掉帧。我尝试限制播放器的最大比特率,但没有改变。
Player player = new ExoPlayer.Builder(context).build();
TrackSelectionParameters parameters = player.getTrackSelectionParameters();
TrackSelectionParameters newParameters = parameters.buildUpon().setMaxVideoBitrate(2000000).build(); // 2 Mbps
player.setTrackSelectionParameters(newParameters);
如何在应用程序渲染多个视频时提高帧率?
英文:
I'm using ExoPlayer 2 to create an app on Android that renders and plays multiple video simultaneously. However, when the number of videos displayed exceeds a certain limit (3-4 videos on my Xiaomi Note 11 Pro), the videos start to drop fps. I tried to limit the players' max bitrate but nothing changed.
Player player = new ExoPlayer.Builder(context).build();
TrackSelectionParameters parameters = player.getTrackSelectionParameters();
TrackSelectionParameters newParameters = parameters.buildUpon().setMaxVideoBitrate(2000000).build(); // 2 Mbps
player.setTrackSelectionParameters(newParameters);
How can I improve fps when app render many videos?
答案1
得分: 1
最终,我认为你只是在耗尽内存/处理能力,系统正在尝试通过丢弃帧来优雅地降级。
当你拥有多个视频时,你更有可能超出任何硬件编解码器的限制,并不得不退回到软件编解码器。
许多视频架构设计旨在在无法及时显示帧时通过丢弃帧来优雅地降级。
我不确定Android的最新状态如何,但在5或6年前,有一些很好的信息在这里:https://stackoverflow.com/a/26345345/334402
特别注意有关放弃那些不能按预期时间显示的帧的说明:
Android正在朝着音视频同步的解决方向前进,即应用程序告诉SurfaceFlinger它希望帧何时显示。如果SurfaceFlinger错过了截止日期,它就会丢弃该帧。
根本问题是需要显示的视频数量超出了设备可以舒适处理的范围,这是相当常见的,不仅限于Android。
一个可能的解决方法,可能不适用于你的情况,是在服务器端将视频合并为单一流,然后将该单一流发送到设备。你仍然可以通过在合并视频上添加触摸网格并在用户选择时为所选视频添加第二个流来允许用户展开或“移动到舞台”特定视频。
英文:
Ultimately, I think you are simply running out of memory/processing power and the system is trying to degrade gracefully by dropping frames.
When you have multiple videos also, you are more likely to go beyond the limits of any HW codecs and have to fall back onto SW codecs.
Many video architectures are designed to try to degrade gracefully by dropping frames if they cannot display them in time.
I'm not sure what the latest status with Android is but there is some excellent information here from 5 or 6 years ago: https://stackoverflow.com/a/26345345/334402
See in particular the note about the move towards dropping frames which would not be displayed at the time intended:
> The solution Android is moving toward for A/V sync is to have the app tell SurfaceFlinger when it wants the frame to be displayed. If SurfaceFlinger misses the deadline, it drops the frame.
The root issue, needing to display more videos than a device can handle comfortably, is quite common and not restricted to Android.
One possible workaround, which may not be applicable for your case, is to combine the videos into a single stream on the server side and then send that single stream to the device. You can still allow a user to expand or 'move to stage' a particular video by using a touch grid over the combined video and adding a second stream for the selected video if a user selects it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论