Recent

Author Topic: libmpv media player control  (Read 7054 times)

Espectr0

  • Full Member
  • ***
  • Posts: 221
libmpv media player control
« on: December 28, 2022, 03:06:07 pm »
Hola!

I just uploaded a new component to play multimedia files with libmpv in Lazarus.
I hope you find it of interest and perhaps together we can improve it.

Tested only in Windows 11 64bits, macOS Monterey and Linux Cinnamon Edition.

Regards!

https://github.com/URUWorks/UW_MPVPlayer
« Last Edit: January 01, 2024, 02:46:53 pm by Espectr0 »

domasz

  • Hero Member
  • *****
  • Posts: 536
Re: libmpv media player control
« Reply #1 on: December 28, 2022, 03:56:10 pm »
Is you LibMPV DLL compiled with --enable-lgpl?
https://github.com/mpv-player/mpv/blob/master/Copyright

GPL license is horrible so it would be better to have a LGPL DLL.


Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1239
Re: libmpv media player control
« Reply #2 on: December 28, 2022, 04:25:52 pm »
Hello
GPL license is horrible
Why ?
if you use the library only for personal use , there is no problem with this license.
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

domasz

  • Hero Member
  • *****
  • Posts: 536
Re: libmpv media player control
« Reply #3 on: December 28, 2022, 06:03:54 pm »
Because every code that touches that DLL automatically becomes GNU/GPL and if you want to give your app to anyone you have to give full source code of your app.

GNU/GPL is a dangerous virus which is great for corporations but makes small programmers poor.

Espectr0

  • Full Member
  • ***
  • Posts: 221
Re: libmpv media player control
« Reply #4 on: December 30, 2022, 02:48:39 pm »
@domasz

I did not compile the lib, I only uploaded it for testing.

Espectr0

  • Full Member
  • ***
  • Posts: 221
Re: libmpv media player control
« Reply #5 on: January 22, 2023, 10:44:07 pm »
some test with BGLcontrols

zbyna

  • Jr. Member
  • **
  • Posts: 63
Re: libmpv media player control
« Reply #6 on: December 30, 2023, 06:39:20 pm »
Hi,

I am testing this project now - demo included in the repository. I have encountered some strange behavior, at least for me  :) .

MPV starts with any video or audio file not embedded for the 1st time, but with some files started second time it stays embedded and keeps embedding for all other files until player restarted.

Spec of file which triggers embedding when play second time:
Code: Pascal  [Select][+][-]
  1. reading file
  2. File loaded
  3. Video Width: 500
  4. Video Height: 500
  5. Video Total Frames: 64065
  6. Video FPS: 1
  7. Buffering: 100%
  8.  
  9.  
  10. (ffmpeg/demuxer) warn: mov,mp4,m4a,3gp,3g2,mj2: stream 0, timescale not set
  11.  
  12. (cplayer) info:  (+) Video --vid=1 [P] (mjpeg 1.000fps)
  13.  
  14. (cplayer) info:  (+) Audio --aid=1 (*) (aac 2ch 22050Hz)
  15.  
  16. (display-tags) info: File tags:
  17.  
  18. (cplayer) info: Displaying cover art. Use --no-audio-display to prevent this.
  19.  
  20. (cplayer) info: VO: [gpu] 500x500 yuv420p
  21.  
  22. (cplayer) info: AO: [wasapi] 48000Hz stereo 2ch float

Specs of files which started not embedded until file above mentioned is played twice:


Code: Pascal  [Select][+][-]
  1. reading file
  2. File loaded
  3. Video Width: 1280
  4. Video Height: 720
  5. Video Total Frames: 112926
  6. Video FPS: 30
  7. Buffering: 100%
  8.  
  9. (cplayer) info:  (+) Video --vid=1 (*) (h264 1280x720 30.000fps)
  10.  
  11. (cplayer) info:  (+) Audio --aid=1 (*) (aac 2ch 44100Hz)
  12.  
  13. (cplayer) info: AO: [wasapi] 48000Hz stereo 2ch float
  14.  
  15. (cplayer) info: VO: [gpu] 1280x720 yuv420p



Code: Pascal  [Select][+][-]
  1. reading file
  2. File loaded
  3. Video Width: 270
  4. Video Height: 270
  5. Video Total Frames: 31758
  6. Video FPS: 1
  7. Buffering: 100%
  8.  
  9. (ffmpeg/demuxer) warn: mp3: Estimating duration from bitrate, this may be inaccurate
  10.  
  11. (cplayer) info:  (+) Video --vid=1 [P] (png 270x270 1.000fps)
  12.  
  13. (cplayer) info:  (+) Audio --aid=1 (mp3 2ch 44100Hz)
  14.  
  15. (display-tags) info: File tags:
  16.  
  17. (cplayer) info: Displaying cover art. Use --no-audio-display to prevent this.
  18.  
  19. (cplayer) info: VO: [gpu] 270x270 rgba
  20.  
  21. (cplayer) info: AO: [wasapi] 48000Hz stereo 2ch float


Thanks for any hint.

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: libmpv media player control
« Reply #7 on: December 30, 2023, 07:08:35 pm »
Hola!

I just uploaded a new component to play multimedia files with libmpv in Lazarus.
I hope you find it of interest and perhaps together we can improve it.

Tested only in my system with Windows 11 64bits.

Regards!

https://github.com/URUWorks/UWlibMPV

PS: The next step... integrate it with sdl2.
thanks, please put it on opm for easy installation

regards

domasz

  • Hero Member
  • *****
  • Posts: 536
Re: libmpv media player control
« Reply #8 on: December 30, 2023, 09:13:58 pm »
Installation is really easy.

zbyna

  • Jr. Member
  • **
  • Posts: 63
Re: libmpv media player control
« Reply #9 on: December 30, 2023, 09:53:27 pm »
Hi,

I am testing this project now - demo included in the repository. I have encountered some strange behavior, at least for me  :) .

MPV starts with any video or audio file not embedded for the 1st time, but with some files started second time it stays embedded and keeps embedding for all other files until player restarted.



Thanks for any hint.

It seems like the way:
https://github.com/mpv-player/mpv/issues/10189

Espectr0

  • Full Member
  • ***
  • Posts: 221
Re: libmpv media player control
« Reply #10 on: December 31, 2023, 12:44:20 am »
Hi,
I am testing this project now - demo included in the repository. I have encountered some strange behavior, at least for me  :) .
MPV starts with any video or audio file not embedded for the 1st time, but with some files started second time it stays embedded and keeps embedding for all other files until player restarted.

It never fail on my system, but I made some changes and added the conditional to treat the wid value as String.
If you can download and try again, maybe you can tell us if there was an improvement  :-\
« Last Edit: December 31, 2023, 09:58:56 am by Espectr0 »

zbyna

  • Jr. Member
  • **
  • Posts: 63
Re: libmpv media player control
« Reply #11 on: December 31, 2023, 06:00:48 pm »
Thanks for response!

Before I had realized your last post, I did some sort of debugging myself.

For cases not playing embedded the FRenderMode has rmOpenGL value at the begin of function TMPVPlayer.SetWID and at the beginning of function TMPVPlayer.Initialize which calls SetWID too.

Then I spotted this line in demo project from repository:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   if not mpv.IsLibMPVAvailable then
  4.     ShowMessage('Please install libmpv ;)');
  5.  
  6.   //mpv.RendererMode := rmEmbedding;
  7.   fnt := BGLFont('Arial', 20, CSSLightYellow, CSSBlack, [fsBold]);
  8. end;  
after uncommenting this every file is played as embedded so the issue disappeared  :) . But it seems that my environment causes unpredictable behaviour. I am using:

Code: Pascal  [Select][+][-]
  1. Lazarus 2.3.0 (rev main-2_3-2346-g0a34290) FPC 3.3.1 x86_64-win64-win32/win64
  2. Microsoft Windows 10 Pro 10.0.19045
  3. x64-based PC Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz
  4.  

EDIT: I enclose link to screencapture: https://youtu.be/DpbDn2peWCI


Code: Pascal  [Select][+][-]
  1. function TMPVPlayer.SetWID: Boolean;
  2. var
  3.   pHwnd: PtrInt;
  4. begin
  5.   if FRenderMode = rmEmbedding then
  6.   begin
  7.     Result := False;
  8.     if not Assigned(mpv_set_option) or not Assigned(FMPV_HANDLE) then Exit;
  9.  
  10.     {$IFDEF LINUX}
  11.     pHwnd := GDK_WINDOW_XWINDOW(PGtkWidget(Self.Handle)^.window);
  12.     {$ELSE}
  13.     pHwnd := Self.Handle;
  14.     {$ENDIF}
  15.     FError := mpv_set_option(FMPV_HANDLE^, 'wid', MPV_FORMAT_INT64, @pHwnd);
  16.     Result := FError = MPV_ERROR_SUCCESS;
  17.   end
  18.   else
  19.     Result := True;
  20. end;  

Code: Pascal  [Select][+][-]
  1. function TMPVPlayer.Initialize: Boolean;
  2. var
  3.   sl : TStringList;
  4.   i  : Integer;
  5. begin
  6.   if FInitialized then Exit;
  7.  
  8.   FInitialized := False;
  9.   Result := False;
  10.  
  11.   {$IFDEF WINDOWS}
  12.   if not IsLibMPV_Loaded then Exit;
  13.   {$ELSE}
  14.   FError := Load_libMPV(FMPVFileName);
  15.   if FError = MPV_ERROR_UNINITIALIZED then Exit;
  16.   {$ENDIF}
  17.  
  18.   FMPV_HANDLE := mpv_create();
  19.   if not Assigned(FMPV_HANDLE) then
  20.   begin
  21.     FError := MPV_ERROR_UNSUPPORTED;
  22.     Free_libMPV;
  23.     Exit;
  24.   end;
  25.  
  26.   // Get version lib
  27.   if Assigned(mpv_client_api_version) then
  28.     FVersion := mpv_client_api_version();
  29.  
  30.   sl := TStringList.Create;
  31.   try
  32.     sl.Assign(FStartOptions);
  33.  
  34.     if not FAutoStart then
  35.       sl.Add('pause'); // Start the player in paused state
  36.  
  37.     if not FAutoLoadSub then
  38.       sl.Add('sub=no'); // don't load subtitles
  39.  
  40.     if not FKeepAspect then
  41.       sl.Add('no-keepaspect'); // always stretch the video to window size
  42.  
  43.     for i := 0 to sl.Count-1 do
  44.       mpv_set_option_string_(sl[i]);
  45.   finally
  46.     sl.Free;
  47.   end;
  48.  
  49.   if not FYTDLPFileName.IsEmpty then
  50.     mpv_set_option_string(FMPV_HANDLE^, PChar('script-opts'), PChar('ytdl_hook-ytdl_path='+FYTDLPFileName));
  51.  
  52.   // Set our window handle
  53.   if not SetWID then
  54.   begin
  55.     UnInitialize;
  56.     Exit;
  57.   end;
  58.  
  59.   {$IFNDEF USETIMER}
  60.   mpv_observe_property(FMPV_HANDLE^, 0, 'playback-time', MPV_FORMAT_INT64);
  61.   {$ENDIF}
  62.   mpv_observe_property(FMPV_HANDLE^, 0, 'eof-reached', MPV_FORMAT_FLAG);
  63.   //mpv_observe_property(FMPV_HANDLE^, 0, 'paused-for-cache', MPV_FORMAT_INT64);
  64.   mpv_observe_property(FMPV_HANDLE^, 0, 'cache-buffering-state', MPV_FORMAT_INT64);
  65.  
  66.   FError := mpv_initialize(FMPV_HANDLE^);
  67.   if FError <> MPV_ERROR_SUCCESS then
  68.   begin
  69.     UnInitialize;
  70.     Exit;
  71.   end;
  72.  
  73.   FError := mpv_request_log_messages(FMPV_HANDLE^, PChar(LogLevelToString));
  74.  
  75.   // Node text overlay cfg
  76.   FText := '';
  77.   SetLength(FTextNodeKeys, 4);
  78.   SetLength(FTextNodeValues, 4);
  79.   FTextNodeKeys[0]             := 'name';
  80.   FTextNodeValues[0].format    := MPV_FORMAT_STRING;
  81.   FTextNodeValues[0].u._string := 'osd-overlay';
  82.   FTextNodeKeys[1]             := 'id';
  83.   FTextNodeValues[1].format    := MPV_FORMAT_INT64;
  84.   FTextNodeValues[1].u.int64_  := 1;
  85.   FTextNodeKeys[2]             := 'format';
  86.   FTextNodeValues[2].format    := MPV_FORMAT_STRING;
  87.   FTextNodeKeys[3]             := 'data';
  88.   FTextNodeValues[3].format    := MPV_FORMAT_STRING;
  89.   FTextNodeValues[3].u._string := NIL;
  90.   FTextNodeList.num            := 4;
  91.   FTextNodeList.keys           := @FTextNodeKeys[0];
  92.   FTextNodeList.values         := @FTextNodeValues[0];
  93.   FTextNode.format             := MPV_FORMAT_NODE_MAP;
  94.   FTextNode.u.list             := @FTextNodeList;
  95.  
  96.   FMPVEvent := TMPVPlayerThreadEvent.Create;
  97.   FMPVEvent.OnEvent := @ReceivedEvent;
  98.   mpv_set_wakeup_callback(FMPV_HANDLE^, @LIBMPV_EVENT, Self);
  99.  
  100.   if FRenderMode = rmOpenGL then
  101.     InitializeRenderGL
  102.   {$IFDEF SDL2}
  103.   else if FRenderMode = rmSDL2 then
  104.     InitializeRenderSDL
  105.   {$ENDIF};
  106.  
  107.   FInitialized := True;
  108.   Result := True;
  109. end;  

« Last Edit: January 01, 2024, 12:53:27 pm by zbyna »

Espectr0

  • Full Member
  • ***
  • Posts: 221
Re: libmpv media player control
« Reply #12 on: January 01, 2024, 12:31:52 pm »
@zbyna:

In what mode does it work for you, rmEmbedding, rmOpenGL or both?
Were you able to try it in rmEmbedding mode with the latest update?

zbyna

  • Jr. Member
  • **
  • Posts: 63
Re: libmpv media player control
« Reply #13 on: January 01, 2024, 01:17:42 pm »
Tested in demo application without any changing RenderMode property in code. This property is set only before recording video to rmOpenGL via Object Inspector gui. Strange behaviour seems to be triggered by closing not embedded videoplayer window.

When rmEmbedded is set, there are no problems at all.

I have not apply your latest changes yet. I am out of my computer today.

zbyna

  • Jr. Member
  • **
  • Posts: 63
Re: libmpv media player control
« Reply #14 on: January 02, 2024, 05:26:30 pm »
Here is video with testing after your changes:
https://youtu.be/dcEurLpuWV0

Testing began after windows restart.
As you can see:

1st launch after restart:
  - rmOpenGL does not work, every video is embedded
2nd and other launches
  - rmOpenGL works until m4b file is opened for the second time (no other testing file caused this)
  - rmEmbedding works well in my opinion

 

TinyPortal © 2005-2018