Jump to content

Convert Video to Gif


rcn3t0
 Share

Recommended Posts

Hello,
Sharing a script.
Search sources are in the code comment.
When executing the script choose the video file (preferably small) to convert to gif
The script has coded lines. Usually I do this in as many lines as possible so that even if the script is decompiled I have little understanding of the actions and functions created.
In the script I kept the eligible conversion file and the encoded temporary path address for consultation and learning

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         Rodrigo Chaves

 Script Function:
    Convert Video to Gif
    07/2019

 Fonte de pesquisa
    https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality
    http://www.autoitbrasil.com/forum/index.php?/topic/1505-pequenos-scripts-%C3%BAteis/

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

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <File.au3>

Opt("ExpandVarStrings", 1)

Dim $hWnd_Main, $sName = "Video2Gif"
Dim $sFileConvert = BinaryToString('0x4054656D70446972405C766964656F326769662E626174')
Dim $sAction_FD = BinaryToString('0x46696C6544656C65746528274054656D70446972405C766964656F326769662E6261742729')
Dim $sAction_FC = BinaryToString('0x46696C65577269746528247346696C65436F6E766572742C20245F73537472696E6746696C6529')
Dim $sFile = FileOpenDialog('Convert Video 2 Gif', '', 'All (*.*)')

If $sFile <> '' Then
    hWnd_Main()
    createFile()
    $getName = StringSplit($sFile, "\", 1)
    $sCountSlash = $getName[0]
    $iPID = Run(@ComSpec & ' /c "' & $sFileConvert & ' ' & $getName[$sCountSlash], '', @SW_HIDE)
    ProcessWaitClose($iPID)
    GUIDelete($hWnd_Main)
    Execute($sAction_FD)
    MsgBox(262144+64, $sName, 'Done', 60)
EndIf

Func createFile($iFPS = 30)
    If Not Int($iFPS) Then Exit MsgBox(262144+16, 'Error', 'Declared value is not an integer', 60)
    $_sStringFile = '@echo off' & @CRLF
    $_sStringFile &= 'set arg1=%1' & @CRLF
    $_sStringFile &= 'set arg2=%arg1:~0,-4%' & @CRLF
    $_sStringFile &= 'ffmpeg -y -i %arg1% -vf fps=30,scale=-1:-1:flags=lanczos,palettegen %TEMP%\palette.png' & @CRLF
    $_sStringFile &= 'ffmpeg -i %arg1% -i %TEMP%\palette.png -filter_complex "fps=' & $iFPS & ',scale=-1:-1:flags=lanczos[x];[x][1:v]paletteuse" %arg2%gif' & @CRLF
    $_sStringFile &= 'del /f %TEMP%\palette.png'
    Execute($sAction_FD)
    Execute($sAction_FC)
EndFunc

Func hWnd_Main()
    Dim Const $tSTRUCT = 'struct;char dark[8];char darkLight[8];char white[8];char aqua[8];char alpha[2];endstruct'
    Dim $oColor = DllStructCreate($tSTRUCT)

    $oColor.dark = 0x252525
    $oColor.darkLight = 0x323232
    $oColor.white = 0xFFFFFF
    $oColor.aqua = 0x00FFFF
    $oColor.alpha = -2

    $hWnd_Main = GUICreate($sName, 602, 203, -1, -1, $WS_POPUPWINDOW)
    GUISetBkColor($oColor.dark)
    $aGetPos = WinGetPos($hWnd_Main)

    $sLabel_Title = GUICtrlCreateLabel($sName, 0, 0, $aGetPos[2] - 1, 17, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, $oColor.darkLight)
    GUICtrlSetColor(-1, $oColor.white)

    GUICtrlCreateGraphic(0, 18, $aGetPos[2] - 1, 1)
    GUICtrlSetBkColor(-1, $oColor.aqua)

    $sLabel_Status = GUICtrlCreateLabel("Converting video to gif", 0, 60, $aGetPos[2] - 1, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetBkColor(-1, $oColor.alpha)
    GUICtrlSetColor(-1, $oColor.white)

    $Progress = GUICtrlCreateProgress(185, 90, 230, 12, 0x8)
    _SendMessage(GUICtrlGetHandle($Progress), $PBM_SETMARQUEE, True, 30)

    $sLabel_Wait = GUICtrlCreateLabel("Aguarde", 0, 115, $aGetPos[2] - 1, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetBkColor(-1, $oColor.alpha)
    GUICtrlSetColor(-1, $oColor.white)
    GUISetState(@SW_SHOW)   
EndFunc

https://1drv.ms/u/s!AnsPM67Cyv4XjIsLwAufsyCrNsTbcw?e=8Bkeg6

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