-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniFiExporterWindows.cmd
133 lines (111 loc) · 4.72 KB
/
UniFiExporterWindows.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@echo off
setlocal EnableDelayedExpansion
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::: Make edits according to your setup and needs under this line ::::::::::
set ExportDirectory=C:\Users\username\VideoStorage\Export
set 8db88c62-7fd0-3737-aa4e-dae19bab87ea=cam1
set 245faecc-8b37-36dc-8f7b-f5097d30bc63=cam2
set GenerateListOnly=No
set ExportToday=No
set ScheduleDailyExecution=No
set ScheduleTime="03:00"
:::::::::: Make edits according to your setup and needs above this line ::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if /I "%ScheduleDailyExecution%"=="yes" (
schtasks /QUERY /TN "UniFiExporter" >NUL 2>&1 || schtasks /CREATE /RU "SYSTEM" /SC DAILY /TN "UniFiExporter" /TR '%0' /ST %ScheduleTime%
)
if not exist "%~dp0UniFiExporterFiles" mkdir "%~dp0UniFiExporterFiles"
if not exist "%~dp0UniFiExporterFiles\Log" mkdir "%~dp0UniFiExporterFiles\Log"
if not exist "%~dp0UniFiExporterFiles\Temp" mkdir "%~dp0UniFiExporterFiles\Temp"
if not exist "%~dp0UniFiExporterFiles\Temp\List" mkdir "%~dp0UniFiExporterFiles\Temp\List"
if not exist "%ExportDirectory%" mkdir "%ExportDirectory%"
if not exist "%~dp0UniFiExporterFiles\ffmpeg-4.4-essentials_build" (
echo(
echo Downloading FFMPEG...
timeout 5 >NUL
bitsadmin.exe /TRANSFER FFmpegDownloadJob /DOWNLOAD /PRIORITY FOREGROUND https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip "%~dp0UniFiExporterFiles\Temp\ffmpeg-release-essentials.zip"
echo(
echo Unpacking FFMPEG...
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%~dp0UniFiExporterFiles\Temp\ffmpeg-release-essentials.zip', '%~dp0UniFiExporterFiles'); }"
del "%~dp0UniFiExporterFiles\Temp\ffmpeg-release-essentials.zip"
)
set current_date="%date:~10,4%-%date:~4,2%-%date:~7,2%"
echo(
echo Renaming chunks...
for /D %%I in ("%~dp0????????-????-????-????-????????????") do (
for /D %%J in ("%%I\????") do (
for /D %%K in ("%%J\??") do (
for /D %%L in ("%%K\??") do (
cd "%%L"
ren *.mp4 *.ts
)
)
)
)
del /Q "%~dp0UniFiExporterFiles\Temp\List\*.*"
echo(
echo Generating list of files...
for /D %%I in ("%~dp0????????-????-????-????-????????????") do (
for /D %%J in ("%%I\????") do (
for /D %%K in ("%%J\??") do (
for /D %%L in ("%%K\??") do (
for %%M in ("%%~fL\*.ts") do (
if not "!%%~nI!"=="" (
echo file '%%M' >> "%~dp0UniFiExporterFiles\Temp\List\%%~nJ-%%~nK-%%~nL-!%%~nI!.txt"
)
)
)
)
)
)
if /I "%ExportToday%"=="no" (
if exist "%~dp0UniFiExporterFiles\Temp\List\%current_date%-*" (
del /Q "%~dp0UniFiExporterFiles\Temp\List\%current_date%-*"
)
)
if /I "%GenerateListOnly%"=="yes" (
for /R "%~dp0UniFiExporterFiles\Temp\List" %%G in (*.txt) do (
copy /Y nul "%~dp0UniFiExporterFiles\Log\%%~nG.txt" >nul
)
echo(
echo Renaming chunks back...
echo(
for /D %%I in ("%~dp0????????-????-????-????-????????????") do (
for /D %%J in ("%%I\????") do (
for /D %%K in ("%%J\??") do (
for /D %%L in ("%%K\??") do (
cd "%%L"
ren *.ts *.mp4
)
)
)
)
endlocal
exit /B
)
echo(
for /R "%~dp0UniFiExporterFiles\Temp\List" %%G in (*.txt) do (
if not exist "%~dp0UniFiExporterFiles\Log\%%~nG.txt" (
echo Processing %%~nG...
"%~dp0UniFiExporterFiles\ffmpeg-4.4-essentials_build\bin\ffmpeg.exe" -y -hide_banner -loglevel panic -stats -f concat -safe 0 -i "%~dp0UniFiExporterFiles\Temp\List\%%~nG.txt" -c copy "%~dp0UniFiExporterFiles\Temp\%%~nG.ts"
"%~dp0UniFiExporterFiles\ffmpeg-4.4-essentials_build\bin\ffmpeg.exe" -y -hide_banner -loglevel panic -stats -i "%~dp0UniFiExporterFiles\Temp\%%~nG.ts" -c copy -movflags +faststart "%~dp0UniFiExporterFiles\Temp\%%~nG.mp4"
move /Y "%~dp0UniFiExporterFiles\Temp\%%~nG.mp4" "%ExportDirectory%\%%~nG.mp4"
del /Q "%~dp0UniFiExporterFiles\Temp\%%~nG.ts"
copy /Y nul "%~dp0UniFiExporterFiles\Log\%%~nG.txt" >nul
echo(
)
)
echo Renaming chunks back...
echo(
for /D %%I in ("%~dp0????????-????-????-????-????????????") do (
for /D %%J in ("%%I\????") do (
for /D %%K in ("%%J\??") do (
for /D %%L in ("%%K\??") do (
cd "%%L"
ren *.ts *.mp4
)
)
)
)
endlocal
exit /B