Skip to content

Commit

Permalink
v3.1
Browse files Browse the repository at this point in the history
Validation of digits in the frame counter
Frame counter detection after delimiter feature
A bit more restructuring
Gif fps fix
  • Loading branch information
keerah committed Feb 20, 2023
1 parent 7d7b0c5 commit bceab03
Show file tree
Hide file tree
Showing 45 changed files with 528 additions and 570 deletions.
15 changes: 10 additions & 5 deletions sendtoffmpeg_encoder01.cmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
REM This is one of the SenTo FFmpeg modular transcoders, keep it with the rest of the files
REM v3.05
REM v3.1

ECHO ----------------------------------------------------------------------------------------
ECHO %divline%
ECHO SendTo FFmpeg encoder v3.1 by Keerah
ECHO %wset.hline1%
IF NOT "[%wset.hline2%]"=="[]" ECHO %wset.hline2%
ECHO %wset.hline3%
ECHO %divline%
ECHO %argCount% files queued to encode

FOR /L %%i IN (1,1,%argCount%) DO (

ECHO ----------------------------------------------------------------------------------------
ECHO %divline%

SET "vlen="
FOR /F "tokens=* delims=" %%f IN ('call "%ffpath%ffprobe.exe" -v error -show_entries "format=duration" -of "default=noprint_wrappers=1:nokey=1" "!argFile[%%i].name!"') DO SET "vlen=%%f"
Expand Down Expand Up @@ -100,6 +105,6 @@ FOR /L %%i IN (1,1,%argCount%) DO (
)

endlocal
ECHO ----------------------------------------------------------------------------------------
ECHO %divline%
ECHO SERVED
ECHO ----------------------------------------------------------------------------------------
ECHO %divline%
102 changes: 77 additions & 25 deletions sendtoffmpeg_encoder02.cmd
Original file line number Diff line number Diff line change
@@ -1,64 +1,116 @@
REM This is one of the SenTo FFmpeg modular transcoders, keep it with the rest of the files
REM v3.05
REM v3.1

ECHO ----------------------------------------------------------------------------------------
ECHO %divline%
ECHO SendTo FFmpeg encoder v3.1 by Keerah
ECHO %wset.hline1%
IF NOT "[%wset.hline2%]"=="[]" ECHO %wset.hline2%
ECHO %wset.hline3%
ECHO %divline%
ECHO %argCount% files queued to encode

FOR /L %%i IN (1,1,%argCount%) DO (

ECHO ----------------------------------------------------------------------------------------
ECHO %divline%

SET "vlen="
FOR /F "tokens=* delims=" %%f IN ('call "%ffpath%ffprobe.exe" -v error -show_entries "format=duration" -of "default=noprint_wrappers=1:nokey=1" "!argFile[%%i].name!"') DO SET "vlen=%%f"

IF !vlen! == N/A (
ECHO The source is a single image file with no length

ECHO The source is a single image file with no length
SET "wset.audiocomp="

IF !imgseq! GTR 0 (
REM detecting image sequence
IF !frcounter! GTR 0 (
REM detecting the counter in the end of the filename
SET "basename=!argFile[%%i].trname:~0,-%frcounter%!"
SET "countername=!argFile[%%i].trname:~-%frcounter%!"
FOR /F "tokens=* delims=0" %%N IN ("!countername!") DO SET /A frnumber=%%N
IF !frnumber! GTR 0 (
REM overwrite default framerate setting with the preset's one
SET /A fps=%wset.fps%
SET "argFile[%%i].name=!argFile[%%i].path!!basename!%%0!frcounter!d!argFile[%%i].ext!"
ECHO Image sequence detected
ECHO Basename: "!basename!" Start frame: !frnumber! Pattern: "!basename!%%0!frcounter!d"
SET "wset.seqfr=-framerate %fps% -start_number !frnumber! -pattern_type sequence"
REM No audio assumed
SET "wset.audiocomp="

SET "middelim="
SET /A frnumber=-1
SET "zer="
FOR /L %%I IN (1,1,%frcounter%) DO SET "zer=!zer!0"

IF !countername!==!zer! (
REM Zero frame
SET /A frnumber=0
) ELSE (
REM Validating frame number
SET "ddet="
FOR /F "delims=0123456789" %%I IN ("!countername!") DO SET ddet=%%i

IF defined ddet (
ECHO The last %frcounter% symbols of the filename is not a number

IF NOT [%frdelim%] == [] (
REM Now let's try to use delimiter
FOR /f "tokens=1-3 delims=%frdelim%" %%A in ("!argFile[%%i].trname!") do (
SET "beforedelim=%%A"
SET "middelim=%%B"
SET "afterdelim=%%C"
)
REM Limiting the counter. Lazy way, will consider string length calculation in future to get all digits
SET "middelimtr=!middelim:~0,%frcounter%!"

REM Validating frame number
SET "ddet="
FOR /F "delims=0123456789" %%I IN ("!middelimtr!") DO SET ddet=%%i
IF defined ddet (
ECHO No frame number after delimiter found. No sequence assumed
) ELSE (
ECHO Image sequence detected. Frame number after delimiter "%frdelim%". Digits:%frcounter%
REM Removing leading zeroes (if any)
FOR /F "tokens=* delims=0" %%N IN ("!middelimtr!") DO SET "frnumbername=%%N"
SET /A "frnumber=!frnumbername!"
)
)
) ELSE (
ECHO Image sequence detected. Frame number at the end of the filename. Digits:%frcounter%
REM Removing leading zeroes (if any)
FOR /F "tokens=* delims=0" %%N IN ("!countername!") DO SET "frnumbername=%%N"
SET /A "frnumber=!frnumbername!"
)
)

IF !frnumber! GTR -1 (
IF [!middelim!] == [] (
REM Constructing the pattern in the end of the name
SET "argFile[%%i].name=!argFile[%%i].path!!basename!%%0%frcounter%d!argFile[%%i].ext!"
ECHO Basename:"!basename!" Start frame:!frnumber! Pattern:"!basename!%%0%frcounter%d"
) ELSE (
REM Constructing the pattern after the delimiter
REM !!! Needs a fix if middelim was trimmed to frcounter = add the trimmed part to filename!!!
IF !middelim! == !middelimtr! (SET "midsfx=") ELSE (SET midsfx=!middelim:~%frcounter%!)
SET "argFile[%%i].name=!argFile[%%i].path!!beforedelim!%frdelim%%%0%frcounter%d!midsfx!%frdelim%!afterdelim!!argFile[%%i].ext!"
ECHO Basename:"!beforedelim!" Start frame:!frnumber! Pattern:"!beforedelim!%frdelim%%%0%frcounter%d!midsfx!%frdelim%!afterdelim!"
)
SET /A fps=!wset.fps!
SET "wset.seqfr=-framerate !fps! -start_number !frnumber! -pattern_type sequence"
ECHO The source and output FPS synced to !fps!
) ELSE (
REM No sequence, no pattern
SET "wset.seqfr="
SET "wset.seqfrout="
)
) ELSE (
REM detecting the counter after first found dot
REM No implementation yet
)
) ELSE (
SET "wset.seqfr="
SET "wset.seqfrout="
)
) ELSE (
echo Video length is: !vlen! seconds
ECHO Video length is: !vlen! seconds
)

ECHO Encoding file %%i of %argCount%
ECHO STAGE 1: Generating a palette
"%ffpath%ffmpeg.exe" !wset.params! !wset.seqfr! -i "!argFile[%%i].name!" !wset.prepass! !wset.seqfrout! -y "!argFile[%%i].trname!"palette.png

ECHO ----------------------------------------------------------------------------------------
ECHO %divline%
ECHO Encoding file %%i of %argCount%
ECHO STAGE 2: Encoding to Gif using the generatied palette
"%ffpath%ffmpeg.exe" !wset.params! !wset.seqfr! -i "!argFile[%%i].name!" -i "!argFile[%%i].trname!"palette.png !wset.videocomp! !wset.over! "!argFile[%%i].trname!"!wset.suff!

IF EXIST "!argFile[%%i].trname!palette.png" DEL /s "!argFile[%%i].trname!palette.png" > nul
)

ECHO ----------------------------------------------------------------------------------------
ECHO %divline%
ECHO SERVED
ECHO ----------------------------------------------------------------------------------------
ECHO %divline%
6 changes: 6 additions & 0 deletions sendtoffmpeg_settings.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ REM It will aslo be used for the framerate of Gifs generated from sequences
SET /A imgseq=1
REM Consider image sequences
REM if 0 then ffmpeg won't look for image sequences even if the selected file is a part of one
REM When this option is on, be cautios if the files you specified are part of a sequence(s),
REM each of them can be encoded into a separate video then.

SET /A frcounter=4
REM Frame counter digits
Expand All @@ -51,3 +53,7 @@ SET "frdelim=."
REM Framecounter delimiter (separation symbol)
REM After the code fails to find frame numbers in the end of the filename, it will try
REM to find the first delimiter symbol and detect if there's frame number after it.
REM Set this to "frdelim=" (empty string) if you do not want this detection to run.

SET "divline=-----------------------------------------------------------------------------------------------"
REM Divider string used for UI
29 changes: 16 additions & 13 deletions to APNG forever loop.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,22 @@ FOR %%f IN (%*) DO (
)

IF %argCount% LEQ 0 (
ECHO -----------------------------------------------------------------------------------
ECHO %divline%
ECHO NO FILE^(S^) SPECIFIED
GOTO :End
)

ECHO -----------------------------------------------------------------------------------
ECHO SendTo FFmpeg encoder v3.0 by Keerah
ECHO Preset: APNG plain, loop forever

SET "cmdp=%~dp0"
SET "argp=%~dp1"

REM get settings
IF EXIST "%argp%sendtoffmpeg_settings.cmd" (
CALL "%argp%sendtoffmpeg_settings.cmd"
ECHO Settings: *LOCAL*, Verbosity: !vbl!
SET "wset.hline3=Settings: *LOCAL*, Verbosity: !vbl!"
) ELSE (
IF EXIST "%cmdp%sendtoffmpeg_settings.cmd" (
CALL "%cmdp%sendtoffmpeg_settings.cmd"
ECHO Settings: Global, Verbosity: !vbl!
SET "wset.hline3=Settings: Global, Verbosity: !vbl!"
) ELSE (
ECHO ! Sorry, the sendtoffmpeg_settings.cmd is unreacheable. Unable to continue!
GOTO :End
Expand All @@ -48,23 +44,30 @@ IF NOT EXIST "%ffpath%ffmpeg.exe" (


REM compression settings
SET "wset.hline1=ECHO Preset: APNG plain, loop forever"
SET "wset.params=-v %vbl% -hide_banner -stats"
SET "wset.videocomp=-f apng -plays 0"
SET "wset.audiocomp="
IF %quietover% == 1 (SET "wset.over=-y") ELSE (SET "wset.over=")
IF %dscr% GTR 0 (SET "wset.dscr=_animpng") ELSE (SET "wset.dscr=")
SET "wset.suff=!wset.dscr!.png"

ECHO -----------------------------------------------------------------------------------
ECHO %divline%
ECHO SendTo FFmpeg encoder v3.1 by Keerah
ECHO %wset.hline1%
IF NOT "[%wset.hline2%]"=="[]" ECHO %wset.hline2%
ECHO %wset.hline3%
ECHO %divline%
ECHO %argCount% files queued to encode


FOR /L %%i IN (1,1,%argCount%) DO (

ECHO -----------------------------------------------------------------------------------
ECHO %divline%

FOR /F "tokens=* delims=" %%f IN ('call "%ffpath%ffprobe.exe" -v error -show_entries "format=duration" -of "default=noprint_wrappers=1:nokey=1" "!argFile[%%i].name!"') DO SET "vlen=%%f"

IF !vlen! NEQ "N/A" (
IF !vlen! == N/A (
ECHO The source is a single image file with no length

IF !imgseq! GTR 0 (
Expand Down Expand Up @@ -100,9 +103,9 @@ FOR /L %%i IN (1,1,%argCount%) DO (
"%ffpath%ffmpeg.exe" !wset.params! !seqfr! -i "!argFile[%%i].name!" !wset.videocomp! !wset.audiocomp! !seqfrout! !wset.over! "!argFile[%%i].trname!"!wset.suff!
)

ECHO -----------------------------------------------------------------------------------
ECHO SERVED
ECHO -----------------------------------------------------------------------------------
ECHO %divline%
ECHO SERVED
ECHO %divline%

:End
if %pse% GTR 0 PAUSE
21 changes: 9 additions & 12 deletions to CUDA h264 mp4 420 10Mbit aac128.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@ FOR %%f IN (%*) DO (
SET "argFile[!argCount!].path=%%~dpf"
)

IF %argCount% LEQ 0 (
ECHO ----------------------------------------------------------------------------------------
ECHO NO FILE^(S^) SPECIFIED
GOTO :End
)

ECHO ----------------------------------------------------------------------------------------
ECHO SendTo FFmpeg encoder v3.0 by Keerah
ECHO Preset: h264 mp4 CUDA 420, slow, 10 Mbps, kf 2 sec, Audio aac128

SET "cmdp=%~dp0"
SET "argp=%~dp1"

REM get settings
IF EXIST "%argp%sendtoffmpeg_settings.cmd" (
CALL "%argp%sendtoffmpeg_settings.cmd"
ECHO Settings: *LOCAL*, Verbosity: !vbl!
SET "wset.hline3=Settings: *LOCAL*, Verbosity: !vbl!"
) ELSE (
IF EXIST "%cmdp%sendtoffmpeg_settings.cmd" (
CALL "%cmdp%sendtoffmpeg_settings.cmd"
ECHO Settings: Global, Verbosity: !vbl!
SET "wset.hline3=Settings: Global, Verbosity: !vbl!"
) ELSE (
ECHO ! Sorry, the sendtoffmpeg_settings.cmd is unreacheable. Unable to continue!
GOTO :End
)
)

IF %argCount% LEQ 0 (
ECHO %divline%
ECHO NO FILE^(S^) SPECIFIED
GOTO :End
)

REM Check for ffmpeg
IF NOT EXIST "%ffpath%ffmpeg.exe" (
ECHO ! Sorry, the path to ffmpeg.exe is unreacheable. Unable to continue!
Expand All @@ -48,6 +44,7 @@ IF NOT EXIST "%ffpath%ffmpeg.exe" (


REM compression settings
SET "wset.hline1=Preset: h264 mp4 CUDA 420, slow, 10 Mbps, kf 2 sec, Audio aac128"
SET "wset.params=-v %vbl% -hide_banner -stats"
SET "wset.videocomp=-c:v h264_nvenc -preset slow -b:v 10M -pix_fmt yuv420p -force_key_frames 0:00:02"
REM The output video will have keyframes each 2 seconds due to -force_key_frames 0:00:02
Expand Down
21 changes: 9 additions & 12 deletions to CUDA h264 mp4 420 10Mbit copy.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@ FOR %%f IN (%*) DO (
SET "argFile[!argCount!].path=%%~dpf"
)

IF %argCount% LEQ 0 (
ECHO ----------------------------------------------------------------------------------------
ECHO NO FILE^(S^) SPECIFIED
GOTO :End
)

ECHO ----------------------------------------------------------------------------------------
ECHO SendTo FFmpeg encoder v3.0 by Keerah
ECHO Preset: h264 mp4 CUDA 420, slow, 10 Mbps, kf 2 sec, Audio copy

SET "cmdp=%~dp0"
SET "argp=%~dp1"

REM get settings
IF EXIST "%argp%sendtoffmpeg_settings.cmd" (
CALL "%argp%sendtoffmpeg_settings.cmd"
ECHO Settings: *LOCAL*, Verbosity: !vbl!
SET "wset.hline3=Settings: *LOCAL*, Verbosity: !vbl!"
) ELSE (
IF EXIST "%cmdp%sendtoffmpeg_settings.cmd" (
CALL "%cmdp%sendtoffmpeg_settings.cmd"
ECHO Settings: Global, Verbosity: !vbl!
SET "wset.hline3=Settings: Global, Verbosity: !vbl!"
) ELSE (
ECHO ! Sorry, the sendtoffmpeg_settings.cmd is unreacheable. Unable to continue!
GOTO :End
)
)

IF %argCount% LEQ 0 (
ECHO %divline%
ECHO NO FILE^(S^) SPECIFIED
GOTO :End
)

REM Check for ffmpeg
IF NOT EXIST "%ffpath%ffmpeg.exe" (
ECHO ! Sorry, the path to ffmpeg.exe is unreacheable. Unable to continue!
Expand All @@ -48,6 +44,7 @@ IF NOT EXIST "%ffpath%ffmpeg.exe" (


REM compression settings
SET "wset.hline1=Preset: h264 mp4 CUDA 420, slow, 10 Mbps, kf 2 sec, Audio copy"
SET "wset.params=-v %vbl% -hide_banner -stats"
SET "wset.videocomp=-c:v h264_nvenc -preset slow -b:v 10M -pix_fmt yuv420p -force_key_frames 0:00:02"
REM The output video will have keyframes each 2 seconds due to -force_key_frames 0:00:02
Expand Down
Loading

0 comments on commit bceab03

Please sign in to comment.