Page 1 of 2

libmpv

Posted: Thu Dec 07, 2023 12:53 am
by wbtcpip
Hi all,
i'm new to purebasic and i would use libmpv. i'm currently using libmpv in another language (very similar to vb). I saw there is a wrapper for libvlc. libmpv is a similar c library but much more simple to wrap.
Can someone of you trasnlate this vb libmpv include to purebasic?

Code: Select all

Global Enum MPV_ERROR_SUCCESS= 0, MPV_ERROR_EVENT_QUEUE_FULL= -1, _
  MPV_ERROR_NOMEM = -2, MPV_ERROR_UNINITIALIZED= -3, MPV_ERROR_INVALID_PARAMETER = -4, _
  MPV_ERROR_OPTION_NOT_FOUND = -5, MPV_ERROR_OPTION_FORMAT= -6, _
  MPV_ERROR_OPTION_ERROR = -7, MPV_ERROR_PROPERTY_NOT_FOUND = -8, _
  MPV_ERROR_PROPERTY_FORMAT = -9, MPV_ERROR_PROPERTY_UNAVAILABLE = -10, _
  MPV_ERROR_PROPERTY_ERROR = -11, MPV_ERROR_COMMAND = -12, _
  MPV_ERROR_LOADING_FAILED = -13, MPV_ERROR_AO_INIT_FAILED = -14, _
  MPV_ERROR_VO_INIT_FAILED = -15, MPV_ERROR_NOTHING_TO_PLAY = -16, _
  MPV_ERROR_UNKNOWN_FORMAT = -17, MPV_ERROR_UNSUPPORTED = -18, _
  MPV_ERROR_NOT_IMPLEMENTED = -19, MPV_ERROR_GENERIC = -20

Global Enum MPV_FORMAT_NONE = 0, MPV_FORMAT_STRING, MPV_FORMAT_OSD_STRING, _
  MPV_FORMAT_FLAG, MPV_FORMAT_INT64, MPV_FORMAT_DOUBLE, MPV_FORMAT_NODE, _
  MPV_FORMAT_NODE_ARRAY, MPV_FORMAT_NODE_MAP, MPV_FORMAT_BYTE_ARRAY

Global Enum MPV_EVENT_NONE= 0, MPV_EVENT_SHUTDOWN, MPV_EVENT_LOG_MESSAGE, _
  MPV_EVENT_GET_PROPERTY_REPLY,  MPV_EVENT_SET_PROPERTY_REPLY, _
  MPV_EVENT_COMMAND_REPLY, MPV_EVENT_START_FILE, MPV_EVENT_END_FILE, _
  MPV_EVENT_FILE_LOADED, MPV_EVENT_IDLE = 11, MPV_EVENT_TICK= 14, _
  MPV_EVENT_CLIENT_MESSAGE = 16, MPV_EVENT_VIDEO_RECONFIG, _
  MPV_EVENT_AUDIO_RECONFIG, MPV_EVENT_SEEK = 20, MPV_EVENT_PLAYBACK_RESTART, _
  MPV_EVENT_PROPERTY_CHANGE, MPV_EVENT_QUEUE_OVERFLOW = 24, _
  MPV_EVENT_HOOK

Global Enum MPV_LOG_LEVEL_NONE  = 0, _
  MPV_LOG_LEVEL_FATAL = 10, '  /// "fatal" - critical/aborting errors _
  MPV_LOG_LEVEL_ERROR = 20, '  /// "error" - simple errors _
  MPV_LOG_LEVEL_WARN = 30, '   /// "warn"  - possible problems _
  MPV_LOG_LEVEL_INFO = 40, '  /// "info"  - informational message _
  MPV_LOG_LEVEL_V = 50, '   /// "v"     - noisy informational message _
  MPV_LOG_LEVEL_DEBUG = 60, '  /// "debug" - very noisy technical information _
  MPV_LOG_LEVEL_TRACE = 70 ',   /// "trace" - extremely noisy

Global Enum MPV_END_FILE_REASON_EOF = 0, MPV_END_FILE_REASON_STOP = 2, MPV_END_FILE_REASON_QUIT = 3, _
  MPV_END_FILE_REASON_ERROR = 4, MPV_END_FILE_REASON_REDIRECT = 5

Type mpv_event_end_file
  reason As Long
  errore As Int
  playlist_entry_id As Large
  playlist_insert_id As Large
  playlist_insert_num_entries As Int
EndType

Type mpv_event_log_message
  prefix As Long
  level As Long
  txt As Long
  log_level As Long
EndType

Type mpv_event
  event_id As Int
  errore As Int
  reply_userdata As Large
  dati As Long
EndType

Type mpv_event_property
  nome As Long
  mpv_format As Int
  dati As Long
EndType


Declare LIB "libmpv-2.dll"
Declare Function mpv_client_api_version CDecl () As Int
Declare Function mpv_error_string CDecl (ByVal myerror As Int) As String
Declare Sub mpv_free CDecl (ByVal p_instance As Int)
Declare Function mpv_client_name CDecl (ByVal mpv_handle As Int) As String
Declare Function mpv_client_id CDecl (ByVal mpv_handle As Int) As Large
Declare Function mpv_create CDecl () As Int
Declare Function mpv_initialize CDecl (ByVal mpv_handle As Int) As Int
Declare Sub mpv_destroy CDecl (ByVal mpv_handle As Int)
Declare Sub mpv_terminate_destroy CDecl (ByVal mpv_handle As Int)
Declare Function mpv_create_client CDecl (ByVal mpv_handle As Int, ByVal cname As String) As Int
Declare Function mpv_set_option_string CDecl (ByVal mpv_handle As Int, ByVal name As String, ByVal mpv_data As String) As Int
Declare Function mpv_set_property CDecl (ByVal mpv_handle As Int, ByVal name As String, ByVal mpv_format As Int, ByVal mpv_data As Int) As Int
Declare Function mpv_set_property_string CDecl (ByVal mpv_handle As Int, ByVal name As String, ByVal mpv_data As String) As Int
Declare Function mpv_get_property CDecl (ByVal mpv_handle As Int, ByVal name As String, ByVal mpv_format As Int, ByVal mpv_data As Int) As Int
Declare Function mpv_get_property_string CDecl (ByVal mpv_handle As Int, ByVal name As String, ByVal mpv_data As String) As String
Declare Function mpv_command CDecl (ByVal mpv_handle As Int, ByVal args As Int) As Int
Declare Sub mpv_set_wakeup_callback CDecl (ByVal mpv_handle As Int, ByVal cb As Int, ByVal data As Int)
Declare Function mpv_wait_event CDecl (ByVal mpv_handle As Int, ByVal timeout As Double) As Int
Declare Function mpv_event_name CDecl (ByVal mpv_event_id As Int) As String
Declare Function mpv_observe_property CDecl (ByVal mpv_handle As Int, ByVal reply_userdata As Large, ByVal name As String, ByVal mpv_format As Int) As Int
Declare Function mpv_unobserve_property CDecl (ByVal mpv_handle As Int, ByVal registered_reply_userdata As Large) As Int
Declare Function mpv_request_log_messages CDecl (ByVal mpv_handle As Int, ByVal min_level As String) As Int

Re: libmpv

Posted: Thu Dec 07, 2023 6:08 am
by idle
welcome to purebasic you can try this

Code: Select all

#MPV_ERROR_SUCCESS= 0
#MPV_ERROR_EVENT_QUEUE_FULL= -1
#MPV_ERROR_NOMEM = -2
#MPV_ERROR_UNINITIALIZED= -3 
#MPV_ERROR_INVALID_PARAMETER = -4
#MPV_ERROR_OPTION_NOT_FOUND = -5
#MPV_ERROR_OPTION_FORMAT= -6
#MPV_ERROR_OPTION_ERROR = -7
#MPV_ERROR_PROPERTY_NOT_FOUND = -8
#MPV_ERROR_PROPERTY_FORMAT = -9
#MPV_ERROR_PROPERTY_UNAVAILABLE = -10
#MPV_ERROR_PROPERTY_ERROR = -11
#MPV_ERROR_COMMAND = -12
#MPV_ERROR_LOADING_FAILED = -13
#MPV_ERROR_AO_INIT_FAILED = -14
#MPV_ERROR_VO_INIT_FAILED = -15
#MPV_ERROR_NOTHING_TO_PLAY = -16
#MPV_ERROR_UNKNOWN_FORMAT = -17
#MPV_ERROR_UNSUPPORTED = -18
#MPV_ERROR_NOT_IMPLEMENTED = -19
#MPV_ERROR_GENERIC = -20

Enumeration 
  #MPV_FORMAT_NONE
  #MPV_FORMAT_STRING
  #MPV_FORMAT_OSD_STRING
  #MPV_FORMAT_FLAG
  #MPV_FORMAT_INT64
  #MPV_FORMAT_DOUBLE
  #MPV_FORMAT_NODE
  #MPV_FORMAT_NODE_ARRAY
  #MPV_FORMAT_NODE_MAP
  #MPV_FORMAT_BYTE_ARRAY
EndEnumeration 

Enumeration 
  #MPV_EVENT_NONE
  #MPV_EVENT_SHUTDOWN
  #MPV_EVENT_LOG_MESSAGE
  #MPV_EVENT_GET_PROPERTY_REPLY
  #MPV_EVENT_SET_PROPERTY_REPLY
  #MPV_EVENT_COMMAND_REPLY
  #MPV_EVENT_START_FILE
  #MPV_EVENT_END_FILE
  #MPV_EVENT_FILE_LOADED
  #MPV_EVENT_IDLE = 11
  #MPV_EVENT_TICK= 14
  #MPV_EVENT_CLIENT_MESSAGE = 16
  #MPV_EVENT_VIDEO_RECONFIG
  #MPV_EVENT_AUDIO_RECONFIG
  #MPV_EVENT_SEEK = 20
  #MPV_EVENT_PLAYBACK_RESTART
  #MPV_EVENT_PROPERTY_CHANGE
  #MPV_EVENT_QUEUE_OVERFLOW = 24
  #MPV_EVENT_HOOK
EndEnumeration

#MPV_LOG_LEVEL_NONE  = 0
#MPV_LOG_LEVEL_FATAL = 10;, '  /// "fatal" - critical/aborting errors _
#MPV_LOG_LEVEL_ERROR = 20;, '  /// "error" - simple errors _
#MPV_LOG_LEVEL_WARN = 30 ;, '   /// "warn"  - possible problems _
#MPV_LOG_LEVEL_INFO = 40 ;, '  /// "info"  - informational message _
#MPV_LOG_LEVEL_V = 50    ;, '   /// "v"     - noisy informational message _
#MPV_LOG_LEVEL_DEBUG = 60;, '  /// "debug" - very noisy technical information _
#MPV_LOG_LEVEL_TRACE = 70; ',   /// "trace" - extremely noisy


#MPV_END_FILE_REASON_EOF = 0
#MPV_END_FILE_REASON_STOP = 2
#MPV_END_FILE_REASON_QUIT = 3
#MPV_END_FILE_REASON_ERROR = 4
#MPV_END_FILE_REASON_REDIRECT = 5

Structure mpv_event_end_file Align 8
  reason.i 
  error.l 
  playlist_entry_id.i 
  playlist_insert_id.i
  playlist_insert_num_entries.l
EndStructure 

Structure mpv_event_log_message Align 8
  *prefix; string utf8 
  *level ; string utf8 
  *txt   ; string p-utf8 
  log_level.i
EndStructure 

Structure mpv_event Align 8
  event_id.i
  error.i
  reply_userdata.q
  *data
EndStructure 

Structure mpv_event_property Align 8
  *name
  mpv_format.i
  *data
EndStructure 

;open cmd line navivate to pb compiler folder and type 
;polib c:\where_it_is\libmpv-2.dll

ImportC "libmpv-2.2.lib" 
  mpv_client_api_version() 
  mpv_error_string(myerror) ;peeks on return 
  mpv_free(pinstance)
  mpv_client_name(mpv_handle) ;As String
  mpv_client_id(mpv_handle)   ;As Large 
  mpv_create() 
  mpv_initialize(mpv_handle)
  mpv_destroy(mpv_handle)
  mpv_terminate_destroy(mpv_handle)
  mpv_create_client(mpv_handle,*cname.p-utf8)
  mpv_set_option_string(mpv_handle,*name.p-utf8,*mpv_data.p-utf8)
  mpv_set_property(mpv_handle,*name.p-utf8,mpv_format,*mpv_data)
  mpv_set_property_string(mpv_handle,*name.p-utf8,*mpv_data.p-utf8)
  mpv_get_property(mpv_handle,*name.p-utf8,mpv_format,*mpv_data) 
  mpv_get_property_string(mpv_handle,*name.p-utf8,*mpv_data.p-utf8) ;peeks 
  mpv_command(mpv_handle,args)
  mpv_set_wakeup_callback(mpv_handle,*cb,*data)
  mpv_wait_event(mpv_handle, timeout.d)
  mpv_event_name(mpv_event_id) ;peeks 
  mpv_observe_property(mpv_handle,reply_userdata.q,*name.p-utf8,mpv_format)
  mpv_unobserve_property(mpv_handle,registered_reply_userdata.q)
  mpv_request_log_messages(mpv_handle,*min_level.p-utf8)
EndImport    


Re: libmpv

Posted: Thu Dec 07, 2023 1:38 pm
by wbtcpip
thank you very much..i will try

Re: libmpv

Posted: Fri Dec 08, 2023 2:28 pm
by dige
Where can I download the lib and the dll for Windows?

Re: libmpv

Posted: Fri Dec 08, 2023 6:33 pm
by idle
It's on github but you need to build it with mingw

Re: libmpv

Posted: Sun Dec 10, 2023 12:17 am
by wbtcpip
here https://github.com/shinchiro/mpv-winbui ... e/releases you will find the releases.

download mpv-dev- ... package. inside you will find libmpv-2.dll and the documentation

Re: libmpv

Posted: Mon Dec 11, 2023 9:48 am
by dige
@wbtcpip @idle: thank you!

I also overlooked the fact that I have to create the lib myself.

@wbtcpip: Have you already been able to create something executable with purebasic and mpv and would you like to make it available here?

Re: libmpv

Posted: Mon Dec 11, 2023 6:38 pm
by idle
dige wrote: Mon Dec 11, 2023 9:48 am @wbtcpip @idle: thank you!

I also overlooked the fact that I have to create the lib myself.

@wbtcpip: Have you already been able to create something executable with purebasic and mpv and would you like to make it available here?
maybe I should have said how to make the lib in the post rather than the code

Re: libmpv

Posted: Sun Dec 17, 2023 9:48 am
by dige
Does it seem that mpv is not so easy to implement? I prefer to use the MediaPlayer variant...

Re: libmpv

Posted: Sun Dec 17, 2023 7:06 pm
by infratec
Since I was not able to get the import to work, I rewrote the whole stuff.

Save it as libmpv.pbi:

Code: Select all

;
; https://github.com/shinchiro/mpv-winbuild-cmake/releases
;
; 
; tested with the dll from:
; mpv-dev-i686-20231215-git-e9d0a31.7z
; mpv-dev-x86_64-20231215-git-e9d0a31.7z
;

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
CompilerEndIf

#MPV_ERROR_SUCCESS              =  0
#MPV_ERROR_EVENT_QUEUE_FULL     = -1
#MPV_ERROR_NOMEM                = -2
#MPV_ERROR_UNINITIALIZED        = -3
#MPV_ERROR_INVALID_PARAMETER    = -4
#MPV_ERROR_OPTION_NOT_FOUND     = -5
#MPV_ERROR_OPTION_FORMAT        = -6
#MPV_ERROR_OPTION_ERROR         = -7
#MPV_ERROR_PROPERTY_NOT_FOUND   = -8
#MPV_ERROR_PROPERTY_FORMAT      = -9
#MPV_ERROR_PROPERTY_UNAVAILABLE = -10
#MPV_ERROR_PROPERTY_ERROR       = -11
#MPV_ERROR_COMMAND              = -12
#MPV_ERROR_LOADING_FAILED       = -13
#MPV_ERROR_AO_INIT_FAILED       = -14
#MPV_ERROR_VO_INIT_FAILED       = -15
#MPV_ERROR_NOTHING_TO_PLAY      = -16
#MPV_ERROR_UNKNOWN_FORMAT       = -17
#MPV_ERROR_UNSUPPORTED          = -18
#MPV_ERROR_NOT_IMPLEMENTED      = -19
#MPV_ERROR_GENERIC              = -20

Enumeration
  #MPV_FORMAT_NONE
  #MPV_FORMAT_STRING
  #MPV_FORMAT_OSD_STRING
  #MPV_FORMAT_FLAG
  #MPV_FORMAT_INT64
  #MPV_FORMAT_DOUBLE
  #MPV_FORMAT_NODE
  #MPV_FORMAT_NODE_ARRAY
  #MPV_FORMAT_NODE_MAP
  #MPV_FORMAT_BYTE_ARRAY
EndEnumeration 

Enumeration 
  #MPV_EVENT_NONE
  #MPV_EVENT_SHUTDOWN
  #MPV_EVENT_LOG_MESSAGE
  #MPV_EVENT_GET_PROPERTY_REPLY
  #MPV_EVENT_SET_PROPERTY_REPLY
  #MPV_EVENT_COMMAND_REPLY
  #MPV_EVENT_START_FILE
  #MPV_EVENT_END_FILE
  #MPV_EVENT_FILE_LOADED
  #MPV_EVENT_IDLE               = 11
  #MPV_EVENT_TICK               = 14
  #MPV_EVENT_CLIENT_MESSAGE     = 16
  #MPV_EVENT_VIDEO_RECONFIG
  #MPV_EVENT_AUDIO_RECONFIG
  #MPV_EVENT_SEEK               = 20
  #MPV_EVENT_PLAYBACK_RESTART
  #MPV_EVENT_PROPERTY_CHANGE
  #MPV_EVENT_QUEUE_OVERFLOW     = 24
  #MPV_EVENT_HOOK
EndEnumeration

#MPV_LOG_LEVEL_NONE  =  0
#MPV_LOG_LEVEL_FATAL = 10 ; "fatal" - critical/aborting errors _
#MPV_LOG_LEVEL_ERROR = 20 ; "error" - simple errors _
#MPV_LOG_LEVEL_WARN  = 30 ; "warn"  - possible problems _
#MPV_LOG_LEVEL_INFO  = 40 ; "info"  - informational message _
#MPV_LOG_LEVEL_V     = 50 ; "v"     - noisy informational message _
#MPV_LOG_LEVEL_DEBUG = 60 ; "debug" - very noisy technical information _
#MPV_LOG_LEVEL_TRACE = 70 ; "trace" - extremely noisy

#MPV_END_FILE_REASON_EOF      = 0
#MPV_END_FILE_REASON_STOP     = 2
#MPV_END_FILE_REASON_QUIT     = 3
#MPV_END_FILE_REASON_ERROR    = 4
#MPV_END_FILE_REASON_REDIRECT = 5


Structure mpv_event_start_file Align #PB_Structure_AlignC
  playlist_entry_id.q
EndStructure

Structure mpv_event_end_file Align #PB_Structure_AlignC
  reason.i 
  error.l 
  playlist_entry_id.q 
  playlist_insert_id.q
  playlist_insert_num_entries.l
EndStructure 

Structure mpv_event_log_message Align #PB_Structure_AlignC
  *prefix; string utf8 
  *level ; string utf8 
  *txt   ; string p-utf8 
  log_level.i
EndStructure 

Structure mpv_event Align #PB_Structure_AlignC
  event_id.i
  error.i
  reply_userdata.q
  *data
EndStructure

Structure mpv_event_property Align #PB_Structure_AlignC
  *name
  mpv_format.i
  *data
EndStructure

Structure mpv_node_list Align #PB_Structure_AlignC
  num.l
  *values
  *keys
EndStructure

Structure mpv_byte_array Align #PB_Structure_AlignC
  *data
  size.i
EndStructure

Structure mpv_node Align #PB_Structure_AlignC
  StructureUnion
    *string
    flag.i
    int64.q
    double_.d
    *list.mpv_node_list
    *ba.mpv_byte_array
  EndStructureUnion
  format.l
EndStructure


PrototypeC Prototype_mpv_cb(*d)

PrototypeC.l Prototype_mpv_client_api_version()
PrototypeC.i Prototype_mpv_error_string(error.l)
PrototypeC Prototype_mpv_free(*Data)
PrototypeC.i Prototype_mpv_client_name(*ctx)
PrototypeC.q Prototype_mpv_client_id(*ctx)
PrototypeC.i Prototype_mpv_create()
PrototypeC.l Prototype_mpv_initialize(*ctx)
PrototypeC Prototype_mpv_destroy(*ctx)
PrototypeC Prototype_mpv_terminate_destroy(*ctx)
PrototypeC.i Prototype_mpv_create_client(*ctx, name.p-utf8)
PrototypeC.i Prototype_mpv_create_weak_client(*ctx, name.p-utf8)
PrototypeC.l Prototype_mpv_load_config_file(*ctx, filename.p-utf8)
PrototypeC.q Prototype_mpv_get_time_ns(*ctx)
PrototypeC.q Prototype_mpv_get_time_us(*ctx)
PrototypeC Prototype_mpv_free_node_contents(*node.mpv_node)
PrototypeC.l Prototype_mpv_set_option(*ctx, name.p-utf8, format.i, *Data)
PrototypeC.l Prototype_mpv_set_option_string(*ctx, name.p-utf8, *Data)
PrototypeC.l Prototype_mpv_set_option_string_str(*ctx, name.p-utf8, string.p-utf8)
PrototypeC.l Prototype_mpv_command(*ctx, *args)
PrototypeC.l Prototype_mpv_command_node(*ctx, *args.mpv_node, *result.mpv_node)
PrototypeC.l Prototype_mpv_command_ret(*ctx, *args, *result.mpv_node)
PrototypeC.l Prototype_mpv_command_string(*ctx, *args)
PrototypeC.l Prototype_mpv_command_async(*ctx, reply_userdata.q, *args)
PrototypeC.l Prototype_mpv_command_node_async(*ctx, reply_userdata.q, *args.mpv_node)
PrototypeC Prototype_mpv_abort_async_command(*ctx, reply_userdata.q)
PrototypeC.l Prototype_mpv_set_property(*ctx, name.p-utf8, format.i, *Data)
PrototypeC.l Prototype_mpv_set_property_string(*ctx, name.p-utf8, *Data)
PrototypeC.l Prototype_mpv_del_property(*ctx, name.p-utf8)
PrototypeC.l Prototype_mpv_set_property_async(*ctx, reply_userdata.q, name.p-utf8, format.i, *Data)
PrototypeC.l Prototype_mpv_get_property(*ctx, name.p-utf8, format.i, *Data)
PrototypeC.i Prototype_mpv_get_property_string_(*ctx, name.p-utf8)
PrototypeC.i Prototype_mpv_get_property_osd_string_(*ctx, name.p-utf8)
PrototypeC.l Prototype_mpv_get_property_async(*ctx, reply_userdata.q, name.p-utf8, format.i)
PrototypeC.l Prototype_mpv_observe_property(*mpv, reply_userdata.q, name.p-utf8, format.i)
PrototypeC.l Prototype_mpv_unobserve_property(*mpv, registered_reply_userdata.q)
PrototypeC.i Prototype_mpv_event_name_(event.i)
PrototypeC.l Prototype_mpv_event_to_node(*dst.mpv_node, *src)
PrototypeC.l Prototype_mpv_request_event(*ctx, event.i, enable.l)
PrototypeC.l Prototype_mpv_request_log_messages(*ctx, min_level.p-utf8)
PrototypeC.i Prototype_mpv_wait_event(*ctx, timeout.d)
PrototypeC Prototype_mpv_wakeup(*ctx)
PrototypeC Prototype_mpv_set_wakeup_callback(*ctx, *cb.Prototype_mpv_cb, *d)
PrototypeC Prototype_mpv_wait_async_requests(*ctx)
PrototypeC.l Prototype_mpv_hook_add(*ctx, reply_userdata.q, name.p-utf8, priority.l)
PrototypeC.l Prototype_mpv_hook_continue(*ctx, id.q)
PrototypeC.l Prototype_mpv_get_wakeup_pipe(*ctx)


Global libmpv.i
Global mpv_client_api_version.Prototype_mpv_client_api_version
Global mpv_error_string_.Prototype_mpv_error_string
Global mpv_free.Prototype_mpv_free
Global mpv_client_name_.Prototype_mpv_client_name
Global mpv_client_id.Prototype_mpv_client_id
Global mpv_create.Prototype_mpv_create
Global mpv_initialize.Prototype_mpv_initialize
Global mpv_destroy.Prototype_mpv_destroy
Global mpv_terminate_destroy.Prototype_mpv_terminate_destroy
Global mpv_create_client.Prototype_mpv_create_client
Global mpv_create_weak_client.Prototype_mpv_create_weak_client
Global mpv_load_config_file.Prototype_mpv_load_config_file
Global mpv_get_time_ns.Prototype_mpv_get_time_ns
Global mpv_get_time_us.Prototype_mpv_get_time_us
Global mpv_free_node_contents.Prototype_mpv_free_node_contents
Global mpv_set_option.Prototype_mpv_set_option
Global mpv_set_option_string.Prototype_mpv_set_option_string
Global mpv_set_option_string_str.Prototype_mpv_set_option_string_str
Global mpv_command.Prototype_mpv_command
Global mpv_command_node.Prototype_mpv_command_node
Global mpv_command_ret.Prototype_mpv_command_ret
Global mpv_command_string.Prototype_mpv_command_string
Global mpv_command_async.Prototype_mpv_command_async
Global mpv_command_node_async.Prototype_mpv_command_node_async
Global mpv_abort_async_command.Prototype_mpv_abort_async_command
Global mpv_set_property.Prototype_mpv_set_property
Global mpv_set_property_string.Prototype_mpv_set_property_string
Global mpv_del_property.Prototype_mpv_del_property
Global mpv_set_property_async.Prototype_mpv_set_property_async
Global mpv_get_property.Prototype_mpv_get_property
Global mpv_get_property_string_.Prototype_mpv_get_property_string_
Global mpv_get_property_osd_string_.Prototype_mpv_get_property_osd_string_
Global mpv_get_property_async.Prototype_mpv_get_property_async
Global mpv_observe_property.Prototype_mpv_observe_property
Global mpv_unobserve_property.Prototype_mpv_unobserve_property
Global mpv_event_name_.Prototype_mpv_event_name_
Global mpv_event_to_node.Prototype_mpv_event_to_node
Global mpv_request_event.Prototype_mpv_request_event
Global mpv_request_log_messages.Prototype_mpv_request_log_messages
Global mpv_wait_event.Prototype_mpv_wait_event
Global mpv_wakeup.Prototype_mpv_wakeup
Global mpv_set_wakeup_callback.Prototype_mpv_set_wakeup_callback
Global mpv_wait_async_requests.Prototype_mpv_wait_async_requests
Global mpv_hook_add.Prototype_mpv_hook_add
Global mpv_hook_continue.Prototype_mpv_hook_continue
Global mpv_get_wakeup_pipe.Prototype_mpv_get_wakeup_pipe


If Not libmpv
  libmpv = OpenLibrary(#PB_Any, "libmpv-2.dll")
  If libmpv
    mpv_client_api_version = GetFunction(libmpv, "mpv_client_api_version")
    mpv_error_string_ = GetFunction(libmpv, "mpv_error_string")
    mpv_free = GetFunction(libmpv, "mpv_free")
    mpv_client_name_ = GetFunction(libmpv, "mpv_client_name")
    mpv_client_id = GetFunction(libmpv, "mpv_client_id")
    mpv_create = GetFunction(libmpv, "mpv_create")
    mpv_initialize = GetFunction(libmpv, "mpv_initialize")
    mpv_destroy = GetFunction(libmpv, "mpv_destroy")
    mpv_terminate_destroy = GetFunction(libmpv, "mpv_terminate_destroy")
    mpv_create_client = GetFunction(libmpv, "mpv_create_client")
    mpv_create_weak_client = GetFunction(libmpv, "mpv_create_weak_client")
    mpv_load_config_file = GetFunction(libmpv, "mpv_load_config_file")
    mpv_get_time_ns = GetFunction(libmpv, "mpv_get_time_ns")
    mpv_get_time_us = GetFunction(libmpv, "mpv_get_time_us")
    mpv_free_node_contents = GetFunction(libmpv, "mpv_free_node_contents")
    mpv_set_option = GetFunction(libmpv, "mpv_set_option")
    mpv_set_option_string = GetFunction(libmpv, "mpv_set_option_string")
    mpv_set_option_string_str = GetFunction(libmpv, "mpv_set_option_string")
    mpv_command = GetFunction(libmpv, "mpv_command")
    mpv_command_node = GetFunction(libmpv, "mpv_command_node")
    mpv_command_ret = GetFunction(libmpv, "mpv_command_ret")
    mpv_command_string = GetFunction(libmpv, "mpv_command_string")
    mpv_command_async = GetFunction(libmpv, "mpv_command_async")
    mpv_command_node_async = GetFunction(libmpv, "mpv_command_node_async")
    mpv_abort_async_command = GetFunction(libmpv, "mpv_abort_async_command")
    mpv_set_property = GetFunction(libmpv, "mpv_set_property")
    mpv_set_property_string = GetFunction(libmpv, "mpv_set_property_string")
    mpv_del_property = GetFunction(libmpv, "mpv_del_property")
    mpv_set_property_async = GetFunction(libmpv, "mpv_set_property_async")
    mpv_get_property = GetFunction(libmpv, "mpv_get_property")
    mpv_get_property_string_ = GetFunction(libmpv, "mpv_get_property_string")
    mpv_get_property_osd_string_ = GetFunction(libmpv, "mpv_get_property_osd_string")
    mpv_get_property_async = GetFunction(libmpv, "mpv_get_property_async")
    mpv_observe_property = GetFunction(libmpv, "mpv_observe_property")
    mpv_unobserve_property = GetFunction(libmpv, "mpv_unobserve_property")
    mpv_event_name_ = GetFunction(libmpv, "mpv_event_name")
    mpv_event_to_node = GetFunction(libmpv, "mpv_event_to_node")
    mpv_request_event = GetFunction(libmpv, "mpv_request_event")
    mpv_request_log_messages = GetFunction(libmpv, "mpv_request_log_messages")
    mpv_wait_event = GetFunction(libmpv, "mpv_wait_event")
    mpv_wakeup = GetFunction(libmpv, "mpv_wakeup")
    mpv_set_wakeup_callback = GetFunction(libmpv, "mpv_set_wakeup_callback")
    mpv_wait_async_requests = GetFunction(libmpv, "mpv_wait_async_requests")
    mpv_hook_add = GetFunction(libmpv, "mpv_hook_add")
    mpv_hook_continue = GetFunction(libmpv, "mpv_hook_continue")
    mpv_get_wakeup_pipe = GetFunction(libmpv, "mpv_get_wakeup_pipe")
  EndIf
EndIf


Procedure.s mpv_error_string(error.l)
  ProcedureReturn PeekS(mpv_error_string_(error), -1, #PB_UTF8)
EndProcedure


Procedure.s mpv_client_name(*ctx)
  ProcedureReturn PeekS(mpv_client_name_(*ctx), -1, #PB_UTF8)
EndProcedure


Procedure.s mpv_get_property_string(*ctx, name.s)
  ProcedureReturn PeekS(mpv_get_property_string_(*ctx, name), -1, #PB_UTF8)
EndProcedure


Procedure.s mpv_get_property_osd_string(*ctx, name.s)
  ProcedureReturn PeekS(mpv_get_property_osd_string_(*ctx, name), -1, #PB_UTF8)
EndProcedure


Procedure.s mpv_event_name(event.i)
  ProcedureReturn PeekS(mpv_event_name_(event), -1, #PB_UTF8)
EndProcedure




CompilerIf #PB_Compiler_IsMainFile
  Debug mpv_client_api_version()
  Debug mpv_error_string(#MPV_ERROR_NOMEM)
CompilerEndIf
The next step was to run a simple example.
The biggest point was to find out how to build the cmd array.
For the test I used a mp4 file as commandline parameter.

Code: Select all

;
; https://github.com/mpv-player/mpv-examples/blob/master/libmpv/simple/simple.c
;

EnableExplicit

IncludeFile "libmpv.pbi"


Procedure check_error(status.i)
  
  If status < 0
    Debug "mpv API error: " + mpv_error_string(status)
    End 1
  EndIf
  
EndProcedure


Define val.i, *ctx, *event.mpv_event, *cmd


If CountProgramParameters() <> 1
  Debug "pass a single media file as argument"
  End 1
EndIf

*ctx = mpv_create()
If Not *ctx
  Debug "failed creating context"
  End 1
EndIf


; Enable Default key bindings, so the user can actually interact with
; the player (And e.g. close the window).
check_error(mpv_set_option_string_str(*ctx, "input-default-bindings", "yes"))
mpv_set_option_string_str(*ctx, "input-vo-keyboard", "yes")
val = 1
check_error(mpv_set_option(*ctx, "osc", #MPV_FORMAT_FLAG, @val))

; Done setting up options.
check_error(mpv_initialize(*ctx))

;Play this file.

Structure cmd
  *cmd.String
EndStructure

Dim cmd.cmd(2)
cmd(0)\cmd = UTF8("loadfile")
cmd(1)\cmd = UTF8(ProgramParameter(0))
cmd(2)\cmd = #Null

;check_error(mpv_command(*ctx, @cmd(0)))
check_error(mpv_command(*ctx, cmd()))


; Let it play, And wait Until the user quits.
While #True
  *event = mpv_wait_event(*ctx, 10000)
  Debug "event: " + mpv_event_name(*event\event_id)
  If *event\event_id = #MPV_EVENT_SHUTDOWN
    Debug "MPV_EVENT_SHUTDOWN"
    Break
  EndIf
Wend

mpv_terminate_destroy(*ctx)

FreeMemory(cmd(0)\cmd)
FreeMemory(cmd(1)\cmd)

End 0
Tested with PB 6.04 x86 on WIndows 10 x64

With PB 6.04 x64 I see only a blue window, but can here the sound. Strange.

Re: libmpv

Posted: Mon Dec 18, 2023 11:10 am
by dige
Thank you Infratec! Now I was able to play videos successfully. Unfortunately, it does not seems to be a high-performance player. I have tested some footage encoded with H264, which jerks slightly during playback. The media player plays it smoothly.

What is your impression of the Mpv player? What are the advantages?

Re: libmpv

Posted: Tue Dec 19, 2023 9:10 pm
by infratec
Hi dige,

I have no experince with mpv.
The listing above was my first use of it.

For me shocking: the size of the dll.
Maybe it is the debug version and it can be stripped.

Re: libmpv

Posted: Tue Nov 26, 2024 7:37 am
by DannyWeijermans
libmpv is awesome,
because it plays so many formats,
and does it really well!
(faster than ffplay for many formats)

would it be possible
that someone helps
porting this code for Mac OSX?

would be a great value!

Regards, Danny Weijermans

Re: libmpv

Posted: Tue Nov 26, 2024 7:42 am
by infratec
Have you already tried to change the OpenLibrary line?

Re: libmpv

Posted: Tue Nov 26, 2024 9:23 am
by DannyWeijermans
Dear infratec,
Yes, what I tried:
install libmpv.2.dylib using brew.
and there's no errors when I open that library in the code.
BUT: any procedure call give a red line,
so I guess that variables should be declared differently
(or something else ;)
Anyone knows more about this?
Would be great to port it to OSX..
Greetings! Danny Weijermans