This repository has been archived by the owner on Jun 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
monthlyvideo.py
54 lines (42 loc) · 2.49 KB
/
monthlyvideo.py
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
from datetime import datetime, timedelta
import os
import timelapseconfig
lastmonth = (datetime.now() - timedelta(15)).strftime(timelapseconfig.monthly_filename_date_formatstring)
output_fulldays_video_path = timelapseconfig.output_dir_for_monthly_timelapse_videos + lastmonth + "_fulldays.mp4"
output_short_video_path = timelapseconfig.output_dir_for_monthly_timelapse_videos + lastmonth + "_short.mp4"
os.chdir(timelapseconfig.output_dir)
print("First make sure all the folders are prepared (they only contain the expected number of pictures)")
n = str(int(timelapseconfig.keep_every_nth_picture))
for dir in os.listdir(timelapseconfig.output_dir):
if dir.startswith(lastmonth):
daydir = timelapseconfig.output_dir + dir
files = os.listdir(daydir)
if len(files) > 250: #it should be 144
cmd = "for file in `find " + daydir + " -type f | awk 'NR %" + n + " != 0'`; do rm $file ; done"
print("Running command: " + cmd)
returnval = os.system(cmd)
print("Command returned: " + str(returnval))
# ffmpeg -r 24 -pattern_type glob -i '2020-05-*/*.png' -s hd1080 -vcodec libx264 out05.mp4
cmd = "ffmpeg -r 24 -pattern_type glob -i '" + lastmonth + "*/*.png' -s hd1080 -vcodec libx264 '" + output_fulldays_video_path + "'"
print("Running command: " + cmd)
returnval = os.system(cmd)
print("Command returned: " + str(returnval))
concat_demuxer_input_file = timelapseconfig.output_dir + "concat_demuxer_input.txt"
f = open(concat_demuxer_input_file, "w")
img_file_path = ""
output_dir_content = os.listdir(timelapseconfig.output_dir)
output_dir_content.sort()
for dir in output_dir_content:
if os.path.isdir(timelapseconfig.output_dir + dir) and dir.startswith(lastmonth):
images = os.listdir(timelapseconfig.output_dir + dir)
images.sort()
for img in images[60:85]: #10am to 2pm with the default values (1 picture per 10 minutes)
img_file_path = timelapseconfig.output_dir + dir + os.path.sep + img
f.write("file '" + img_file_path + "'\nduration 0.04\n")
f.write("file '" + img_file_path + "'\n") # the last image has to be specified twice, see https://trac.ffmpeg.org/wiki/Slideshow#Concatdemuxer
f.close()
# ffmpeg -f concat -i input.txt -vsync vfr -pix_fmt yuv420p output.mp4
cmd = "ffmpeg -f concat -safe 0 -i '" + concat_demuxer_input_file + "' -vsync vfr -pix_fmt yuv420p '" + output_short_video_path + "'"
print("Running command: " + cmd)
returnval = os.system(cmd)
print("Command returned: " + str(returnval))