当视频准备好之后,就需要进行截图了。
截图的方式,需要日志文件以特定的方式进行排列。这样可以计算出需要截取的时间,以及输出的文件名。
输入文件类似下面这样:
start_record 2022-07-10_08:00:00
pwd
ls
ll -h
ls
ll /opt/
ls -l
echo "helloworld"
echo "shell"
grep "ERROR" /var/log/messages
time ls
systemctl status redis
pwd
ls
ll -h
ls
ll /opt/
ls -l
echo "helloworld"
echo "shell"
grep "ERROR" /var/log/messages
time ls
systemctl status redis
systemctl status mysqld
systemctl status mysqld
end_record 2022-07-10_10:00:00 1.1.1_列出当前路径
crontab -l
end_record 2022-07-10_10:01:20 1.1.2_查看crontab的定时任务
systemctl status sshd
end_record 2022-07-10_12:02:30 1.1.3_查看sshd服务
当日志以这种方式进行记录之后,就可以使用如下方式进行数据处理。
import datetime
# need_record_dict key是时间差,name是要命名的文件 ,输出craw.sh 文件, 执行即可
need_record_dict = {}
with open("process.log", 'r', encoding="utf-8") as fr:
for index, line in enumerate(fr):
line = line.strip()
if line.startswith("start_record"):
basetime = line.split(" ")[1]
start_time = datetime.datetime.strptime(basetime ,"%Y-%m-%d_%H:%M:%S")
elif line.startswith("end_record"):
base, recordtime, name = line.split(" ")
end_time = datetime.datetime.strptime(recordtime ,"%Y-%m-%d_%H:%M:%S")
timediff = (end_time - start_time).seconds
hour = str(timediff // 3600).zfill(2)
minute = str((timediff-int(hour)*3600) // 60).zfill(2)
second = str(timediff-int(hour)*3600-int(minute)*60).zfill(2)
outStr = f'{hour}:{minute}:{second}'
need_record_dict[outStr] = name
need_craw_file="craw.sh"
with open(need_craw_file, "w", encoding="utf-8") as ff:
for k,v in need_record_dict.items():
ff.write(f"ffmpeg -i output.gif -ss {k} -vframes 1 {v}.png\n")
该博客讲述了如何利用日志文件来安排视频截图的时间点,并通过Python脚本计算时间差,生成ffmpeg命令进行截图。内容涉及日志解析、时间处理及文件命名,为视频处理提供了自动化方案。
3836

被折叠的 条评论
为什么被折叠?



