Nachtwind1 / Mp4-To-Srt

A Python Programm That Converts Mp4 files to Srt files
GNU General Public License v3.0
74 stars 8 forks source link

change: Major Optimization and General Improvement #2

Closed ryan-hami closed 11 months ago

ryan-hami commented 11 months ago

Dramatically improves image extraction speed by storing the images in an array.

The program no longer needs to write files and remove files, so the temp/ directory is removed. Because of this, it is faster by A. LOT.

Reworked logic for frame iteration.

Extracting the fps from the video file instead of from user input and calculating the milliseconds per frame allows precise time positioning, so the program should work for any fps now instead of just multiple of 30.

Robust implementation of offsets.

Offsets are accounted for before any images are extracted. Not only is this a major optimization, it also reduces overall complexity of the program.

Cleaner CLI

The command line interface experience while using this software was pretty bad before. It spammed the terminal a lot. So I commented all the print statements and added a clean progress bar which updates in-place.

General

A minor optimization that saw repeated implementation was resolving string concatenation in loops. Strings are immutable in python, so building a huge string with a loop is generally bad practice. To avoid this I implemented lists and used str.join(list) at the end.

I tried not to change the code too much, just wanted to add these performance and logic optimizations. :) 💯

image