Jump to content

Video/audio player problem


ajit
 Share

Recommended Posts

Hi:

This video player is based on UDF by ludocus.

Plz help me with making the video position slider move as the video progresses (Guictrlsetdata).

Also, i cannot figure out how to get the total time and time elasped of the video.

I would be delighted if someone could help me out.

Thanks in anticipation.

Ajit

Herebelow the code:

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.11.7 (beta)

Author: ludocus

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>

;#include "SoundGetSetQuery.au3"

Global $mov, $tAlias, $iLength = 0

$hVideo = GUICreate("Test Video Player", 340, 340)

GUICtrlCreateLabel("", 10, 10, 320, 240)

GUICtrlSetBkColor(-1, 0x000000)

$hPlay = GUICtrlCreateButton("Play", 10, 285, 60, 20)

$hPause = GUICtrlCreateButton("Pause", 75, 285, 60, 20)

$hLoad = GUICtrlCreateButton("Load", 140, 285, 60, 20)

$position = GUICtrlCreateSlider(6, 255, 325, 20) ; slider to seek position

GUICtrlSetLimit(-1, 100)

GUICtrlCreateLabel("Vol", 250, 320)

$volume = GUICtrlCreateSlider(230, 285, 100, 20) ; slider to set volume

GUICtrlSetLimit(-1, 100)

GUICtrlSetData($volume, 100)

;_SoundSetMasterVolume(100)

;; video time

$timeelasped = GUICtrlCreateLabel("0:00", 40, 320, 25, 20)

GUICtrlCreateLabel("/", 80, 320, 10, 20)

$totaltime = GUICtrlCreateLabel("0:00", 100, 320, 25, 20)

; master volume

$mastervol = GUICtrlCreateLabel("100", 270, 320, 25, 20)

GUISetState()

While 1

Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE

_MovieClose($mov)

Exit

Case $position ; thanks to @Authenticity

Local $iPos, $iTotalMs

If $iLength > 0 Then

$iPos = GUICtrlRead($position)/100

$iTotalMs = Int($iPos*$iLength)

_MovieSeek($mov, $iTotalMs)

_MoviePlay($mov)

EndIf

Case $hPlay

_MoviePlay($mov)

Case $volume

Local $ivol

$ivol = GUICtrlRead($volume)

;_SoundSetMasterVolume($ivol)

GUICtrlSetData($mastervol, $ivol)

Case $hPause

_MoviePause($mov)

Case $hLoad

$sFile = FileOpenDialog("Open", "", "All Files (*.*)", 1)

If $sFile = '' Then

$iLength = 0

Else

$mov = _MovieOpen($sFile, $hVideo, 10, 10, 320, 240)

$iLength = _MovieLength($mov)

EndIf

EndSwitch

WEnd

; Script Start - Add your code below here

Func mciSendString($string)

Local $iRet

$iRet = DllCall("winmm.dll", "int", "mciSendStringA", "str", $string, "str", "", "int", 65534, "hwnd", 0)

If Not @error Then Return $iRet[2]

EndFunc ;==>mciSendString

Func _MovieOpen($pFile, $pHwnd, $pTop, $pLeft, $pWidth, $pHeight, $pAlias = '')

If $pAlias = '' Then $pAlias = RandomStr(10)

mciSendString("close " & $pAlias)

If Not @error Then

mciSendString("open " & FileGetShortName($pFile) & " alias " & $pAlias)

mciSendString("window " & $pAlias & " handle " & Number($pHwnd))

mciSendString("put " & $pAlias & " destination at " & $pTop & ' ' & $pLeft & ' ' & $pWidth & ' ' & $pHeight)

Return $pAlias

Else

Return 0

EndIf

EndFunc ;==>_MovieOpen

Func _MovieClose($hAlias)

Return mciSendString("close " & $hAlias)

EndFunc ;==>_MovieClose

Func _MoviePause($rAlias)

Return mciSendString("pause " & $rAlias)

EndFunc ;==>_MoviePause

Func _MovieStop($jAlias)

Return mciSendString("seek " & $jAlias & " to start")

EndFunc ;==>_MovieStop

Func _MoviePlay($sAlias)

mciSendString("set Test_Video time format milliseconds")

If mciSendString("status " & $sAlias & " position") = mciSendString("status " & $sAlias & " length") Then mciSendString("seek " & $sAlias & " to start")

mciSendString("play " & $sAlias)

Return 1

EndFunc ;==>_MoviePlay

Func _MoviePos($tAlias)

$sReturn = mciSendString("status " & $tAlias & " position")

If @error Then Return 0

Return $sReturn

EndFunc ;==>_MoviePos

Func _MovieLength($tAlias)

$tReturn = mciSendString("status " & $tAlias & " length")

If @error Then Return 0

Return $tReturn

EndFunc ;==>_MovieLength

Func _MovieSeek($sSnd_id, $iMs)

Local $iRet

mciSendString("set " & FileGetShortName($sSnd_id) & " time format miliseconds")

$iRet = mciSendString("seek " & $sSnd_id & " to " & $iMs)

If $iRet = 0 Then

Return 1

Else

Return SetError(1, 0, 0)

EndIf

EndFunc ;==>_MovieSeek

Func _MovieStatus($kAlias)

Return mciSendString("status " & $kAlias & " mode")

EndFunc ;==>_MovieStatus

Func RandomStr($len)

Local $string

For $iCurrentPos = 1 To $len

$string &= Chr(Random(97, 122, 1))

Next

Return $string

EndFunc ;==>RandomStr

movie_test.au3

Link to comment
Share on other sites

Hi,

I haven't tried your code, but maybe you can work it out from some of my code I wrote a while back.

Maybe you can mix and mash the bits to get the job done.

Here's an example of use an the needed include file required written by me.

Video_In_Gui_Example.au3

MCI_Video.au3

Note1: Under the Play menu you can use the option in the example to Slide N Seek to seek the video in real time as you slide.

Default the example lets the user slide and once they let the slider go it then seeks to the time in the movie.

Note2: Under the View menu to view video as wallpaper (only works in XP) you need to enable "Lock Web Items on Desktop" eg:

Right click your desktop and select "Arrange Icons By -> Lock Web Items on Desktop"

Let me know when or if you have the attachments so I can remove them.

Cheers

Link to comment
Share on other sites

Hi smashly,

Thanks very much for your help. Thanks for your script, it is really superb.

I am experimenting with it. Will surely come back to you for help.

Thanks again for your help.

Regards

Ajit

Link to comment
Share on other sites

  • 2 years later...

I’m having trouble getting an AVI to play at normal speed in AutoIt. There are a few example scripts, and in each that I’ve tried the video plays approximately 38 times faster than normal. The code I’m posting is smashly code for “Video_In_Gui_Example.au3” that was posted on 28 April 2009, but with the following typos corrected in order to get the script to run.

1. Corrected incorrect variable name in Func _Video_Open, parameter 5. $iH should be $iW.

2. In Func _VidPlay, function mciSendString is missing its leading underscore. Should be __mciSendString.

3. In Func _VidLength, function mciSendString is missing its leading underscore. Should be __mciSendString (two places).

4. Calls to Func _VidOpen should be _Video_Open (5 places)

5. Line 61 has too many arguments in its call to Func _Video_Open. Remove the 2nd one (the null string).

In an attempt to set the frame rate, I’ve added the following to smashly’s coding for the Open button:

$sFrameRate = _mciSendString("status " & $vID & " nominal frame rate", 255) / 1000

ConsoleWrite(@LF & "Frame Rate: " & $sFrameRate & @LF)

It returns 25 for the frame rate, but the video still plays 38 times faster than normal.

I’ve tried the AutoIt GUI AVI Management functions, but my videos do not play at all, and others have similarly noted.

Can anyone assist me? If it's makes any difference, I'm attempting to run 30 and 90 minute videos, not tiny videos like in the help file.

smashly's coding with my corrections and additions follows:

;; Original Coding by smashly.
;; Edited by ILLBeBack to correct typos and to set frame rate
;;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>

HotKeySet('!{ENTER}', 'FullScreen') ; Alt + Enter toggles fullscreen

Opt("GuiOnEventMode",1)

Global $vID, $Fullscreen


$hGUI = GUICreate("Video Control", 400, 335 , -1, -1, BitOr($WS_OVERLAPPEDWINDOW,$WS_CLIPCHILDREN))
GUISetOnEvent($GUI_EVENT_CLOSE , "Event")

$Play = GUICtrlCreateButton("Play", 5, 305, 40, 25)
GUICtrlSetOnEvent(-1 , "Event")
GuiCtrlSetState(-1, $GUI_DISABLE)

$Stop = GUICtrlCreateButton("Stop", 50, 305, 40, 25)
GUICtrlSetOnEvent(-1 , "Event")
GuiCtrlSetState(-1, $GUI_DISABLE)

$Open = GUICtrlCreateButton("Load", 95, 305, 40, 25)
GUICtrlSetOnEvent(-1 , "Event")

GuiSetState(@SW_SHOW, $hGUI)

While 1
    Sleep(100)

WEnd

Func Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _SoundClose($vID)
            Exit
        Case $Play
            If _SoundStatus($vID) = "playing" Then
                _SoundPause($vID)
               GUICtrlSetData($Play, 'Play')
            ElseIf _SoundStatus($vID) = "paused" Then
                _SoundResume($vID)
                GUICtrlSetData($Play, 'Pause')
            ElseIf _SoundStatus($vID) = "stopped" Then
                _VidPlay($vID, 0)
                GUICtrlSetData($Play, 'Pause')
            EndIf
        Case $Stop
            If _SoundStatus($vID) = "playing" Then
                _SoundStop($vID)
                GUICtrlSetData($Play, 'Play')
            EndIf
        Case $Open
            $file = FileOpenDialog("OPEN","","Video (*.avi;*.mpg)")
            If @error <> 1 Then
                If _SoundStatus($vID) <> "" Then
                    _SoundClose($vID)
                    GUICtrlSetData($Play, 'Play')
                EndIf
                $vID = _Video_Open($file, $hGUI, 0, 0, 400, 300)

                If $vID <> "" Then
$sFrameRate = _mciSendString("status " & $vID & " nominal frame rate", 255) / 1000
ConsoleWrite(@LF & "Frame Rate: " & $sFrameRate & @LF)
                    _VidPlay($vID, 0)
                    GUICtrlSetData($Play, 'Pause')
                    GuiCtrlSetState($Play, $GUI_ENABLE)
                    GuiCtrlSetState($Stop, $GUI_ENABLE)
          WinSetTitle($hGUI, "", _VidLength($vID, 1))
                EndIf
            EndIf
    EndSwitch
EndFunc

Func Quit()
            _SoundClose($vID)
            Exit
EndFunc

Func FullScreen()
    If $Fullscreen = 0 Then
        _VidPlay($vid, 1)
        $Fullscreen = 1
    ElseIf $Fullscreen = 1 Then
        _VidPlay($vid, 0)
        $Fullscreen = 0
    EndIf
EndFunc

;========================================================================================================
; Description ...: Opens a Video file ready for use with other _Video_xxxx functions.
; Syntax.........: _Video_Open($sFile, $hWnd, $iX, $iY, $iW, $iH)
; Parameters ....: $sFile     - The full path to video file.
;                  $hWnd      - Handle to a window or control that the video will be displayed on
;                  $iX        - Left position of the video.
;                  $iY        - Top position of the video.
;                  $iW        - Width of the video.
;                  $iH        - Height of the video.
; Return values .: Success    - Return a string (Alias name for use with other _Video_xxxx functions)
;                  Failure    - Return an empty String "" and @error 1~5
;                               @error 1 = File doesn't exist
;                               @error 2 = Window or Control handle not valid.
;                               @error 3 = Failed to render video.
;                               @error 4 = Failed to place video at the deignated location.
; Author ........: smashly
;========================================================================================================
Func _Video_Open($sFile, $hWnd, $iX, $iY, $iW, $iH)
    Local $sVID, $gId, $vRet, $vWin, $vLoc
    If Not FileExists($sFile) Then Return SetError(1, 0, "")
    If Not IsHWnd($hWnd) Then Return SetError(2, 0, "")
    $gId = Dec(StringTrimLeft($hWnd,2))
    $sVID = _RandomStr()
    $vRet = _mciSendString("open " & FileGetShortName($sFile) & " alias " & $sVID)
    $vWin = _mciSendString("window " & $sVID & " handle " & $gId)
    If $vWin <> 0 Then
        _mciSendString("close " & $sVID)
        Return SetError(3, 0, "")
    EndIf
    $vLoc = _mciSendString("put " & $sVID & " destination at " & $iX & " " & $iY & " " & $iH & " " & $iH)
    If $vLoc <> 0 Then
        _mciSendString("close " & $sVID)
        Return SetError(4, 0, "")
    EndIf
    Return SetError(0, 0, $sVID)
EndFunc   ;==>_Video_Open

;===============================================================================
;
; Function Name:   _VidPlay($vID, $fScreen)
; Description::    Plays a Video from the current position (beginning is the default)
; Parameter(s):    $vID - Video ID returned by _Video_Open
;                  $fScreen [Optional] - If set to 1 the will be played in FullScreen (no Gui or Controls displayed)
;                                      - If set to 0 the video will play in the GUI as specified in _Video_Open
;                                      - If omitted then 0 will be used (play in the GUI as specified in _Video_Open)
; Requirement(s):  AutoIt 3.2 ++
; Return Value(s): 1 - Success, 0 - Failure
;                  @error = 1 - play failed
; Author(s):       smashly (modified from RazorM sound udf for video play)
;
;===============================================================================
;
Func _VidPlay($vID, $fScreen = 0)
    ;Declare variables
    Local $vRet
    ;if sound has finished, seek to start
    If _VidPos($vID, 2) = _VidLength($vID, 2) Then _mciSendString("seek " & $vID & " to start")
    If $fScreen = 1 Then
        $vRet = _mciSendString("play " & $vID & " fullscreen")
    Else
        $vRet = _mciSendString("play " & $vID)
    EndIf
    ;return
    If $vRet = 0 Then
        Return 1
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_VidPlay

;===============================================================================
;
; Function Name:   _VidLength
; Description::    Returns the length of the sound in the format hh:mm:ss
; Parameter(s):    $vID     - Sound ID returned by _SoundOpen or sound file,
;                  $iMode = 1 - hh:mm:ss, $iMode = 2 - milliseconds
; Requirement(s):  AutoIt 3.2 ++
; Return Value(s): Length of the sound - Success, 0 and @error = 1 - $iMode is invalid
; Author(s):       RazerM
; Mofified:        jpm
;
;===============================================================================
;
Func _VidLength($vID, $iMode = 1)
    Local $iMS
    If $vID = "" Or StringRegExp($vID, "\W|_", 0) Then Return SetError(1, 0, 0)
    If $iMode <> 1 And $iMode <> 2 Then Return SetError(2, 0, 0)
    _mciSendString("set " & FileGetShortName($vID) & " time format ms")
    $iMS = _mciSendString("status " & FileGetShortName($vID) & " length", 255)
    If $iMode = 1 Then Return _MSToHMS($iMs)
    If $iMode = 2 Then Return $iMS
EndFunc   ;==>_VidLength

Func _VidPos($vID, $iMode = 1)
    Local $iMS
    If $vID = "" Or StringRegExp($vID, "\W|_", 0) Then Return SetError(1, 0, 0)
    If $iMode <> 1 And $iMode <> 2 Then Return SetError(2, 0, 0)
    _mciSendString("set " & $vID & " time format ms")
    $iMs = _mciSendString("status " & $vID & " position", 255)
    If $iMode = 1 Then Return _MSToHMS($iMs)
    If $iMode = 2 Then Return $iMs
EndFunc   ;==>_VidPos




Func _MSToHMS($iMS)
    Local $iHours = 0, $iMins = 0, $iSecs = 0
    If Number($iMS) > 0 Then
        $iMS = Round($iMS / 1000)
        $iHours = Int($iMS / 3600)
        $iTicks = Mod($iMS, 3600)
        $iMins = Int($iTicks / 60)
        $iSecs = Round(Mod($iMS, 60))
        Return StringFormat("%02i:%02i:%02i", $iHours, $iMins, $iSecs)
    EndIf
    Return StringFormat("%02i:%02i:%02i", $iHours, $iMins, $iSecs)
EndFunc

Func _mciSendString($string, $iLen = 0)
    Local $iRet
    $iRet = DllCall("winmm.dll", "int", "mciSendStringA", "str", $string, "str", "", "long", $iLen, "long", 0)
    If Not @error Then Return $iRet[2]
EndFunc   ;==>mciSendString

Func _RandomStr($len = 10)
    Local $string
    For $iCurrentPos = 1 To $len
        $string &= Chr(Random(97, 122, 1))
    Next
    Return $string
EndFunc   ;==>RandomStr
Link to comment
Share on other sites

I remastered one of the AVI videos that plays too fast using AVS VideoRemaker, and that copy plays properly and at normal speed. I assume something is odd with regards to frame rate, and that editor corrected it.

Should I be doing something in the AutoIt script that would correct this and avoid having to remaster videos beforehand?

Link to comment
Share on other sites

It's hard to say only based on a description, would be easier if there was a videofile for us to try on.

Thanks for your reply! I would like to post a video for this purpose, but unfortunately copyright laws prevent it. The videos in question are recordings of over-the-air television broadcasts, and while perfectly legal they cannot be distributed. I’ve tried to extract a short clip which I believe I could post under “Fair Use”, but I don’t know how to do that without remastering (which resolves the issue).

I don’t know if this will help, but inspection of the video file “Properties” of the one that plays too fast and the one that plays correctly reveals differences in “Data Rate” and “Total Bitrate” as follows:

Original --- Remastered

1080 --- 1065 (Data Rate)

1208 --- 1193 (Total Bitrate)

Link to comment
Share on other sites

  • 2 weeks later...

I couldn’t resolved the fast play back issue that I described above, but I found another player, named AAA Player, by forum member monoceres, that perfectly plays the same videos. For those interested, that thread is

ILLBeBack

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...