Skip to content

Commit 8b34851

Browse files
committed
Added compresion ratio to stdout and performance log
1 parent 20fdc72 commit 8b34851

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

transcode.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
"""
1414
1515
TODO:
16-
- convert all string paths into os.path objects
1716
- allow comma-separated string for --preset, e.g. medium,slow,slower, map to list
18-
- add compression ratio / space saved to log + screen output
1917
- ~~if presets.json does not exist, download from github~~
2018
2119
"""
@@ -125,11 +123,11 @@ def signal_handler(self, sig, frame):
125123
"""
126124
self.cleanup()
127125

128-
def log(self, elapsed_time, fps):
126+
def log(self, elapsed_time, fps, compression_ratio):
129127
""" Summarizes transcode session for screen and log
130128
"""
131129
with open(self.path["log"], "w") as logfile:
132-
summary = str(elapsed_time) + "\n" + str(fps) + " fps"
130+
summary = "{elapsed_time}\n{fps} fps\n{compression_ratio}% reduction".format(elapsed_time=elapsed_time, fps=fps, compression_ratio=compression_ratio)
133131
logfile.write(summary + "\n\n" + session.args + "\n\n")
134132
pprint(vars(self), logfile)
135133
print(summary)
@@ -213,8 +211,11 @@ def cleanup(self):
213211
session_end_time = datetime.now()
214212
session_elapsed_time = session_end_time - session_start_time
215213
fps = session.source["frames"] / session_elapsed_time.seconds
214+
source_file_size = session.source["filesize"] / 1000000
215+
output_file_size = os.path.getsize(session.path["output"] / 1000000
216+
compression_ratio = int(100 - (output_file_size / source_file_size * 100))
216217
print("\n{date}: Finished {output_file}".format(date=str(session_end_time), output_file=session.path["output"]))
217-
session.log(session_elapsed_time, fps)
218+
session.log(session_elapsed_time, fps, compression_ratio)
218219
print("\n\n\n\n\n")
219220
if args.delete:
220221
session.cleanup()

0 commit comments

Comments
 (0)