Last active
September 14, 2018 22:15
-
-
Save retorillo/856fcbfbb3d29108ffe322274b11927b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| REM This snippet can concat many TS files up to 9999 (1.ts - 9999.ts) | |
| REM NOTE: `ffmpeg -i "concat:[too many files]"` will fail | |
| @echo off | |
| setlocal enabledelayedexpansion | |
| set skipped_files= | |
| ( | |
| for /f %%f in ('dir /b *.ts') do ( | |
| set num=%%~nf | |
| set elif=1 | |
| set NaN=0 | |
| for /f "delims=0123456789" %%a in ("!num!") do set NaN=1 | |
| if !NaN! equ 0 ( | |
| if !elif! equ 1 if !num! lss 10 set "num=000!num!" && set elif=0 | |
| if !elif! equ 1 if !num! lss 100 set "num=00!num!" && set elif=0 | |
| if !elif! equ 1 if !num! lss 1000 set "num=0!num!" && set elif=0 | |
| echo !num!:%%f | |
| ) | |
| if !NaN! equ 1 ( | |
| set skipped_files=!skipped_files!%%f | |
| ) | |
| ) | |
| ) > files | |
| set "first=" | |
| ( | |
| for /f "delims=: tokens=2" %%a in ('type files ^| sort') do ( | |
| if "!first!" equ "" set first=%%a | |
| echo %%a | |
| ) | |
| ) > sorted_files | |
| :eof | |
| set /a in_num=0 | |
| set /a out_num=0 | |
| set in_files= | |
| set out_files= | |
| for /f %%f in (sorted_files) do ( | |
| if "!in_files!" neq "" set in_files=!in_files!^|%%f | |
| if "!in_files!" equ "" set in_files=%%f | |
| set /a in_num+=1 | |
| if !in_num! gtr 1000 call :out | |
| ) | |
| if !in_num! gtr 0 call :out | |
| ffmpeg -i "concat:!out_files!" -c copy concat.ts | |
| echo files skipped: !skipped_files! | |
| goto :end | |
| :out | |
| echo !in_files! | |
| set /a out_num+=1 | |
| set /a in_num=0 | |
| set outf=c!out_num!.ts | |
| ffmpeg -y -i "concat:!in_files!" -c copy "!outf!" | |
| set in_files= | |
| if "!out_files!" neq "" set out_files=!out_files!^| | |
| set out_files=!out_files!!outf! | |
| :end | |
| endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment