Skip to content

Instantly share code, notes, and snippets.

@nico-lab
Last active March 16, 2018 21:10
Show Gist options
  • Save nico-lab/8863041 to your computer and use it in GitHub Desktop.
Save nico-lab/8863041 to your computer and use it in GitHub Desktop.
comskip_vdr_to_ffmpeg_cut_and_concat
@echo off
set VIDEO="video.ts"
set MEDIAINFO="MediaInfo.exe"
set FFMPEG="ffmpeg.exe"
%FFMPEG% -analyzeduration 100M -probesize 100M -i %VIDEO% -acodec copy -vn %VIDEO%.aac
set time1=%1
set sec0=%time1:~-5,-3%
rem %sec0:~0,1%
if %sec0:~0,1% equ 0 (
set time1=%sec0:~1,1%%time1:~-2%
) else (
set time1=%sec0:~0,2%%time1:~-2%
)
set time2=%2
set /A msec=%time2:~-8,-6%*60*100
set sec0=%time2:~-5,-3%
if %sec0:~0,1% equ 0 (
set sec=%sec0:~1,1%%time2:~-2%
) else (
set sec=%sec0:~0,2%%time2:~-2%
)
set /A time2=%msec%+%sec%
set /A opd=%time2%-6000-%time1%
%FFMPEG% -analyzeduration 100M -probesize 100M -ss %1 -i %VIDEO% -t %opd:~0,-2%.%opd:~-2% -copyinkf -vcodec copy -an %VIDEO%1.ts
set time3=%3
set /A msec=%time3:~-8,-6%*60*100
set sec0=%time3:~-5,-3%
if %sec0:~0,1% equ 0 (
set sec=%sec0:~1,1%%time3:~-2%
) else (
set sec=%sec0:~0,2%%time3:~-2%
)
set /A time3=%msec%+%sec%
echo %time3%
set /A apd=%time3%-6000-%time2%
%FFMPEG% -analyzeduration 100M -probesize 100M -ss %2 -i %VIDEO% -t %apd:~0,-2%.%apd:~-2% -copyinkf -vcodec copy -an %VIDEO%2.ts
set time4=%4
set /A msec=%time4:~-8,-6%*60*100
set sec0=%time4:~-5,-3%
rem %sec0:~0,1%
if %sec0:~0,1% equ 0 (
set sec=%sec0:~1,1%%time4:~-2%
) else (
set sec=%sec0:~0,2%%time4:~-2%
)
set /A time4=%msec%+%sec%
echo %time4%
set /A bpd=%time4%-%time3%
%FFMPEG% -analyzeduration 100M -probesize 100M -ss %3 -i %VIDEO% -t %bpd:~0,-2%.%bpd:~-2% -copyinkf -vcodec copy -an %VIDEO%3.ts
set /A time5=%time4%+6000
echo %time5%
echo %time5:~0,-2%.%time5:~-2%
%FFMPEG% -analyzeduration 100M -probesize 100M -ss %time5:~0,-2%.%time5:~-2% -i %VIDEO% -t 15 -copyinkf -vcodec copy -an %VIDEO%4.ts
%FFMPEG% -analyzeduration 100M -probesize 100M -i %VIDEO%1.ts 2> %VIDEO%1.txt
%FFMPEG% -analyzeduration 100M -probesize 100M -i %VIDEO%2.ts 2> %VIDEO%2.txt
%FFMPEG% -analyzeduration 100M -probesize 100M -i %VIDEO%3.ts 2> %VIDEO%3.txt
%FFMPEG% -analyzeduration 100M -probesize 100M -i %VIDEO%4.ts 2> %VIDEO%4.txt
for /f "tokens=2 delims= " %%a in ('FIND "Duration" %VIDEO%1.txt') do set Duration=%%a
set Duration=%Duration:,=%
set opdm=%Duration:~1%
for /f "tokens=2 delims= " %%a in ('FIND "Duration" %VIDEO%2.txt') do set Duration=%%a
set Duration=%Duration:,=%
set apdm=%Duration:~1%
for /f "tokens=2 delims= " %%a in ('FIND "Duration" %VIDEO%3.txt') do set Duration=%%a
set Duration=%Duration:,=%
set bpdm=%Duration:~1%
for /f "tokens=2 delims= " %%a in ('FIND "Duration" %VIDEO%4.txt') do set Duration=%%a
set Duration=%Duration:,=%
set cpdm=%Duration:~1%
ffmpeg -analyzeduration 100M -probesize 100M -i %VIDEO%.aac -ss %1 -t %opdm% -acodec copy -vn %VIDEO%1.aac
ffmpeg -analyzeduration 100M -probesize 100M -i %VIDEO%.aac -ss %2 -t %apdm% -acodec copy -vn %VIDEO%2.aac
ffmpeg -analyzeduration 100M -probesize 100M -i %VIDEO%.aac -ss %3 -t %bpdm% -acodec copy -vn %VIDEO%3.aac
ffmpeg -analyzeduration 100M -probesize 100M -i %VIDEO%.aac -ss %time5:~0,-2%.%time5:~-2% -t %cpdm% -acodec copy -vn %VIDEO%4.aac
ffmpeg -i concat:"%VIDEO%1.ts|%VIDEO%2.ts|%VIDEO%3.ts|%VIDEO%4.ts" -i concat:"%VIDEO%1.aac|%VIDEO%2.aac|%VIDEO%3.aac|%VIDEO%4.aac" -c copy %VIDEO%5.ts
if %5 equ 1 (
del %VIDEO%1.txt
del %VIDEO%2.txt
del %VIDEO%3.txt
del %VIDEO%4.txt
del %VIDEO%1.ts
del %VIDEO%2.ts
del %VIDEO%3.ts
del %VIDEO%4.ts
del %VIDEO%.aac
del %VIDEO%1.aac
del %VIDEO%2.aac
del %VIDEO%3.aac
del %VIDEO%4.aac
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment