1iJaCk

ffmpeg_gifme.bat

Mar 19th, 2017
363
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 25.30 KB | None | 0 0
  1. :: 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.
  2. ::
  3. :: 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"
  4. ::
  5. ::  Over-Engineered Mauch? Naw... *waves jedi/witcher hand signs* There is no script...  
  6. ::  Its ugly? You Dont say... Even a mother loves her ugly-ass turdling.
  7. ::
  8. @echo off && setlocal EnableDelayedExpansion && (for /f "tokens=1 delims==" %%a in ('set fgme_') do set "%%a=") 2>nul 1>nul
  9.  
  10. :: Setting Script Parameters to Variables
  11. set "fgme_input_file=%~1"
  12. set "fgme_output_file=%~2"
  13. set "fgme_palette_file=%~3"
  14.  
  15. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  16. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  17. ::::::                                                                ::::::
  18.  ::::                        Development Version                       ::::
  19.  ::::                       USE AT YOUR OWN RISK                       ::::
  20. ::::::                                                                ::::::
  21. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  22. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  23.  
  24.  
  25. :::::::::::::::::::::::::::::::::::::::
  26. :::                                 :::
  27. ::             User Vars             ::
  28. ::           User Settings           ::
  29. :::                                 :::
  30. :::::::::::::::::::::::::::::::::::::::
  31.  
  32. :: Hard Coded User Settings
  33. :: - if Not Set, script will prompt
  34. set "fgme_start_time=01:30"         rem :: Default: 01:30 --- Description: starting time offset - ffmpeg will skip this duration before processing
  35. set "fgme_duration_rate=2/3"        rem :: Default:   2/3 --- Description: Total duration of each frame in the gif that is to be created
  36. set "fgme_scale_image_base=360"     rem :: Default:   360 --- Description: base width of the output file -- Height will be auto-magiclly calculated
  37. 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
  38. 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
  39. 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
  40.  
  41. ::::::::::::::::::  :::::::::::::::::::
  42. ::::::                           ::::::
  43. :::::::::::::::: :::: :::::::::::::::::
  44.  
  45.  
  46.  
  47. :::::::::::::::::::::::::::::::::::::::
  48. :::                                 :::
  49. ::            Script Vars            ::
  50. ::          Script Settings          ::
  51. :::                                 :::
  52. :::::::::::::::::::::::::::::::::::::::
  53.  
  54. :: Notes on Usage
  55. ::  -Default: Not Set --- This means that the default setting was/is: empty, blank, null, nil, undefined
  56. ::  -Default: false; Type: Boolean  --- When var is undefined it is still [false]. Being undefined, the boolean function will consider it [false]
  57. ::  -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.
  58. ::     False States:  [undefined]   : no; false; 0;
  59. ::     True States: [defined=>true] : yes; true; 1; pass;
  60. ::
  61.  
  62.  
  63. 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
  64. set "fgme_palette_dir=palette\"
  65.  
  66. rem :: Default: Not Set --- Type: String  --- Required: Optional :: Description: when set, uses set file name.  When unset, uses: video-filename.png
  67. set "fgme_palette_name="
  68.  
  69. rem :: Default: false   --- Type: Boolean --- Required: Optional :: Description: when true, palette file is not deleted after use.
  70. set "fgme_keep_palette=true"
  71.  
  72. rem :: Default: true    --- Type: Boolean --- Required: Optional :: Description: Increases the rate value ten-fold to increase creation.
  73. set "fgme_fast_palette=true"
  74.  
  75. rem :: Default: false   --- Type: Boolean --- Required: Optional :: Description: makes sure not to overwrite already created files
  76. set "fgme_wfilelock_bool="
  77.  
  78. 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]
  79. set "fgme_filters="
  80.  
  81. rem Default: Not Set    --- Type: String  --- Required: Optional :: Description: specific settings for ffmpeg gif muxer
  82. rem Accepts:
  83. rem    -loop         0  --- Number of times to loop the output: -1 - no loop, 0 - infinite loop. From -1 to 65535
  84. rem    -final_delay -1  --- Force delay, in centiseconds, after the last frame. From -1 to 65535
  85. set "fgme_ffmpeg_gifOpt="
  86.  
  87. rem :: Default: true    --- Type: Boolean --- Required: Optional :: Description: when true, line numbers will be dumped for debug messages.
  88. set "fgme_debug_dline=true"
  89.  
  90. ::::::::::::::::::  :::::::::::::::::::
  91. ::::::                           ::::::
  92. :::::::::::::::: :::: :::::::::::::::::
  93.  
  94.  
  95.  
  96. :::::::::::::::::::::::::::::::::::::::
  97. :::                                 :::
  98. ::          Prompt for input         ::
  99. :::                                 :::
  100. :::::::::::::::::::::::::::::::::::::::
  101.  
  102. :: Input the dam file... please
  103. if defined fgme_input_filev if not defined fgme_input_file set "fgme_input_file=!fgme_input_filev!"
  104.  
  105. if not defined fgme_input_file call :func_get_user_input "fgme_input_file" "Input: Enter Video file [and relative path if needed]"
  106.  
  107. if not exist "!fgme_input_file!" (
  108.     echo/ Error: Unable to locate Input file !fgme_input_file!
  109.     goto :eof
  110. )
  111.  
  112.  
  113. :: drop the out file on the var... NOW
  114. if not defined fgme_output_file if defined fgme_output_filev (
  115.     set "fgme_output_file=!fgme_output_filev!"
  116. ) else (
  117.     call :func_get_user_input fgme_output_file "Input: Enter Output file name [and outpath path if needed]"
  118.     if defined fgme_output_file set "fgme_output_file=!fgme_output_file:"=!"
  119.     echo/
  120. )
  121.  
  122.  
  123. :: I hope this palette is to you palettes liking  -- Making the external, internal
  124. if defined fgme_palette_filev if not defined fgme_palette_file set "fgme_palette_file=!fgme_palette_filev!"
  125. if defined fgme_palette_file for %%P in ("!fgme_palette_file!") do (
  126.     set "fgme_palette_dir=%%~dpP"
  127.     set "fgme_palette_name=%%~nxP"
  128.     if "%%~xP" equ "" set "fgme_palette_name=%%~nP.png"
  129. )
  130.  
  131.  
  132. :: Did someone order a pallet of palettes -- oh well, to temp you go...
  133. rem If we created the dir successfully then set remove bool
  134. if defined fgme_palette_dir (
  135.     if not exist "!fgme_palette_dir!" (
  136.         echo/    Info: Creating dir: "!fgme_palette_dir!"
  137.        
  138.         mkdir "!fgme_palette_dir!"
  139.         if !errorlevel! equ 0 if not defined fgme_keep_palette (
  140.             set "fgme_dpalette_dir=true"
  141.         )
  142.     )
  143. ) else (
  144.     set "fgme_palette_dir=%temp%"
  145.     set "fgme_dpalette_dir="
  146. )
  147.  
  148.  
  149.  
  150. if defined fgme_palette_name (
  151.     set "fgme_palette=!fgme_palette_dir!\!fgme_palette_name!"
  152. ) else (
  153.     for /f "tokens=1* delims=" %%z in ("!fgme_input_file!") do (
  154.         if "%%~n" neq "" (
  155.             set "fgme_palette_name=%%~nz.png"
  156.             set "fgme_palette=!fgme_palette_dir!\!fgme_palette_name!"
  157.         )
  158.     )
  159. )
  160.  
  161.  
  162. :: out from in -- maybe
  163. if not defined fgme_output_file (
  164.     for /f "tokens=1* delims=" %%z in ("!fgme_input_file!") do (
  165.         if "%%~n" neq "" set "fgme_output_file=%%~dpnz.gif"
  166.     )
  167.    
  168.     if defined fgme_output_file (
  169.         echo/
  170.         echo/ - Info: Self Defined Output File name: !fgme_output_file!
  171.         echo/
  172.     ) else (
  173.         echo/
  174.         echo/ - Error: Unble to auto define Output file and one has not been defined
  175.         echo/
  176.         goto :eof
  177.     )
  178. )
  179.  
  180. :: Strip path to just the name to print purdy
  181. :: Verify extension is gif
  182. for /f "tokens=1* delims=" %%Z in ("!fgme_output_file!") do (
  183.     if "%%~xZ" neq ".gif" (
  184.         set "fgme_output_fname=%%~nxZ.gif"
  185.         set "fgme_output_file=%%~Z.gif"
  186.     ) else (
  187.         set "fgme_output_fname=%%~nZ.gif"
  188.     )
  189. )
  190.  
  191. if not defined fgme_output_fname set "fgme_output_fname=!fgme_output_file!"
  192.  
  193.  
  194. :: Over-Right [unlike over-left]
  195. if exist "!fgme_output_file!" (
  196.     echo/
  197.     echo/
  198.     echo/ - Warning: File Already Exits
  199.  
  200.     if not defined fgme_wfilelock_bool (
  201.         call :func_get_bool_input "fgme_wfile_bool" "Input: User: Overwrite file [Yes/No]" "No"
  202.         if not defined fgme_wfile_bool goto :eof
  203.     ) else (
  204.         set "fgme_wfile_bool="
  205.         goto :eof
  206.     )
  207. )
  208.  
  209. :: Skip to time
  210. if not defined fgme_start_time (
  211.     echo/
  212.     echo/
  213.     call :func_get_user_input fgme_start_time  "Input: Optional: Enter the time capture starting point of video"   "01:30"
  214. )
  215.  
  216. :: fgme_duration_rate of gif
  217. if not defined fgme_duration_rate (
  218.     echo/
  219.     echo/
  220.     call :func_get_user_input fgme_duration_rate  "Input: Optional: Enter the desired duration for the gif"   2/3
  221. )
  222.  
  223. :: Filter Setttings
  224. if not defined fgme_scale_image_base (
  225.     echo/
  226.     echo/
  227.     call :func_get_user_input fgme_scale_image_base "Input: Optional: Enter the desired scale base [123,360,480,720,etc]"   360
  228. )
  229.  
  230.  
  231. ::::::::::::::::::  :::::::::::::::::::
  232. ::::::                           ::::::
  233. :::::::::::::::: :::: :::::::::::::::::
  234.  
  235. :: give it some lazlow and we are gtg
  236. if defined fgme_filters (
  237.     set "fgme_filters=!fgme_filters!,select='not(mod(n,60))',setpts='N/17/TB',scale=-1:!fgme_scale_image_base!:flags=lanczos"
  238. ) else (
  239.     set "fgme_filters=select='not(mod(n,60))',setpts='N/17/TB',scale=-1:!fgme_scale_image_base!:flags=lanczos"
  240. )
  241.  
  242.  
  243. :::::::::::::::::::::::::::::::::::::::
  244. :::                                 :::
  245. ::     tyme fowda EphEphEm-Paegg     ::
  246. :::                                 :::
  247. :::::::::::::::::::::::::::::::::::::::
  248.  
  249.  
  250. :: Call ffmpeg to do teh magic
  251. :: Palette and gif File Creation
  252. if exist "!fgme_output_file!" (
  253.     if defined fgme_wfile_bool (
  254.         call :func_set_sstime 5 60
  255.  
  256.         if not exist "!fgme_palette!" (
  257.             call :func_ffm_palette
  258.         )
  259.        
  260.         if exist "!fgme_palette!" (
  261.             call :func_ffm_pfsrc_gfout
  262.         ) else (
  263.             call :func_ffm_nopf_gfout
  264.         )
  265.     )
  266. ) else (
  267.     call :func_set_sstime 5 60
  268.    
  269.     if not exist "!fgme_palette!" (
  270.         call :func_ffm_palette
  271.     )
  272.    
  273.     if exist "!fgme_palette!" (
  274.         call :func_ffm_pfsrc_gfout
  275.     ) else (
  276.         call :func_ffm_nopf_gfout
  277.     )
  278. )
  279.  
  280.  
  281. :: k, thnx, bai
  282. if not defined fgme_keep_palette del /q /f "!fgme_palette!"
  283.  
  284. if defined fgme_dpalette_dir del /q /f "!fgme_palette_dir!"
  285.  
  286. ::::::::::::::::::  :::::::::::::::::::
  287. ::::::                           ::::::
  288. :::::::::::::::: :::: :::::::::::::::::
  289.  
  290. :::::::::::::::::::::::::::::::::::::::
  291. ::                                   ::
  292. ::        Fin-Finito                 ::
  293. ::                                   ::
  294. :::::::::::::::::::::::::::::::::::::::
  295.  
  296. (for /f "tokens=1 delims==" %%a in ('set fgme_') do set "%%a=") 2>nul 1>nul
  297. endlocal
  298. goto :eof
  299.  
  300. ::::::::::::::::::  :::::::::::::::::::
  301. ::::::                           ::::::
  302. :::::::::::::::: :::: :::::::::::::::::
  303.  
  304. :::::::::::::::::::::::::::::::::::::::
  305. ::                                   ::
  306. ::         Functions                 ::
  307. ::                                   ::
  308. :::::::::::::::::::::::::::::::::::::::
  309.  
  310.  
  311.  
  312. rem Parses through this script and looks for the line numbers containing uniqueParseMessage, such as the call to the/a function
  313. rem   When function encounters an error, it will clear the variable fgme_debug_line
  314. rem   When function is called without a uniqueParseMessage, it will clear the variable fgme_debug_line and leave function
  315.  
  316. :: Usage: func_dump_debug_line    uniqueParseMessage
  317. :func_dump_debug_line
  318. if "%~1" equ "" (
  319.     set "fgme_debug_line="
  320.     goto :eof
  321. )
  322.  
  323. set "fgme_debug_line="
  324. for /f "eol=- tokens=1 delims=[]" %%a in ('find /N %* "%~dpnx0"') do (
  325.     if "%%~a" neq "" if defined fgme_debug_line (
  326.         set "fgme_debug_line=!fgme_debug_line!,%%a"
  327.     ) else (
  328.         set "fgme_debug_line=%%a"
  329.     )
  330. )
  331.  
  332. goto :eof
  333.  
  334.  
  335.  
  336. rem Prints messages from params 1 and 2 and dumps all script vars if param 3 is undef
  337. rem  Examples -
  338. rem    To dump all vars and not print other messages --
  339. rem      func   "" ""
  340.  
  341. rem    To print MsgHeader and MsgText without dumping Vars --
  342. rem      func   "INIT: " "Errorlevel is !errorlevel!"  0
  343.      
  344. rem    To print MsgText and dump all vars --
  345. rem      func   "get_fduration all vars"
  346.  
  347. :: Usage :: func_dump_debug_msg  MsgTextORHeaderText-Optional   MsgText-Optional   doNotDumpVarsFlag-Optional
  348. :func_dump_debug_msg
  349. if "%~3" equ "" if "%~1" equ "" goto :eof
  350.  
  351. if "%~1" neq "" (
  352.     if defined fgme_debug_dline (
  353.         call :func_dump_debug_line %*
  354.     )
  355. )
  356.    
  357. if "%~1" neq "" (
  358.     if defined fgme_debug_line (
  359.         echo/    Debug: Line: [!fgme_debug_line!]: %~1%~2
  360.     ) else (
  361.         echo/    Debug: %~1%~2
  362.     )
  363. )
  364.  
  365. if "%~3" equ "" (
  366.     if defined fgme_debug_line (
  367.         call :func_dump_debug_vars "!fgme_debug_line!: "
  368.     ) else (
  369.         call :func_dump_debug_vars " "
  370.     )
  371. )
  372.  
  373. goto :eof
  374.  
  375.  
  376. :: Usage :: func_dump_debug_vars   MsgOrHeaderText-Optional
  377. :func_dump_debug_vars
  378. set "_varCnt=0"
  379.  
  380. for /f "tokens=1,* delims==" %%a in ('set fgme_ ') do (
  381.     if "%%~a" neq "" (
  382.         set /a "_varCnt+=1"
  383.         echo/    Debug: %~1Variable[!_varCnt!]: [%%~a]: [%%~b]
  384.     )
  385. )
  386.  
  387. for /f "tokens=1,* delims==" %%a in ('set _fgme_') do (
  388.     if "%%~a" neq "" (
  389.         set /a "_varCnt+=1"
  390.         echo/    Debug: %~1Variable[!_varCnt!]: [%%~a]: [%%~b]
  391.     )
  392. )
  393.  
  394. set "_varCnt="
  395. goto :eof
  396.  
  397.  
  398.  
  399. rem  Prompts User for input
  400. rem    Quoted parameters optional, double-quotes will be dropped regardless, White-spaces ignored between params
  401. rem    Example usage:
  402. rem      func   varUserFeedback   "Input: User: Did you like %~nx0"   "N/A"
  403.  
  404. :: Usage :: func_get_user_input  returnVar   msgText-Optional   defaultResponse-Optional
  405. :func_get_user_input
  406. if "%~1" equ "" (
  407.     goto :eof
  408. )
  409.  
  410. if "%~2" neq "" (
  411.     echo/ %~2
  412. )
  413.  
  414. if "%~3" neq "" (
  415.     echo/   [Default: %~3]
  416.     set "%~1=%~3"
  417. )
  418.  
  419. set /p "%~1= ~> "
  420.  
  421. goto :eof
  422.  
  423.  
  424.  
  425. rem  Prompts User for input, then calls func_bool_bistate to check booleans, returns 'true' otherwise unsets returnVar
  426. rem    Quoted parameters optional, double-quotes will be dropped regardless, White-spaces ignored between params
  427. rem    Example usage:
  428. rem      func   boolUserFileOverwrite    "Input: User: Overwrite file Yes/No"   "No"
  429.  
  430. :: Usage :: func_get_bool_input  returnVar   msgText-Optional   defaultResponse-Optional
  431. :func_get_bool_input
  432. if "%~1" equ "" goto :eof
  433. if "%~2" neq "" echo/ %~2
  434. if "%~3" neq "" echo/   [Default: %~3]
  435.  
  436. set /p "%~1= -> "
  437.  
  438. if not defined %~1 set "%~1=%~3"
  439.  
  440. if "!%~1:~0,1!" equ "" (set "%~1=")
  441. if "!%~1:~0,1!" equ "1" (set "%~1=true")
  442. if /i "!%~1:~0,1!" equ "y" (set "%~1=true")
  443. if /i "!%~1:~0,1!" equ "p" (set "%~1=true")
  444. if /i "!%~1:~0,1!" equ "a" (set "%~1=true")
  445. if /i "!%~1:~0,1!" equ "t" (set "%~1=true") else (set "%~1=")
  446.  
  447. goto :eof
  448.  
  449.  
  450.  
  451. rem Gets video duration from file using ffmpeg
  452. rem  Note - when encountering errors sets returnVar to 0
  453. rem  Note - when function is called incorrectly does not set vars and leave func
  454. rem  Note - Returns returnVar rounded to the nearest second
  455.  
  456. :: Usage :: func_get_fduration returnVar "videoFile.ext"
  457. :func_get_fduration
  458. if "%~1" equ "" (goto :eof)
  459. if "%~2" equ "" (goto :eof)
  460.  
  461. for /f "tokens=2 delims=, " %%d in ('call ffmpeg -i "%~2" 2^>^&1 ^| findstr /c:"Duration: "') do set "%~1=%%~d"
  462.  
  463. rem var will cause problems if unset
  464. if "!%~1!" equ "" (
  465.     set "%~1=0"
  466.     goto :eof
  467. )
  468.  
  469. rem strip out trailing zeros for batch calc not to confuse octal vs decimal
  470. set "%~1=!%~1::0=:!"
  471.  
  472. for /f "tokens=1-4 delims=:." %%a in ("!%~1!") do (
  473.     set "%~1=0"
  474.     if "%%~a" neq "" (
  475.         if %%a gtr 0 set /a "%~1+=%%~a * 3600"
  476.         if %%b gtr 0 set /a "%~1+=%%~b * 60"
  477.         if %%c gtr 0 set /a "%~1+=%%~c"
  478.         if %%~d geq 50 set /a "%~1+=1"
  479.     )
  480. )
  481.  
  482. goto :eof
  483.  
  484.  
  485.  
  486. rem From param2-sendTime, Returns param1-returnVar in seconds
  487. rem  Note - when encountering errors sets returnVar to 0
  488. rem  Note - when function is called incorrectly does not set vars and leave func
  489. rem  Note - Returns returnVar rounded to the nearest second
  490. rem  Accepted notations -
  491. rem   HH:MM:SS.MS
  492. rem   HH:MM:SS
  493. rem   MM:SS.MS
  494. rem   MM:SS
  495. rem   SS.MS
  496. rem   SS
  497. rem
  498. rem  Examples -
  499. rem    func  "DurationInSecs" "01:11:54.71"
  500. rem    func  "DurationInSecs" "23:15.11"
  501. rem    func  "DurationInSecs" "11:55"
  502. rem    func  "DurationInSecs" "1.85"
  503.  
  504. :: Usage :: func_get_secs_duration returnVar  sendTime
  505. :func_get_secs_duration
  506. if "%~1" equ "" goto :eof
  507. if "%~2" equ "" goto :eof
  508.  
  509. for /f "tokens=1,2 delims=." %%A in ("%~2") do (
  510.     set "%~1=0"
  511.  
  512.     if "%%~B" equ "" if "%%~A" neq "" (
  513.         for /f "tokens=1,2,3 delims=:" %%a in ("%%A") do (
  514.             if "%%~c" equ "" if "%%~b" equ "" if "%%~a" neq "" (
  515.                 set /a "%~1+=%%~a"
  516.             )
  517.  
  518.             if "%%~c" equ "" if "%%~b" neq "" (
  519.                 set /a "%~1+=%%~a * 60"
  520.                 set /a "%~1+=%%~b"
  521.             )
  522.  
  523.             if "%%~c" neq "" (
  524.                 set /a "%~1+=%%~a * 3600"
  525.                 set /a "%~1+=%%~b * 60"
  526.                 set /a "%~1+=%%~c"
  527.             )
  528.         )
  529.     )
  530.    
  531.     if "%%~B" neq "" if %%~B geq 50 (
  532.         set /a "%~1+=1"
  533.     )
  534. ) 2>nul
  535.  
  536. if "!%~1!" equ "" (
  537.     set "%~1=0"
  538. )
  539.  
  540. goto :eof
  541.  
  542.  
  543. rem From param2-sendTime, Returns param1-returnVar in HH:MM:SS notation
  544. rem  Note - Checks input validity except when param1 is missing
  545. rem  Note - when encountering errors sets returnVar to 00:00:00
  546. rem  Note - when function is called incorrectly does not set vars and leave func
  547. rem   Example --- func  "varDuration" "6430"
  548.  
  549. rem func_get_time_from_secs returnVar  sendTime
  550. :func_get_time_from_secs
  551. if "%~1" equ "" (goto :eof)
  552.  
  553. if "%~2" equ "" (
  554.     set "%~1=00:00:00"
  555.     goto :eof
  556. )
  557.  
  558. set /a "%~2*=1" 2>nul
  559. if !errorlevel! neq 0 (
  560.     set "%~1=00:00:00"
  561.     goto :eof
  562. )
  563.  
  564. if not %~2 gtr 0 (
  565.     set "%~1=00:00:00"
  566.     goto :eof
  567. )
  568.  
  569. rem calc and pad/strip zeros
  570. if %~2 lss 60 (
  571.     set "%~1=00:00:%~2"
  572. ) else (
  573.     set /a "_%~1h=%~2/3600"
  574.     set /a "_%~1m=(%~2 - (!_%~1h! * 3600))/60"
  575.     set /a "_%~1s=(%~2 - (!_%~1m! * 60) - (!_%~1h! * 3600))"
  576.  
  577.     if "!_%~1h:~0,2!" equ "!_%~1h!" (
  578.         set "_%~1h=00!_%~1h!"
  579.         set "_%~1h=!_%~1h:~-2!
  580.     )
  581.     set "_%~1m=00!_%~1m!"
  582.     set "_%~1s=00!
  583.  
  584.     set "%~1=!_%~1h!:!_%~1m:~-2!:!_%~1s:~-2!"
  585.  
  586.     set "_%~1h="
  587.     set "_%~1m="
  588.     set "_%~1s="
  589. )
  590.  
  591.  
  592. if "!%~1!" equ "" set "%~1=00:00:00"
  593.  
  594. goto :eof
  595.  
  596.  
  597.  
  598. rem  Checks to see if the value is "t","a","p","y" or "1" and sets returBoolVar to "true"
  599. rem  Otherwise, unsets the var
  600. rem  Case is ignored and White-spaces ignored between params
  601. rem    Optional - Double Quoted parameters - double-quotes will be dropped regardless,
  602. rem    Optional - Un-setting the var - var will be overwritten except when param1 is missing
  603. rem    Optional - Un/Pre-setting the var - param1s value can be passed as param2 - "setTestValue-Optional"
  604. rem             - When param2 is defined - before param1 is evaluated - overwrites/sets param1 with param2
  605. rem    Example usage:
  606. rem      func  flag_overwrite   "true"
  607. rem      func  flag_disable_state
  608.  
  609. rem func_bool_bistate  returBoolVar   setTestValue-Optional
  610. :func_bool_bistate
  611. if "%~1" equ "" (goto :eof)
  612.  
  613. if "%~2" neq "" (set "%~1=%~2")
  614.  
  615. if "!%~1:~0,1!" equ "1" (set "%~1=true")
  616. if /i "!%~1:~0,1!" equ "y" (set "%~1=true")
  617. if /i "!%~1:~0,1!" equ "p" (set "%~1=true")
  618. if /i "!%~1:~0,1!" equ "a" (set "%~1=true")
  619. if /i "!%~1:~0,1!" equ "t" (set "%~1=true") else (set "%~1=")
  620.  
  621. goto :eof
  622.  
  623.  
  624.  
  625. rem  Checks to see if the value is "t","a","p","y" or "1" and sets returBoolVar to "true"
  626. rem  Checks to see if the value is "f","n" or "0" and sets returBoolVar to "false"
  627. rem  Otherwise, unsets the var
  628. rem  Case is ignored and White-spaces ignored between params
  629. rem    Optional - Double Quoted parameters - double-quotes will be dropped regardless,
  630. rem    Optional - Un-setting the var - var will be overwritten except when param1 is missing
  631. rem    Optional - Un/Pre-setting the var - param1s value can be passed as param2 - "setTestValue-Optional"
  632. rem    Example usage:
  633. rem      func  check_machine_status   false
  634. rem      func     true
  635.  
  636. rem func_bool_tristate  returBoolVar   setTestValue-Optional
  637. :func_bool_tristate
  638. if "%~1" equ "" (goto :eof)
  639.  
  640. if "%~2" neq "" (set "%~1=%~2")
  641.  
  642. if "!%~1:~0,1!" equ "0" (set "%~1=false")
  643. if /i "!%~1:~0,1!" equ "n" (set "%~1=false")
  644. if /i "!%~1:~0,1!" equ "f" (set "%~1=false"
  645. goto :eof)
  646.  
  647. if "!%~1:~0,1!" equ "1" (set "%~1=true")
  648. if /i "!%~1:~0,1!" equ "y" (set "%~1=true")
  649. if /i "!%~1:~0,1!" equ "p" (set "%~1=true")
  650. if /i "!%~1:~0,1!" equ "a" (set "%~1=true")
  651. if /i "!%~1:~0,1!" equ "t" (set "%~1=true"
  652. goto :eof) else (set "%~1=")
  653.  
  654. goto :eof
  655.  
  656.  
  657.  
  658. rem  Cleans up MSOffice AutoFsckYou character swaps when coppie/pasta and etc.
  659. rem    Example usage:
  660. rem      func   "UserInputVar"
  661.  
  662. rem func_fix_funky_chars   Send-Return-var
  663. :func_fix_funky_chars
  664. if "%~1" equ "" goto :eof
  665.  
  666. if "!%~1:   = !" neq "!%~1!" (
  667.     set "%~1=!%~1:  = !"
  668.     )
  669. if "!%~1:–=-!" neq "!%~1!" (
  670.     set "%~1=!%~1:–=-!"
  671.     )
  672. if "!%~1:“="!" neq "!%~1!" (
  673.     set "%~1=!%~1:“="!"
  674.     )
  675. if "!%~1:”="!" neq "!%~1!" (
  676.     set "%~1=!%~1:”="!"
  677.     )
  678.  
  679. goto :eof
  680.  
  681.  
  682. rem Gets, checks and compares Skip_Start_Time with Total_File_Duration.  
  683. rem When total is less than start+Pad, sets start to 1 or newTime-Optional
  684. rem  Example -- func 5 60
  685. rem  Example -- func "" 90
  686.  
  687. rem func_set_sstime newTime-Optional  padTimeSecs-Optional
  688. :func_set_sstime
  689. call :func_get_fduration "_fgme_fdur" "!fgme_input_file!"
  690. call :func_get_secs_duration "_fgme_stm" "!fgme_start_time!"
  691.  
  692. if "%~1" neq "" (
  693.     call :func_get_secs_duration _fgme_stmSecsOne "%~1"
  694.     call :func_get_time_from_secs _fgme_stmStdOne "%~1"
  695. )
  696.  
  697. if "%~2" neq "" (
  698.     call :func_get_secs_duration _fgme_stmSecsPTwo "%~2"
  699.     if defined _fgme_stmSecsPTwo (
  700.         set /a "_fgme_stm+=!_fgme_stm!"
  701.     ) else (
  702.         set /a "_fgme_stm+=%~2"
  703.     )
  704. )
  705.  
  706. if !_fgme_fdur! leq !_fgme_stm! (
  707.     if "%~1" neq "" (
  708.         if %~1 geq 10 (
  709.             call :func_get_time_from_secs _fgme_stm "%~1"
  710.             set "fgme_start_time=!_fgme_stm!"
  711.         ) else (
  712.             set "fgme_start_time=00:00:%~1"
  713.         )
  714.     ) else (
  715.         set "fgme_start_time=00:00:01"
  716.     )
  717. )
  718.  
  719. set "_fgme_stm="
  720. set "_fgme_fdur="
  721.  
  722. goto :eof
  723.  
  724.  
  725. rem  Duration Time Multiplier to decrease palette creation time
  726.  
  727. rem  Note: Multiplier Default is 10 - unless a valid setMultiplierValue-Optional is passed
  728. rem  Note: When currentRateValue is less than zero, it's considered as zero
  729.  
  730. rem  Note: setMultiplierValue-Optional valid values are a positive number or an equation.
  731. rem    -- processed in OOP -- ((equationORvalue) + 1)
  732.  
  733. rem  Note: Predefined returnVar
  734. rem    when  number  - multiplier is added to it
  735. rem    when  string  - treated as undefined
  736. rem    when   mixed  - preceeding numbers are used
  737.  
  738. rem func_calc_fast_palette   returBoolVar   currentRateValue   setMultiplierValue-Optional
  739. :func_calc_fast_palette
  740. if "%~1" equ "" goto :eof
  741. if "%~2" equ "" goto :eof
  742.  
  743. set /a "%~1*=1"
  744.  
  745. if "%~3" neq "" (
  746.     set /a "%~1+=(( %~3 ) + 1) * (( %~2 ) + 1)"
  747. ) else (
  748.     set /a "%~1+=(     10    ) * (( %~2 ) + 1)"
  749. )
  750.  
  751. goto :eof
  752.  
  753.  
  754.  
  755. rem echo/  Info: Create Palette: [Dir:!fgme_palette_dir!] [File:!fgme_palette_name!]
  756. rem test params -metadata "JIF=%~nx0,JIF_CREATED_ON=!Date! !time!"
  757. :func_ffm_palette
  758. set "fmge_palette_rate=!fgme_duration_rate!"
  759.  
  760. call :func_calc_fast_palette   fmge_palette_rate   !fgme_duration_rate!   100
  761.  
  762. if "!fgme_duration_rate:~0,2!" neq "!fmge_palette_rate:~0,2!" (
  763.     echo/  Info: Create Palette:  Faster Mode: [!fgme_palette_name!]
  764. ) else (
  765.     echo/  Info: Create Palette:  Normal Mode: [!fgme_palette_name!]
  766. )
  767.  
  768. 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!"
  769. if not errorlevel 0 (
  770.     echo/  Error: Create Palette: Removing "!fgme_palette_name!"
  771.     if exist "!fgme_palette_name!" del /q "!fgme_palette_name!"
  772. )
  773.  
  774.  
  775.  
  776. goto :eof
  777.  
  778.  
  779.  
  780. :func_ffm_nopf_gfout
  781. echo/  Info: Create Gif w/o  Palette file: [!fgme_output_fname!]
  782. 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!"
  783.  
  784. goto :eof
  785.  
  786.  
  787.  
  788. :func_ffm_pfsrc_gfout
  789. echo/  Info: Create Gif with Palette file: [!fgme_output_fname!]
  790. 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!"
  791.  
  792. goto :eof
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment