Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: by JaCk | DevStable 08/21/2017| https://pastebin.com/JGL83SM8 | ffmpeg_gifme.bat --- Creates a palette file from input file, then proceeds to generate a gif file with the same name as input file.
- ::
- :: Based on command: ffmpeg -an -sn -ss 01:30 -i "video.mkv" -i "%temp%\fgme_palette.png" -vf "select='not(mod(n,60))',setpts='N/17/TB',scale=-1:360" -r 2/3 -y "out.gif"
- ::
- :: Over-Engineered Mauch? Naw... *waves jedi/witcher hand signs* There is no script...
- :: Its ugly? You Dont say... Even a mother loves her ugly-ass turdling.
- ::
- @echo off && setlocal EnableDelayedExpansion && (for /f "tokens=1 delims==" %%a in ('set fgme_') do set "%%a=") 2>nul 1>nul
- :: Setting Script Parameters to Variables
- set "fgme_input_file=%~1"
- set "fgme_output_file=%~2"
- set "fgme_palette_file=%~3"
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :::::: ::::::
- :::: Development Version ::::
- :::: USE AT YOUR OWN RISK ::::
- :::::: ::::::
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::
- ::: :::
- :: User Vars ::
- :: User Settings ::
- ::: :::
- :::::::::::::::::::::::::::::::::::::::
- :: Hard Coded User Settings
- :: - if Not Set, script will prompt
- set "fgme_start_time=01:30" rem :: Default: 01:30 --- Description: starting time offset - ffmpeg will skip this duration before processing
- set "fgme_duration_rate=2/3" rem :: Default: 2/3 --- Description: Total duration of each frame in the gif that is to be created
- set "fgme_scale_image_base=360" rem :: Default: 360 --- Description: base width of the output file -- Height will be auto-magiclly calculated
- set "fgme_input_filev=" rem :: Default: --- Description: when defined, it uses this filename AND its location when specified; when location is unspecified uses cd. Params DO NOT overset var
- set "fgme_output_filev=" rem :: Default: --- Description: when defined, it uses this filename AND its location when specified; when location is unspecified uses cd. Params DO NOT overset var
- set "fgme_palette_filev=" rem :: Default: --- Description: when defined, it uses this filename AND its location when specified; when location is unspecified uses cd. Params DO NOT overset var
- :::::::::::::::::: :::::::::::::::::::
- :::::: ::::::
- :::::::::::::::: :::: :::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::
- ::: :::
- :: Script Vars ::
- :: Script Settings ::
- ::: :::
- :::::::::::::::::::::::::::::::::::::::
- :: Notes on Usage
- :: -Default: Not Set --- This means that the default setting was/is: empty, blank, null, nil, undefined
- :: -Default: false; Type: Boolean --- When var is undefined it is still [false]. Being undefined, the boolean function will consider it [false]
- :: -Type: Boolean --- No matter how long the string is, only first character is used to determine setting [t/a/p/y/1/def] or [f/und/n/0/nul]. When first character is a white space, then it is considered false/NotSet.
- :: False States: [undefined] : no; false; 0;
- :: True States: [defined=>true] : yes; true; 1; pass;
- ::
- rem :: Default: Not Set --- Type: String --- Required: Optional :: Description: output location of the palette file. When set, uses set directory name. When unset, uses %temp%. Relative paths are relative to the video file. Absolute paths, are absolute/fully-qualified
- set "fgme_palette_dir=palette\"
- rem :: Default: Not Set --- Type: String --- Required: Optional :: Description: when set, uses set file name. When unset, uses: video-filename.png
- set "fgme_palette_name="
- rem :: Default: false --- Type: Boolean --- Required: Optional :: Description: when true, palette file is not deleted after use.
- set "fgme_keep_palette=true"
- rem :: Default: true --- Type: Boolean --- Required: Optional :: Description: Increases the rate value ten-fold to increase creation.
- set "fgme_fast_palette=true"
- rem :: Default: false --- Type: Boolean --- Required: Optional :: Description: makes sure not to overwrite already created files
- set "fgme_wfilelock_bool="
- rem Default: Not Set --- Type: String --- Required: Optional :: Description: base filters, the image-scaling will be appended to this var further down this script - [scale=-1:!fgme_scale_image_base!:flags=lanczos]
- set "fgme_filters="
- rem Default: Not Set --- Type: String --- Required: Optional :: Description: specific settings for ffmpeg gif muxer
- rem Accepts:
- rem -loop 0 --- Number of times to loop the output: -1 - no loop, 0 - infinite loop. From -1 to 65535
- rem -final_delay -1 --- Force delay, in centiseconds, after the last frame. From -1 to 65535
- set "fgme_ffmpeg_gifOpt="
- rem :: Default: true --- Type: Boolean --- Required: Optional :: Description: when true, line numbers will be dumped for debug messages.
- set "fgme_debug_dline=true"
- :::::::::::::::::: :::::::::::::::::::
- :::::: ::::::
- :::::::::::::::: :::: :::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::
- ::: :::
- :: Prompt for input ::
- ::: :::
- :::::::::::::::::::::::::::::::::::::::
- :: Input the dam file... please
- if defined fgme_input_filev if not defined fgme_input_file set "fgme_input_file=!fgme_input_filev!"
- if not defined fgme_input_file call :func_get_user_input "fgme_input_file" "Input: Enter Video file [and relative path if needed]"
- if not exist "!fgme_input_file!" (
- echo/ Error: Unable to locate Input file !fgme_input_file!
- goto :eof
- )
- :: drop the out file on the var... NOW
- if not defined fgme_output_file if defined fgme_output_filev (
- set "fgme_output_file=!fgme_output_filev!"
- ) else (
- call :func_get_user_input fgme_output_file "Input: Enter Output file name [and outpath path if needed]"
- if defined fgme_output_file set "fgme_output_file=!fgme_output_file:"=!"
- echo/
- )
- :: I hope this palette is to you palettes liking -- Making the external, internal
- if defined fgme_palette_filev if not defined fgme_palette_file set "fgme_palette_file=!fgme_palette_filev!"
- if defined fgme_palette_file for %%P in ("!fgme_palette_file!") do (
- set "fgme_palette_dir=%%~dpP"
- set "fgme_palette_name=%%~nxP"
- if "%%~xP" equ "" set "fgme_palette_name=%%~nP.png"
- )
- :: Did someone order a pallet of palettes -- oh well, to temp you go...
- rem If we created the dir successfully then set remove bool
- if defined fgme_palette_dir (
- if not exist "!fgme_palette_dir!" (
- echo/ Info: Creating dir: "!fgme_palette_dir!"
- mkdir "!fgme_palette_dir!"
- if !errorlevel! equ 0 if not defined fgme_keep_palette (
- set "fgme_dpalette_dir=true"
- )
- )
- ) else (
- set "fgme_palette_dir=%temp%"
- set "fgme_dpalette_dir="
- )
- if defined fgme_palette_name (
- set "fgme_palette=!fgme_palette_dir!\!fgme_palette_name!"
- ) else (
- for /f "tokens=1* delims=" %%z in ("!fgme_input_file!") do (
- if "%%~n" neq "" (
- set "fgme_palette_name=%%~nz.png"
- set "fgme_palette=!fgme_palette_dir!\!fgme_palette_name!"
- )
- )
- )
- :: out from in -- maybe
- if not defined fgme_output_file (
- for /f "tokens=1* delims=" %%z in ("!fgme_input_file!") do (
- if "%%~n" neq "" set "fgme_output_file=%%~dpnz.gif"
- )
- if defined fgme_output_file (
- echo/
- echo/ - Info: Self Defined Output File name: !fgme_output_file!
- echo/
- ) else (
- echo/
- echo/ - Error: Unble to auto define Output file and one has not been defined
- echo/
- goto :eof
- )
- )
- :: Strip path to just the name to print purdy
- :: Verify extension is gif
- for /f "tokens=1* delims=" %%Z in ("!fgme_output_file!") do (
- if "%%~xZ" neq ".gif" (
- set "fgme_output_fname=%%~nxZ.gif"
- set "fgme_output_file=%%~Z.gif"
- ) else (
- set "fgme_output_fname=%%~nZ.gif"
- )
- )
- if not defined fgme_output_fname set "fgme_output_fname=!fgme_output_file!"
- :: Over-Right [unlike over-left]
- if exist "!fgme_output_file!" (
- echo/
- echo/
- echo/ - Warning: File Already Exits
- if not defined fgme_wfilelock_bool (
- call :func_get_bool_input "fgme_wfile_bool" "Input: User: Overwrite file [Yes/No]" "No"
- if not defined fgme_wfile_bool goto :eof
- ) else (
- set "fgme_wfile_bool="
- goto :eof
- )
- )
- :: Skip to time
- if not defined fgme_start_time (
- echo/
- echo/
- call :func_get_user_input fgme_start_time "Input: Optional: Enter the time capture starting point of video" "01:30"
- )
- :: fgme_duration_rate of gif
- if not defined fgme_duration_rate (
- echo/
- echo/
- call :func_get_user_input fgme_duration_rate "Input: Optional: Enter the desired duration for the gif" 2/3
- )
- :: Filter Setttings
- if not defined fgme_scale_image_base (
- echo/
- echo/
- call :func_get_user_input fgme_scale_image_base "Input: Optional: Enter the desired scale base [123,360,480,720,etc]" 360
- )
- :::::::::::::::::: :::::::::::::::::::
- :::::: ::::::
- :::::::::::::::: :::: :::::::::::::::::
- :: give it some lazlow and we are gtg
- if defined fgme_filters (
- set "fgme_filters=!fgme_filters!,select='not(mod(n,60))',setpts='N/17/TB',scale=-1:!fgme_scale_image_base!:flags=lanczos"
- ) else (
- set "fgme_filters=select='not(mod(n,60))',setpts='N/17/TB',scale=-1:!fgme_scale_image_base!:flags=lanczos"
- )
- :::::::::::::::::::::::::::::::::::::::
- ::: :::
- :: tyme fowda EphEphEm-Paegg ::
- ::: :::
- :::::::::::::::::::::::::::::::::::::::
- :: Call ffmpeg to do teh magic
- :: Palette and gif File Creation
- if exist "!fgme_output_file!" (
- if defined fgme_wfile_bool (
- call :func_set_sstime 5 60
- if not exist "!fgme_palette!" (
- call :func_ffm_palette
- )
- if exist "!fgme_palette!" (
- call :func_ffm_pfsrc_gfout
- ) else (
- call :func_ffm_nopf_gfout
- )
- )
- ) else (
- call :func_set_sstime 5 60
- if not exist "!fgme_palette!" (
- call :func_ffm_palette
- )
- if exist "!fgme_palette!" (
- call :func_ffm_pfsrc_gfout
- ) else (
- call :func_ffm_nopf_gfout
- )
- )
- :: k, thnx, bai
- if not defined fgme_keep_palette del /q /f "!fgme_palette!"
- if defined fgme_dpalette_dir del /q /f "!fgme_palette_dir!"
- :::::::::::::::::: :::::::::::::::::::
- :::::: ::::::
- :::::::::::::::: :::: :::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::
- :: ::
- :: Fin-Finito ::
- :: ::
- :::::::::::::::::::::::::::::::::::::::
- (for /f "tokens=1 delims==" %%a in ('set fgme_') do set "%%a=") 2>nul 1>nul
- endlocal
- goto :eof
- :::::::::::::::::: :::::::::::::::::::
- :::::: ::::::
- :::::::::::::::: :::: :::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::
- :: ::
- :: Functions ::
- :: ::
- :::::::::::::::::::::::::::::::::::::::
- rem Parses through this script and looks for the line numbers containing uniqueParseMessage, such as the call to the/a function
- rem When function encounters an error, it will clear the variable fgme_debug_line
- rem When function is called without a uniqueParseMessage, it will clear the variable fgme_debug_line and leave function
- :: Usage: func_dump_debug_line uniqueParseMessage
- :func_dump_debug_line
- if "%~1" equ "" (
- set "fgme_debug_line="
- goto :eof
- )
- set "fgme_debug_line="
- for /f "eol=- tokens=1 delims=[]" %%a in ('find /N %* "%~dpnx0"') do (
- if "%%~a" neq "" if defined fgme_debug_line (
- set "fgme_debug_line=!fgme_debug_line!,%%a"
- ) else (
- set "fgme_debug_line=%%a"
- )
- )
- goto :eof
- rem Prints messages from params 1 and 2 and dumps all script vars if param 3 is undef
- rem Examples -
- rem To dump all vars and not print other messages --
- rem func "" ""
- rem To print MsgHeader and MsgText without dumping Vars --
- rem func "INIT: " "Errorlevel is !errorlevel!" 0
- rem To print MsgText and dump all vars --
- rem func "get_fduration all vars"
- :: Usage :: func_dump_debug_msg MsgTextORHeaderText-Optional MsgText-Optional doNotDumpVarsFlag-Optional
- :func_dump_debug_msg
- if "%~3" equ "" if "%~1" equ "" goto :eof
- if "%~1" neq "" (
- if defined fgme_debug_dline (
- call :func_dump_debug_line %*
- )
- )
- if "%~1" neq "" (
- if defined fgme_debug_line (
- echo/ Debug: Line: [!fgme_debug_line!]: %~1%~2
- ) else (
- echo/ Debug: %~1%~2
- )
- )
- if "%~3" equ "" (
- if defined fgme_debug_line (
- call :func_dump_debug_vars "!fgme_debug_line!: "
- ) else (
- call :func_dump_debug_vars " "
- )
- )
- goto :eof
- :: Usage :: func_dump_debug_vars MsgOrHeaderText-Optional
- :func_dump_debug_vars
- set "_varCnt=0"
- for /f "tokens=1,* delims==" %%a in ('set fgme_ ') do (
- if "%%~a" neq "" (
- set /a "_varCnt+=1"
- echo/ Debug: %~1Variable[!_varCnt!]: [%%~a]: [%%~b]
- )
- )
- for /f "tokens=1,* delims==" %%a in ('set _fgme_') do (
- if "%%~a" neq "" (
- set /a "_varCnt+=1"
- echo/ Debug: %~1Variable[!_varCnt!]: [%%~a]: [%%~b]
- )
- )
- set "_varCnt="
- goto :eof
- rem Prompts User for input
- rem Quoted parameters optional, double-quotes will be dropped regardless, White-spaces ignored between params
- rem Example usage:
- rem func varUserFeedback "Input: User: Did you like %~nx0" "N/A"
- :: Usage :: func_get_user_input returnVar msgText-Optional defaultResponse-Optional
- :func_get_user_input
- if "%~1" equ "" (
- goto :eof
- )
- if "%~2" neq "" (
- echo/ %~2
- )
- if "%~3" neq "" (
- echo/ [Default: %~3]
- set "%~1=%~3"
- )
- set /p "%~1= ~> "
- goto :eof
- rem Prompts User for input, then calls func_bool_bistate to check booleans, returns 'true' otherwise unsets returnVar
- rem Quoted parameters optional, double-quotes will be dropped regardless, White-spaces ignored between params
- rem Example usage:
- rem func boolUserFileOverwrite "Input: User: Overwrite file Yes/No" "No"
- :: Usage :: func_get_bool_input returnVar msgText-Optional defaultResponse-Optional
- :func_get_bool_input
- if "%~1" equ "" goto :eof
- if "%~2" neq "" echo/ %~2
- if "%~3" neq "" echo/ [Default: %~3]
- set /p "%~1= -> "
- if not defined %~1 set "%~1=%~3"
- if "!%~1:~0,1!" equ "" (set "%~1=")
- if "!%~1:~0,1!" equ "1" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "y" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "p" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "a" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "t" (set "%~1=true") else (set "%~1=")
- goto :eof
- rem Gets video duration from file using ffmpeg
- rem Note - when encountering errors sets returnVar to 0
- rem Note - when function is called incorrectly does not set vars and leave func
- rem Note - Returns returnVar rounded to the nearest second
- :: Usage :: func_get_fduration returnVar "videoFile.ext"
- :func_get_fduration
- if "%~1" equ "" (goto :eof)
- if "%~2" equ "" (goto :eof)
- for /f "tokens=2 delims=, " %%d in ('call ffmpeg -i "%~2" 2^>^&1 ^| findstr /c:"Duration: "') do set "%~1=%%~d"
- rem var will cause problems if unset
- if "!%~1!" equ "" (
- set "%~1=0"
- goto :eof
- )
- rem strip out trailing zeros for batch calc not to confuse octal vs decimal
- set "%~1=!%~1::0=:!"
- for /f "tokens=1-4 delims=:." %%a in ("!%~1!") do (
- set "%~1=0"
- if "%%~a" neq "" (
- if %%a gtr 0 set /a "%~1+=%%~a * 3600"
- if %%b gtr 0 set /a "%~1+=%%~b * 60"
- if %%c gtr 0 set /a "%~1+=%%~c"
- if %%~d geq 50 set /a "%~1+=1"
- )
- )
- goto :eof
- rem From param2-sendTime, Returns param1-returnVar in seconds
- rem Note - when encountering errors sets returnVar to 0
- rem Note - when function is called incorrectly does not set vars and leave func
- rem Note - Returns returnVar rounded to the nearest second
- rem Accepted notations -
- rem HH:MM:SS.MS
- rem HH:MM:SS
- rem MM:SS.MS
- rem MM:SS
- rem SS.MS
- rem SS
- rem
- rem Examples -
- rem func "DurationInSecs" "01:11:54.71"
- rem func "DurationInSecs" "23:15.11"
- rem func "DurationInSecs" "11:55"
- rem func "DurationInSecs" "1.85"
- :: Usage :: func_get_secs_duration returnVar sendTime
- :func_get_secs_duration
- if "%~1" equ "" goto :eof
- if "%~2" equ "" goto :eof
- for /f "tokens=1,2 delims=." %%A in ("%~2") do (
- set "%~1=0"
- if "%%~B" equ "" if "%%~A" neq "" (
- for /f "tokens=1,2,3 delims=:" %%a in ("%%A") do (
- if "%%~c" equ "" if "%%~b" equ "" if "%%~a" neq "" (
- set /a "%~1+=%%~a"
- )
- if "%%~c" equ "" if "%%~b" neq "" (
- set /a "%~1+=%%~a * 60"
- set /a "%~1+=%%~b"
- )
- if "%%~c" neq "" (
- set /a "%~1+=%%~a * 3600"
- set /a "%~1+=%%~b * 60"
- set /a "%~1+=%%~c"
- )
- )
- )
- if "%%~B" neq "" if %%~B geq 50 (
- set /a "%~1+=1"
- )
- ) 2>nul
- if "!%~1!" equ "" (
- set "%~1=0"
- )
- goto :eof
- rem From param2-sendTime, Returns param1-returnVar in HH:MM:SS notation
- rem Note - Checks input validity except when param1 is missing
- rem Note - when encountering errors sets returnVar to 00:00:00
- rem Note - when function is called incorrectly does not set vars and leave func
- rem Example --- func "varDuration" "6430"
- rem func_get_time_from_secs returnVar sendTime
- :func_get_time_from_secs
- if "%~1" equ "" (goto :eof)
- if "%~2" equ "" (
- set "%~1=00:00:00"
- goto :eof
- )
- set /a "%~2*=1" 2>nul
- if !errorlevel! neq 0 (
- set "%~1=00:00:00"
- goto :eof
- )
- if not %~2 gtr 0 (
- set "%~1=00:00:00"
- goto :eof
- )
- rem calc and pad/strip zeros
- if %~2 lss 60 (
- set "%~1=00:00:%~2"
- ) else (
- set /a "_%~1h=%~2/3600"
- set /a "_%~1m=(%~2 - (!_%~1h! * 3600))/60"
- set /a "_%~1s=(%~2 - (!_%~1m! * 60) - (!_%~1h! * 3600))"
- if "!_%~1h:~0,2!" equ "!_%~1h!" (
- set "_%~1h=00!_%~1h!"
- set "_%~1h=!_%~1h:~-2!
- )
- set "_%~1m=00!_%~1m!"
- set "_%~1s=00!
- set "%~1=!_%~1h!:!_%~1m:~-2!:!_%~1s:~-2!"
- set "_%~1h="
- set "_%~1m="
- set "_%~1s="
- )
- if "!%~1!" equ "" set "%~1=00:00:00"
- goto :eof
- rem Checks to see if the value is "t","a","p","y" or "1" and sets returBoolVar to "true"
- rem Otherwise, unsets the var
- rem Case is ignored and White-spaces ignored between params
- rem Optional - Double Quoted parameters - double-quotes will be dropped regardless,
- rem Optional - Un-setting the var - var will be overwritten except when param1 is missing
- rem Optional - Un/Pre-setting the var - param1s value can be passed as param2 - "setTestValue-Optional"
- rem - When param2 is defined - before param1 is evaluated - overwrites/sets param1 with param2
- rem Example usage:
- rem func flag_overwrite "true"
- rem func flag_disable_state
- rem func_bool_bistate returBoolVar setTestValue-Optional
- :func_bool_bistate
- if "%~1" equ "" (goto :eof)
- if "%~2" neq "" (set "%~1=%~2")
- if "!%~1:~0,1!" equ "1" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "y" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "p" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "a" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "t" (set "%~1=true") else (set "%~1=")
- goto :eof
- rem Checks to see if the value is "t","a","p","y" or "1" and sets returBoolVar to "true"
- rem Checks to see if the value is "f","n" or "0" and sets returBoolVar to "false"
- rem Otherwise, unsets the var
- rem Case is ignored and White-spaces ignored between params
- rem Optional - Double Quoted parameters - double-quotes will be dropped regardless,
- rem Optional - Un-setting the var - var will be overwritten except when param1 is missing
- rem Optional - Un/Pre-setting the var - param1s value can be passed as param2 - "setTestValue-Optional"
- rem Example usage:
- rem func check_machine_status false
- rem func true
- rem func_bool_tristate returBoolVar setTestValue-Optional
- :func_bool_tristate
- if "%~1" equ "" (goto :eof)
- if "%~2" neq "" (set "%~1=%~2")
- if "!%~1:~0,1!" equ "0" (set "%~1=false")
- if /i "!%~1:~0,1!" equ "n" (set "%~1=false")
- if /i "!%~1:~0,1!" equ "f" (set "%~1=false"
- goto :eof)
- if "!%~1:~0,1!" equ "1" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "y" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "p" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "a" (set "%~1=true")
- if /i "!%~1:~0,1!" equ "t" (set "%~1=true"
- goto :eof) else (set "%~1=")
- goto :eof
- rem Cleans up MSOffice AutoFsckYou character swaps when coppie/pasta and etc.
- rem Example usage:
- rem func "UserInputVar"
- rem func_fix_funky_chars Send-Return-var
- :func_fix_funky_chars
- if "%~1" equ "" goto :eof
- if "!%~1: = !" neq "!%~1!" (
- set "%~1=!%~1: = !"
- )
- if "!%~1:–=-!" neq "!%~1!" (
- set "%~1=!%~1:–=-!"
- )
- if "!%~1:“="!" neq "!%~1!" (
- set "%~1=!%~1:“="!"
- )
- if "!%~1:”="!" neq "!%~1!" (
- set "%~1=!%~1:”="!"
- )
- goto :eof
- rem Gets, checks and compares Skip_Start_Time with Total_File_Duration.
- rem When total is less than start+Pad, sets start to 1 or newTime-Optional
- rem Example -- func 5 60
- rem Example -- func "" 90
- rem func_set_sstime newTime-Optional padTimeSecs-Optional
- :func_set_sstime
- call :func_get_fduration "_fgme_fdur" "!fgme_input_file!"
- call :func_get_secs_duration "_fgme_stm" "!fgme_start_time!"
- if "%~1" neq "" (
- call :func_get_secs_duration _fgme_stmSecsOne "%~1"
- call :func_get_time_from_secs _fgme_stmStdOne "%~1"
- )
- if "%~2" neq "" (
- call :func_get_secs_duration _fgme_stmSecsPTwo "%~2"
- if defined _fgme_stmSecsPTwo (
- set /a "_fgme_stm+=!_fgme_stm!"
- ) else (
- set /a "_fgme_stm+=%~2"
- )
- )
- if !_fgme_fdur! leq !_fgme_stm! (
- if "%~1" neq "" (
- if %~1 geq 10 (
- call :func_get_time_from_secs _fgme_stm "%~1"
- set "fgme_start_time=!_fgme_stm!"
- ) else (
- set "fgme_start_time=00:00:%~1"
- )
- ) else (
- set "fgme_start_time=00:00:01"
- )
- )
- set "_fgme_stm="
- set "_fgme_fdur="
- goto :eof
- rem Duration Time Multiplier to decrease palette creation time
- rem Note: Multiplier Default is 10 - unless a valid setMultiplierValue-Optional is passed
- rem Note: When currentRateValue is less than zero, it's considered as zero
- rem Note: setMultiplierValue-Optional valid values are a positive number or an equation.
- rem -- processed in OOP -- ((equationORvalue) + 1)
- rem Note: Predefined returnVar
- rem when number - multiplier is added to it
- rem when string - treated as undefined
- rem when mixed - preceeding numbers are used
- rem func_calc_fast_palette returBoolVar currentRateValue setMultiplierValue-Optional
- :func_calc_fast_palette
- if "%~1" equ "" goto :eof
- if "%~2" equ "" goto :eof
- set /a "%~1*=1"
- if "%~3" neq "" (
- set /a "%~1+=(( %~3 ) + 1) * (( %~2 ) + 1)"
- ) else (
- set /a "%~1+=( 10 ) * (( %~2 ) + 1)"
- )
- goto :eof
- rem echo/ Info: Create Palette: [Dir:!fgme_palette_dir!] [File:!fgme_palette_name!]
- rem test params -metadata "JIF=%~nx0,JIF_CREATED_ON=!Date! !time!"
- :func_ffm_palette
- set "fmge_palette_rate=!fgme_duration_rate!"
- call :func_calc_fast_palette fmge_palette_rate !fgme_duration_rate! 100
- if "!fgme_duration_rate:~0,2!" neq "!fmge_palette_rate:~0,2!" (
- echo/ Info: Create Palette: Faster Mode: [!fgme_palette_name!]
- ) else (
- echo/ Info: Create Palette: Normal Mode: [!fgme_palette_name!]
- )
- call ffmpeg -an -sn -dn -v warning -ss !fgme_start_time! -i "!fgme_input_file!" -filter_complex "!fgme_filters!, palettegen=stats_mode=diff" -r !fmge_palette_rate! -y "!fgme_palette!"
- if not errorlevel 0 (
- echo/ Error: Create Palette: Removing "!fgme_palette_name!"
- if exist "!fgme_palette_name!" del /q "!fgme_palette_name!"
- )
- goto :eof
- :func_ffm_nopf_gfout
- echo/ Info: Create Gif w/o Palette file: [!fgme_output_fname!]
- call ffmpeg -an -sn -dn -v warning -ss !fgme_start_time! -i "!fgme_input_file!" -vf "!fgme_filters!" -r !fgme_duration_rate! -y "!fgme_output_file!"
- goto :eof
- :func_ffm_pfsrc_gfout
- echo/ Info: Create Gif with Palette file: [!fgme_output_fname!]
- call ffmpeg -an -sn -dn -v warning -ss !fgme_start_time! -i "!fgme_input_file!" -i "!fgme_palette!" -filter_complex "!fgme_filters!,paletteuse" -r !fgme_duration_rate! -y "!fgme_output_file!"
- goto :eof
Advertisement