Baseflow / ExoPlayerXamarin

Xamarin bindings library for the Google ExoPlayer library
https://baseflow.com
MIT License
153 stars 66 forks source link

Video stutters with ExoPlayer but not with MediaPlayer #158

Closed timothyparez closed 1 year ago

timothyparez commented 1 year ago

Info

Platform: Android Framework: Xamarin.Android Version: 2.18.10-xamarin1 Android Version: Android 11 Android Target: Android 13

What

I am trying to play a few h264 encoded mp4 files with a resolution of 1920x1080. The SoC on which I am running this is capable of decoding h264/h265 streams at 4K with the hardware decoder.

Result

When the videos play they often jutter or stutter.
Playing the same videos on the same device in the same project but with the classic MediaPlayer instead does not have this issue.

Example


var exoPlayerView = FindViewById<StyledPlayerView>(Resource.Id.player_view_sample);

var exoplayer = new ExoPlayerBuilder(this).Build();                        
var mediaItem2 = MediaItem.FromUri(Android.Net.Uri.Parse("/mnt/sdcard/Movies/loop.mp4"));
var mediaItem3 = MediaItem.FromUri(Android.Net.Uri.Parse("/mnt/sdcard/Movies/loop2.mp4"));
var mediaItem4 = MediaItem.FromUri(Android.Net.Uri.Parse("/mnt/sdcard/Movies/cube.mp4"));

exoPlayerView.Player = exoplayer;                                     
exoPlayerView.UseController = false;
exoPlayerView.Player.RepeatMode = RepeatModeUtil.RepeatToggleModeAll;
exoPlayerView.Player.AddMediaItem(mediaItem4);
exoPlayerView.Player.AddMediaItem(mediaItem2);
exoPlayerView.Player.AddMediaItem(mediaItem3);            
exoPlayerView.Player.Prepare();
exoPlayerView.Player.PlayWhenReady = true;

Perhaps there is a way to increase the buffers etc, but it's hard to match the documentation on Google
with the implementation here.

Logs when it stutters:

[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/439 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/649 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/855 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/1070 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/1277 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/1487 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/1692 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 3)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/1900 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/2126 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/2334 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/2543 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/2752 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/2978 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/3205 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/3411 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/3615 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/3825 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/4034 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/4240 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/4448 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 1)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/4652 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/4863 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/5088 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/5295 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 1)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/5501 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 1)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/5711 (fetch/transfer)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/5935 (fetch/transfer)
[CCodecBuffers] [c2.android.aac.decoder#85:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
[BufferPoolAccessor2.0] bufferpool2 0xb400006ec6a56fb8 : 4(32768 size) total buffers - 4(32768 size) used buffers - 1/6 (recycle/alloc) - 5/6140 (fetch/transfer)

Is there anything I can try to resolve this?

timothyparez commented 1 year ago

A little more info: apparently it's caused by the audio.

ffmpeg -i loop2.mp4 -c:v copy -an loop3.mp4

ArchangelWTF commented 1 year ago

@timothyparez Would you have a sample of an AAC video file in question? It would seem weird that AAC would cause video to stutter, and I'd definitively need something to reproduce it on.

timothyparez commented 1 year ago

This video for example: https://1drv.ms/v/s!AmkewwA9r9K0gcAk5bXsm3fIdPqefQ?e=tn5eVo (Hopefully you can access it).

I've recently migrated to a Java implementation with ExoPlayer3 and found the same issue,
so there's probably not much that can be done about it.

It's most likely an issue specific to the SoC we are targetting,
it seems to be very good at playing 4K/H265 encoded video while having issues with 1080p/H264 encoded videos.

Makes me think this issue can simply be closed.

ArchangelWTF commented 1 year ago

Yeah I checked it as well, it seems that it's just an issue of the SoC you are targetting in particular, will close this one out!

mhdwaelanjo commented 1 year ago

We can use this library now Media3 ExoPlayer SDK for .NET for Android

` Anjo.Android.Media3.ExoPlayer (>= 1.1.1) Anjo.Android.Media3.Common (>= 1.1.1) Anjo.Android.Media3.Container (>= 1.1.1) Anjo.Android.Media3.Database (>= 1.1.1) Anjo.Android.Media3.DataSource (>= 1.1.1) Anjo.Android.Media3.Decoder (>= 1.1.1) Anjo.Android.Media3.Extractor (>= 1.1.1)

`