Skip to content

Instantly share code, notes, and snippets.

@nico-lab
Last active August 29, 2015 13:56
Show Gist options
  • Save nico-lab/8953286 to your computer and use it in GitHub Desktop.
Save nico-lab/8953286 to your computer and use it in GitHub Desktop.
@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 opad=%time2%-12000-%time1%
%FFMPEG% -analyzeduration 100M -probesize 100M -ss %1 -i %VIDEO% -t %opad:~0,-2%.%opad:~-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%
set /A bpd=%time3%-%time2%
%FFMPEG% -analyzeduration 100M -probesize 100M -ss %2 -i %VIDEO% -t %bpd:~0,-2%.%bpd:~-2% -copyinkf -vcodec copy -an %VIDEO%2.ts
set /A time4=%time3%+9000
%FFMPEG% -analyzeduration 100M -probesize 100M -ss %time4:~0,-2%.%time4:~-2% -i %VIDEO% -t 30 -copyinkf -vcodec copy -an %VIDEO%3.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
for /f "tokens=2 delims= " %%a in ('FIND "Duration" %VIDEO%1.txt') do set Duration=%%a
set Duration=%Duration:,=%
set opadm=%Duration:~1%
for /f "tokens=2 delims= " %%a in ('FIND "Duration" %VIDEO%2.txt') do set Duration=%%a
set Duration=%Duration:,=%
set bpdm=%Duration:~1%
for /f "tokens=2 delims= " %%a in ('FIND "Duration" %VIDEO%3.txt') do set Duration=%%a
set Duration=%Duration:,=%
set cpdm=%Duration:~1%
ffmpeg -i %VIDEO%.aac -ss %1 -t %opadm% -acodec copy -vn %VIDEO%1.aac
ffmpeg -i %VIDEO%.aac -ss %2 -t %bpdm% -acodec copy -vn %VIDEO%2.aac
ffmpeg -i %VIDEO%.aac -ss %time4:~0,-2%.%time4:~-2% -t %cpdm% -acodec copy -vn %VIDEO%3.aac
ffmpeg -i concat:"%VIDEO%1.ts|%VIDEO%2.ts|%VIDEO%3.ts" -i concat:"%VIDEO%1.aac|%VIDEO%2.aac|%VIDEO%3.aac" -c copy %VIDEO%4.ts
if %4 equ 1 (
del %VIDEO%1.txt
del %VIDEO%2.txt
del %VIDEO%3.txt
del %VIDEO%1.ts
del %VIDEO%2.ts
del %VIDEO%3.ts
del %VIDEO%.aac
del %VIDEO%1.aac
del %VIDEO%2.aac
del %VIDEO%3.aac
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment