SuRGeoNix / Flyleaf

Media Player .NET Library for WinUI 3/ WPF/WinForms (based on FFmpeg/DirectX)
GNU Lesser General Public License v3.0
711 stars 98 forks source link

FlyleafHost not resize the form after Stop and Play again #377

Closed MinChanSike closed 9 months ago

MinChanSike commented 9 months ago

FlyleafHost is not align when I'm trying to play in second time after stop. ( Player.Stop(); , no Dispose) I'm using FlyleafLib.Controls.WinUI 1.0.18 in WinUI application. For your reference, if you get some time to check please see my sample repo here .

image

SuRGeoNix commented 9 months ago

Hi @MinChanSike,

I'm not sure what you mean, just tried your sample repo and can't see the issue. Do you mean it does not resize the form to fit to the video?

(By the way, if you want to open a new input there is not need to stop, player will do it automatically)

MinChanSike commented 9 months ago

Sorry to make you confuse, Yes you are correct, the issue is video does not resize the form to fit. It can be fit again if we resize the form, please see my screenshot below.

Thanks for information for player no need to stop to open new stream, the issue is because of playing after stop. I may need to use stop function as a usecase, the library have some function to invalidate/refresh video size after stop?

https://github.com/SuRGeoNix/Flyleaf/assets/2868221/c4d6c68f-003e-45b5-9bc0-2330bc4b9c50

SuRGeoNix commented 9 months ago

@MinChanSike Can you help me reproduce it? It seems that this issue it only happens with the rtsp protocols? How do you create the local rtsp so I can test it?

By the way the issue here is not the form resize. Is the FlyleafHost control resize. But I need to reproduce it to see what is wrong with WinUI FlyleafHost.

MinChanSike commented 9 months ago

@SuRGeoNix According by my testing, unfortunately the issue is happen on RTSP/RTMP/HLS/MPEG-DASH protocols. To create local rtsp/rtmp, I'm using WowzaStreamingEngine and pushing stream with ffmpeg.

ffmpeg.exe -re -stream_loop -1 -i sample.mp4 -c:v copy -c:a copy -f rtsp rtsp://127.0.0.1:1935/live/sample1
SuRGeoNix commented 9 months ago

@MinChanSike From your first screenshot, my understanding is that for WPF works fine? This sound for me more like an FFmpeg issue with the specify proto/format. I will give another try to reproduce it.

MinChanSike commented 9 months ago

yes, it is work fine on WPF FlyleafPlayer, only on WinUI got that issue.

SuRGeoNix commented 9 months ago

@MinChanSike I've used mediamtx and the same command as you suggest above to publish rtsp stream. I was not able to reproduce the issue. Can you provide the specified media file to test? (happens with all the files?)

MinChanSike commented 9 months ago

@SuRGeoNix Thanks for your time. You are testing with my sample repo? It is happens with all the files and rtsp url from camera. Btw, this is my OS information for your reference.

Edition Windows 11 Pro
Version 23H2
Experience Windows Feature Experience Pack 1000.22677.1000.0
SuRGeoNix commented 9 months ago

Yes I've used your repo. Can you provide the sample file that you use? I cannot reproduce it. Can you test it also with mediamtx?

MinChanSike commented 9 months ago

Yes, I also test with mediamtx and got same result. https://github.com/SuRGeoNix/Flyleaf/assets/2868221/997bf9ef-8535-4d70-bb6b-af808df21a6a

Please take a look my test video file from google drive lik. https://drive.google.com/file/d/13IP4iu2xom7nTRVQRYCLUohn6Qc4P5V-

This is my rtsp stream push command to mediamtx server.

ffmpeg.exe -re -stream_loop -1 -i sample_rb.mp4 -c:v copy -c:a copy -tune zerolatency -preset ultrafast -f rtsp rtsp://127.0.0.1:8554/live/sample1

Thank you @SuRGeoNix

SuRGeoNix commented 9 months ago

@MinChanSike I cannot reproduce it with Win10, I use latest MediaMTX v1.3.1 and tried different version of FFmpeg (4/5/6/master). So I suspect it's Win11 which causing this issue. I don't have a spare Win11 system for testing currently.

I think the easiest way for you to fix this issue is to use to resize the control back to the preferred width/height or possible use Player.renderer.ResizeBuffers (not sure when exactly but after that it changes your control's width/height).

MinChanSike commented 9 months ago

@SuRGeoNix Thanks for your time and effort. According by my testing, the issue is not because of source stream. Even MediaMTX v1.3.1 and camera direct rtsp url, still got same issue.

I think it is related with #328, after changing my Display Scaling in Window Settings 125% to 100%, does not see this issue. Also can resolve with Player.renderer.ResizeBuffers, but I may need to know previous FlyleafHost element size to correct back.

Edit: The issue was fixed for me with this code when stopping the player.

 Player.renderer.ResizeBuffers((int)flyleafHost.ActualWidth - 1, (int)flyleafHost.ActualHeight - 1);
 Player.Stop();
 Player.renderer.ResizeBuffers((int)flyleafHost.ActualWidth, (int)flyleafHost.ActualHeight);
SuRGeoNix commented 9 months ago

@MinChanSike Nice finding, doing the same in SwapChainClbk as the commit did in SCP_SizeChanged will fix the issue. I will review this a bit more and then I will have an update

Edit: The nuget is ready so you can re-test and confirm that fixes the issue

MinChanSike commented 9 months ago

It work perfectly after updated FlyleafLib.Controls.WinUI 1.0.19 Thank you @SuRGeoNix