52

小米摄像头视频文件批量合并处理脚本

 3 years ago
source link: https://zedex.cn/8334.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

小米摄像头视频文件批量合并处理脚本

小米摄像头的视频记录文件是每分钟保存成一个文件的,后期存档和查看很不方便,对此,我编写了几个小脚本方便自动化的处理其原始视频文件。

思路如下:

  1. 遍历审查所有视频/截图内容,删除不必要的文件
  2. 创建待处理清单
  3. 利用ffmpeg压缩所有文件

具体脚本如下:

1. 导出监控,有两种方式:
方式1:通过小米监控摄像头的NAS同步设置
方式2:手工同步:需要每次在APP中设置 推出储存卡,然后手工取下存储卡,并通过 读卡器,将视频和截图文件保存到电脑上

方式1更方便,但是没有图片截图,后面审查工作会比较费时间,可以通过批处理来生成缩略图:

for /f "delims=" %%i in ('dir *.mp4 /b /s') do (ffmpeg -v quiet -y -i %%i -ss 1 -f image2 %%i.jpeg)

2. 遍历审查所有视频/截图内容,审查完后删除当前文件夹下及所有子目录下的jpeg图片来删除缩略图,命令如下:

del /f /s /q *.jpeg

3. 创建待处理清单:

dir /s /b > files.lst

4. 增加文件头尾辅助字符,以符合ffmpeg的待处理文件清单格式:

@echo off
cd /d "%~dp0"
set "fd=temp"
md "%fd%" 2>nul
@echo off
cd /d "%~dp0"
set "fd=temp"
md "%fd%" 2>nul
for /f "delims=" %%a in ('dir /a-d/b *.lst') do (
    echo;"%%a"
    (for /f "tokens=1*delims=:" %%b in ('findstr /n .* "%%a"') do (
        set "f=%%c"
        if defined f (echo;file '%%c') else (echo;)
    ))>"%fd%\%%a"
    del "%%a"
    move /y "%fd%\%%a" "%%a"
)
echo;%w% +%#%%#% %zx%
rd temp

5. 压缩所有文件

for %%i in (*.lst) do (ffmpeg -hide_banner -f concat -safe 0 -i %%i -c:v libx265 -b:v 384k -c:a aac -s 1280x720 -vf scale=1280:720 -vf fps=20 %%i.mp4)

6. 删除清单lst文件

del /f /s /q *.lst

批处理打包下载:

CategoriesT: Tech


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK