cxfksword / MPVKit

mpv library for iOS, macOS, tvOS applications
GNU General Public License v3.0
71 stars 18 forks source link

AppleTV showing single images sometimes #20

Closed zmartell closed 5 months ago

zmartell commented 5 months ago

Hi there,

I am having an issue where the iOS Simulator is okay, but sometimes physically on the AppleTV ( 4K (2nd generation): May 21, 2021 if important. ) tvOS 16.x and 17.4. it gives a single solid color image that flashes different colors.

The audio keeps playing fine, but the video is flashing different solid colours taking up the entire screen.

If I use the OGL version, it always happens on HDR test video in the repo(but not limited to HDR), but in Metal it happens on any random videos, even sometimes if I even load images, so it doesnt seem related to any particular video content or codec.

If I play a video a few times, usually happens on the first attempt, or sometimes the 2nd or 3rd attempt, it will start to break. If I reopen the app, it is fine again for awhile.

Any ideas? It never has any problems in Simulator. What can I provide that would be helpful?

cxfksword commented 5 months ago

You can attempt to install and debug on AppleTV, then observe the mpv log output when this error occurs. Currently, Metal support only a patch version and does not officially support it yet. Therefore, encountering any issues is not strange.

zmartell commented 5 months ago

Hi @cxfksword I think I found something.. It always has window size 1x1 whenever it starts to mess up, and for all videos after. I think thats why I end up with audio and one single colours flashing on the screen. Sounds right if it somehow becomes 1x1, = 1 pixel.

I've also updated to your latest version today.

the specific lines:

[cplayer] v: VO: Description: Video output based on libplacebo [vo/gpu-next] v: reconfig to 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/display CL=mpeg2/4/h264 crop=1920x1080+0+0 [vo/gpu-next/libplacebo] debug: Requested alpha compositing mode: VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR [vo/gpu-next/libplacebo] debug: Requested surface transform: VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR [vo/gpu-next/libplacebo] debug: Requested image count: 4 (min 2 max 3) [vo/gpu-next/libplacebo] debug: Requested image size: 1x1 (min 1x1 < cur 1920x1080 < max 16384x16384) [vo/gpu-next/libplacebo] debug: (Re)creating swapchain of size 1x1 [mvk-info] Created 3 swapchain images with size (1, 1) and contents scale 1.0 in layer (null) (0x3033d3f30) on screen Main Screen. [vo/gpu-next] v: Window size: 1x1 (Borders: l=0 t=0 r=0 b=0) event: video-reconfig [vo/gpu-next] v: Video source: 1920x1080 (1:1) [vo/gpu-next] v: Video display: (0, 0) 1920x1080 -> (0, 0) 1x1

The whole log is attached. mpv.log

Hope theres something I can do. I've tried: checkError(mpv_set_option_string(mpv, "geometry", "1920x1080")) checkError(mpv_set_option_string(mpv, "autofit", "1920x1080"))

but they didnt seem to help. It says it forced, but still puts as 1x1 [vd] v: Decoder format: 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/auto CL=mpeg2/4/h264 crop=1920x1080+0+0 [vd] v: Forcing user-set aspect ratio. [vf] v: [in] 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/display CL=mpeg2/4/h264 crop=1920x1080+0+0 [vf] v: [userdeint] 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/display CL=mpeg2/4/h264 crop=1920x1080+0+0 [vf] v: [userdeint] (disabled) [vf] v: [autorotate] 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/display CL=mpeg2/4/h264 crop=1920x1080+0+0 [vf] v: [autorotate] (disabled) [vf] v: [convert] 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/display CL=mpeg2/4/h264 crop=1920x1080+0+0 event: video-reconfig [vf] v: [convert] (disabled) [vf] v: [out] 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/display CL=mpeg2/4/h264 crop=1920x1080+0+0 [vd] debug: Allocating new (host-cached) DR image... [cplayer] info: VO: [gpu-next] 1920x1080 yuv420p [cplayer] v: VO: Description: Video output based on libplacebo [vo/gpu-next] v: reconfig to 1920x1080 yuv420p bt.709/bt.709/bt.1886/limited/display CL=mpeg2/4/h264 crop=1920x1080+0+0 [vo/gpu-next/libplacebo] debug: Requested alpha compositing mode: VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR [vo/gpu-next/libplacebo] debug: Requested surface transform: VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR [vo/gpu-next/libplacebo] debug: Requested image count: 4 (min 2 max 3) [vo/gpu-next/libplacebo] debug: Requested image size: 1x1 (min 1x1 < cur 1920x1080 < max 16384x16384) [vo/gpu-next/libplacebo] debug: (Re)creating swapchain of size 1x1 [mvk-info] Created 3 swapchain images with size (1, 1) and contents scale 1.0 in layer (null) (0x300b13ea0) on screen Main Screen. [vo/gpu-next] v: Window size: 1x1 (Borders: l=0 t=0 r=0 b=0) event: video-reconfig [vo/gpu-next] v: Video source: 1920x1080 (1:1) [vo/gpu-next] v: Video display: (0, 0) 1920x1080 -> (0, 0) 1x1 [vo/gpu-next] v: Video scale: 0.000521/0.000926 [vo/gpu-next] v: OSD borders: l=0 t=0 r=0 b=0 [vo/gpu-next] v: Video borders: l=0 t=0 r=0 b=0

zmartell commented 5 months ago

I think im experiencing https://github.com/mpv-player/mpv/pull/13651

it sets the drawableSize to 1x1 to forcefully complete the presentation. though if 1x1 resolution frame is presented it causes a visual flicker or rather a solid coloured frame. it causes even more problems since sometimes it does not reset the drawableSize to the proper resolution and keeps rendering everything in 1x1.

Im confused though because it closes the ticket, and it's in the 0.38.0 changelog, mac/vulkan: add support for frame timing via presentation feedback, or is it just fixed on Mac and not tvOS branch?

cxfksword commented 5 months ago

The mpv repository only supports Metal on the Mac mpv app now, not the libmpv library. You can try override the drawableSize of CAMetalLayer like https://github.com/mpv-player/mpv/pull/13651 to see if it can solve the problem. otherwise, you have to wait for MoltenVK to improve this issue or wait for libmpv support Metal officially.

Can you upload a screenshot when this problem occurred? It seems I have never experienced this issue.

zmartell commented 5 months ago

Hi @cxfksword it seems to only affect on actual AppleTV's. Simulator is always OK.

It happen

https://github.com/cxfksword/MPVKit/assets/1806454/6a1c41a7-76f8-4db0-954a-10176a9b8181

s always when I go from image -> image by using command("skip") a bunch, or video -> video of different res -> video -> video of different res. If I stay in the same resolution video it doesn't seem to happen as easily. I can give you some test repo and files? Would that help?

If the mpv log shows 0x0 it seems OK likely do that min max thing, because it just forces it to my 1920x1080 but when it does 1x1 it does not, and all future ones are broken like that. I tried listening to weight and height observing, but that didnt seem to help as it would return video resolution.

Would you be able to give me some guidance of overriding the drawableSize? Should I be cloning that repo (with that hotfix), building it and replacing the MoltenVK.xcframework in the MPVKit?

I have attached a four second video I took yesterday when experiencing it.

cxfksword commented 5 months ago

you can refer to demo commit https://github.com/cxfksword/MPVKit/commit/53687a81b3787dbbf19fa89bb4c92088b7eb6586

zmartell commented 5 months ago

Hi @cxfksword wow, much smarter solution than I thought.

THANK YOUU!!! Xie Xie!

So far in initial testing just now, I cant reproduce It anymore. the logs all show either 0x0 or 1920x1080, no more mention of 1x1.

[vo/gpu-next/libplacebo] debug: Requested image size: 0x0 (min 1x1 < cur 1920x1080 < max 16384x16384) [vo/gpu-next/libplacebo] debug: Requested image size: 1920x1080 (min 1x1 < cur 1920x1080 < max 16384x16384) [vo/gpu-next/libplacebo] debug: Requested image size: 1920x1080 (min 1x1 < cur 1920x1080 < max 16384x16384) [vo/gpu-next/libplacebo] debug: Requested image size: 1920x1080 (min 1x1 < cur 1920x1080 < max 16384x16384) ....