Jump to content

Video in GUI 2023 solution?


Recommended Posts

I'm looking for a solution to play a video in a GUI with no frame or any controls just the video, in any size I want to.

Of course I've searched for solutions myself but everything that I found is from many years ago and does not work anymore on Windows 10.

Cmon there must be a way? 

Link to comment
Share on other sites

I haven't used it much, but I just opened a script that I've used this VLC UDF on before and it still works for me on Windows 10: 

I haven't tried opening a video file directly using the UDF, instead I open a playlist which specifies the video file to play, but my script looks like this:

#include <GUIConstants.au3>
#include <VLC.au3>
#include <SliderConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>

_VLCErrorHandlerRegister()

Local $hMainGui = GUICreate("VLC UDF Example", 600, 1013, -1, -1)
Local $state, $msg

$vlc1 = _GUICtrlVLC_Create(0, 0, 600, 337) ; _GUICtrlVLC_Create($left, $top, $width, $height)
;$vlc2 = _GUICtrlVLC_Create(0, 337, 600, 337)

GUISetState(@SW_SHOW)

UpdateGUIAndPlay($vlc1, "C:\Users\Raven\Documents\AutoIt\VLC\TestVideo.xspf")

While 1
    $msg = GUIGetMsg()

    ; Loop a finished video
    $state = _GUICtrlVLC_GetState($vlc1)
    If $state = 6 Then UpdateGUIAndPlay($vlc1)

    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
WEnd



Func UpdateGUIAndPlay(ByRef $hVlc, $path = "")
    If StringLen($path) > 0 Then
        _GUICtrlVLC_Clear($hVlc)
        _GUICtrlVLC_Play($hVlc, _GUICtrlVLC_Add($hVlc, $path))
    Else
        _GUICtrlVLC_Play($hVlc, 0)
    EndIf

    While _GUICtrlVLC_GetState($hVlc) <> 3
        Sleep(10)
    WEnd
EndFunc   ;==>UpdateGUIAndPlay

 

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

1 hour ago, mistersquirrle said:

I haven't used it much, but I just opened a script that I've used this VLC UDF on before and it still works for me on Windows 10: 

I haven't tried opening a video file directly using the UDF, instead I open a playlist which specifies the video file to play, but my script looks like this:

#include <GUIConstants.au3>
#include <VLC.au3>
#include <SliderConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>

_VLCErrorHandlerRegister()

Local $hMainGui = GUICreate("VLC UDF Example", 600, 1013, -1, -1)
Local $state, $msg

$vlc1 = _GUICtrlVLC_Create(0, 0, 600, 337) ; _GUICtrlVLC_Create($left, $top, $width, $height)
;$vlc2 = _GUICtrlVLC_Create(0, 337, 600, 337)

GUISetState(@SW_SHOW)

UpdateGUIAndPlay($vlc1, "C:\Users\Raven\Documents\AutoIt\VLC\TestVideo.xspf")

While 1
    $msg = GUIGetMsg()

    ; Loop a finished video
    $state = _GUICtrlVLC_GetState($vlc1)
    If $state = 6 Then UpdateGUIAndPlay($vlc1)

    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
WEnd



Func UpdateGUIAndPlay(ByRef $hVlc, $path = "")
    If StringLen($path) > 0 Then
        _GUICtrlVLC_Clear($hVlc)
        _GUICtrlVLC_Play($hVlc, _GUICtrlVLC_Add($hVlc, $path))
    Else
        _GUICtrlVLC_Play($hVlc, 0)
    EndIf

    While _GUICtrlVLC_GetState($hVlc) <> 3
        Sleep(10)
    WEnd
EndFunc   ;==>UpdateGUIAndPlay

 

Thank you! I've played around with this too but I don't rlly like it. I'm not writing on my own UDF using the ffmpeg decoder library. works like a charm

Link to comment
Share on other sites

Another way with Media Player (no need of UDF) :

#include <Constants.au3>
#include <StructureConstants.au3>
#include <GUIConstants.au3>

Local $hGui = GUICreate("WMPlayer", 800, 600)
Local $oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then Exit MsgBox($MB_SYSTEMMODAL, "WMPlayer.OCX", "Cannot create a WMP object.", 5)
GUICtrlCreateObj($oPlayer, 0, 0, 800, 600)

With $oPlayer
  .URL = "Your path here.wmv" ; $sFullPath
  .uiMode = "none"
  .settings.mute = False
EndWith

While $oPlayer.playState = 9
  Sleep(50)
WEnd

GUISetState()
ResizeOCX($oPlayer, 0, 0, 800, 600)

While $oPlayer.playState = 3     ; 1 - stopped, 2 - paused, 3 - playing
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
WEnd

Func ResizeOCX($oObject, $iLeft, $iTop, $iRight, $iBottom)
  Local Const $tagIOleInPlaceObj = _
      "ContextSensitiveHelp none(int); " & _
      "GetWindow none(ptr); " & _
      "InPlaceDeactivate none(); " & _
      "ReactivateAndUndo none(); " & _
      "SetObjectRects none(ptr; ptr;); " & _
      "UIDeactivate none();"
  Local $oIInPlace = ObjCreateInterface($oObject, "{00000113-0000-0000-C000-000000000046}", $tagIOleInPlaceObj)
  Local $tRect = DllStructCreate($tagRECT)
  $tRect.Left = $iLeft
  $tRect.Top = $iTop
  $tRect.Right = $iRight
  $tRect.Bottom = $iBottom
  Local $pRect = DllStructGetPtr($tRect)
  $oIInPlace.SetObjectRects($pRect, $pRect)
EndFunc   ;==>ResizeOCX

 

Link to comment
Share on other sites

7 minutes ago, Nine said:

Another way with Media Player (no need of UDF) :

#include <Constants.au3>
#include <StructureConstants.au3>
#include <GUIConstants.au3>

Local $hGui = GUICreate("WMPlayer", 800, 600)
Local $oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then Exit MsgBox($MB_SYSTEMMODAL, "WMPlayer.OCX", "Cannot create a WMP object.", 5)
GUICtrlCreateObj($oPlayer, 0, 0, 800, 600)

With $oPlayer
  .URL = "Your path here.wmv" ; $sFullPath
  .uiMode = "none"
  .settings.mute = False
EndWith

While $oPlayer.playState = 9
  Sleep(50)
WEnd

GUISetState()
ResizeOCX($oPlayer, 0, 0, 800, 600)

While $oPlayer.playState = 3     ; 1 - stopped, 2 - paused, 3 - playing
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
WEnd

Func ResizeOCX($oObject, $iLeft, $iTop, $iRight, $iBottom)
  Local Const $tagIOleInPlaceObj = _
      "ContextSensitiveHelp none(int); " & _
      "GetWindow none(ptr); " & _
      "InPlaceDeactivate none(); " & _
      "ReactivateAndUndo none(); " & _
      "SetObjectRects none(ptr; ptr;); " & _
      "UIDeactivate none();"
  Local $oIInPlace = ObjCreateInterface($oObject, "{00000113-0000-0000-C000-000000000046}", $tagIOleInPlaceObj)
  Local $tRect = DllStructCreate($tagRECT)
  $tRect.Left = $iLeft
  $tRect.Top = $iTop
  $tRect.Right = $iRight
  $tRect.Bottom = $iBottom
  Local $pRect = DllStructGetPtr($tRect)
  $oIInPlace.SetObjectRects($pRect, $pRect)
EndFunc   ;==>ResizeOCX

 

Yup I've seen this one too, doesn't work in windows 10 unfortunately idk why. 

Link to comment
Share on other sites

Link to comment
Share on other sites

4 hours ago, argumentum said:

would you share the code ?

oh it's actually pretty simple, just download the ffmpeg release, and run the ffplay.exe in terminal like: ffplay -noborder -x 600 -y 400 ./video.avi 

you can also position it with -left and -top parameters. then just create your gui and position it inside of the gui where ever you want. use the "Run" function from autoit to run the cmd command. and use the @SW_HIDE showflag to hide the cmd window.

 But make sure to credit FFmpeg if you're planning to release anything in public.

Link to comment
Share on other sites

  • 1 month later...

Does anyone know what commands I should use to open ffplay running as light as possible, I'm currently testing Mplayer but it's a little heavy on more modest machines so I'm trying to find another player alternative that requires less cpu resources.

Link to comment
Share on other sites

so far in searches I only saw -threads 1 to improve ffplay.

I'm using it like this:

Run("ffplay.exe video.mp4"& $mute & " -fs -x 1024 -y 768 -left 0 -top 0 -threads 1 -window_title win_fundo -infbuf -framedrop -noborder -vf setdar=ratio=4/3", @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)

 

Edited by Belini
Link to comment
Share on other sites

3 hours ago, Belini said:

-threads 1

Was there any explanation as why that improves performance, more threads should get better performance, though I do know that some programs likes singlethread.

Have you tried using the exact amount of threads the cpu supports?

$cores = EnvGet("NUMBER_OF_PROCESSORS")

Run("ffplay.exe video.mp4"& $mute & " -fs -x 1024 -y 768 -left 0 -top 0 -threads " & $cores & "-window_title win_fundo -infbuf -framedrop -noborder -vf setdar=ratio=4/3", @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)

 

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Link to comment
Share on other sites

winmm.dll comes with Windows and using it is probably the leanest method available for media streaming. The following example shows 2 videos playing in one GUI. Other examples of winmm.dll commands can be found here.

#include <GUIConstants.au3>
#include <WinAPISysWin.au3>
#include <WinAPIConv.au3>
;#include <Array.au3>

HotKeySet("^!{END}", "_Exit")

$videoWidth = 720
$videoHeight = 405
$hGUI = GUICreate("WINMM.DLL", $videoWidth, $videoHeight*2, -1, -1) ;, $WS_OVERLAPPEDWINDOW)
$iGui = Dec(StringMid($hGUI, 3))

$aPos = WinGetPos($hGUI)
$borderWidth = ($aPos[2]-$videoWidth)/2
$titleHeight = $aPos[3]-$videoHeight*2-$borderWidth

GUISetState()

$hDLL = DllOpen("winmm.dll")

GUIRegisterMsg($WM_MOVE, "WM_MOVE")

$sFile1 = "D:\Video\Big_buck_Bunny.webM"
$sFile2 = "D:\Video\Yanni - The Rain Must Fall.mp4"

$iRet = mciSendString("open """ & $sFile1 & """ alias myMedia_1 type MPEGVideo style popup parent " & $iGui)
If $iRet <> 1 Then
    $sMsg = $sFile1 & @CRLF & @CRLF & "This file cannot be opened by this player."
    MsgBox(0, "Open error", $sMsg)
    _Exit()
EndIf
mciSendString("set myMedia_1 audio all off")
mciSendString("play myMedia_1 repeat")
$hVideo1 = WinGetHandle($sFile1)
WinMove($hVideo1, "", $aPos[0]+$borderWidth, $aPos[1]+$titleHeight, $videoWidth, $videoHeight)

$iRet = mciSendString("open """ & $sFile2 & """ alias myMedia_2 type MPEGVideo style popup parent " & $iGui)
If $iRet <> 2 Then
    $sMsg = $sFile2 & @CRLF & @CRLF & "This file cannot be opened by this player."
    MsgBox(0, "Open error", $sMsg)
    _Exit()
EndIf
;mciSendString("set myMedia_2 audio all off")
mciSendString("play myMedia_2 repeat")
$hVideo2 = WinGetHandle($sFile2)
WinMove($hVideo2, "", $aPos[0]+$borderWidth, $aPos[1]+$titleHeight+$videoHeight, $videoWidth, $videoHeight)

While 1
    $guiMsg = GUIGetMsg()
    Switch $guiMsg
        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd

Func mciSendString($string) ;https://learn.microsoft.com/en-us/windows/win32/multimedia/multimedia-command-strings
    Local $aRet = DllCall($hDLL, "int", "mciSendStringW", "wstr", $string, "wstr", "", "int", 65534, "hwnd", 0)
    If Not @error Then Return $aRet[2]
EndFunc

Func WM_MOVE($hWnd, $MsgID, $wParam, $lParam)
    #forceref $hWnd, $MsgID, $wParam, $lParam
    If $hWnd = $hGUI Then
        $x = _WinAPI_LoWord($lParam)
        $y = _WinAPI_HiWord($lParam)
        WinMove($hVideo1, "", $x, $y)
        WinMove($hVideo2, "", $x, $y+$videoHeight)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func _Exit()
    mciSendString("close myMedia_1")
    mciSendString("close myMedia_2")
    DllClose($hDLL)
    Exit
EndFunc

 

Edited by CYCho
Link to comment
Share on other sites

@CYCho yes using winmm.dll was always my best option and it was working fine until it got to windows 10 then with it problems started with some videos not playing so I'm trying to migrate to some light player that already has its own codecs because using the winmm.dll need to install klite or another codec pack to play videos.

Link to comment
Share on other sites

Thank you for sharing your experience. I've been toying around with winmm.dll for the last couple of months and I also had some frustrations. The biggest problem I had was that some files could not be played in fullscreen mode. This was solved by combination of mciSendString("play myMedia") and  mciSendString("play myMedia fullscreen from 0"). So far I have not seen any file that cannot be played by winmm.dll. As regards to codec, I already had klite installed in my computer, so I did not see it as a problem.

49 minutes ago, Belini said:

some videos not playing

Are those files playing in Windows Media Player, but not in winmm.dll?

 

Link to comment
Share on other sites

yes, having the codec, all videos that play in the media player will play with winmm.dll too, as for fullscreen, I couldn't make videos of different resolution occupy the whole screen without black bars, did you manage to solve this?

Link to comment
Share on other sites

30 minutes ago, Belini said:

whole screen without black bars, did you manage to solve this?

No, I couldn't. I took it as an effort to keep the aspect ratio of the source which, to me, was a very important feature.  If I really wanted to fill the screen disregarding the aspect ratio, I had to be content with a maximized window.

Link to comment
Share on other sites

On 5/9/2023 at 10:27 PM, Belini said:

whole screen without black bars, did you manage to solve this?

I learned just now from here that I can make the video fullscreen without the black bars.

WinMove($hVideo1, "", 0, 0, @DesktopWidth, @DesktopHeight)
GUISetStyle(BitOR($WS_POPUP, $WS_EX_TOPMOST), $hVideo1)

Edit: The file must have been opened in popup style in order for this to be effective.

Edited by CYCho
Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...