Created
May 16, 2021 16:48
-
-
Save jeffehobbs/b1ece3a1effe1ed5ce38bd93c9328574 to your computer and use it in GitHub Desktop.
Create screenshots with subtitles (requires pysubparser + ffmpeg)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # bulk screenshotter // May 2021 // jeffehobbs@gmail.com | |
| import os, subprocess | |
| from pysubparser import parser | |
| videos_dir = 'Videos/' | |
| screenshot_dir = 'Screenshots/' | |
| season = 'Season 1/' | |
| video_file_extension = '.mp4' | |
| subtitle_file_extension = '.eng.srt' | |
| screenshot_file_extension = '.jpg' | |
| episodes = [] | |
| for file in os.listdir(videos_dir + season): | |
| if file.endswith(video_file_extension): | |
| episodes.append(file) | |
| for episode in episodes: | |
| video_file = videos_dir + season + episode | |
| subtitle_file = videos_dir + season + episode.replace(video_file_extension, subtitle_file_extension) | |
| subtitles = parser.parse(subtitle_file) | |
| for subtitle in subtitles: | |
| print(subtitle) | |
| timecode = subtitle.start | |
| screenshot_file = screenshot_dir + episode.replace(' ', '_').replace(video_file_extension,'') + str(timecode).replace(':','-') + screenshot_file_extension | |
| subprocess.call('ffmpeg -hide_banner -loglevel error -ss ' + str(timecode) + | |
| ' -copyts -i "' + video_file + | |
| '" -vf subtitles="' + subtitle_file + | |
| '" -vframes 1 -q:v 2 "' + screenshot_file + | |
| '" ', shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment