Last active
January 17, 2020 04:12
-
-
Save zackbloom/2bf0971cc7a8f2d7a9aa84079bb00587 to your computer and use it in GitHub Desktop.
Join Paralenz Videos, Automatically Handling Multiple Videos in the Same Directory
This file contains 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
#!/usr/bin/env python | |
import os | |
import os.path | |
import time | |
import tempfile | |
from glob import glob | |
ONE_HOUR = 60 * 60 | |
files = [f for f in glob('*.MP4') if os.path.isfile(f)] | |
files.sort(key=os.path.getmtime) | |
current_file_index = 0 | |
file = None | |
def next_file(): | |
global file | |
if file is not None: | |
file.flush() | |
join_videos() | |
file.close() | |
file = tempfile.NamedTemporaryFile() | |
def join_videos(): | |
global current_file_index, file | |
if file.tell() > 0: | |
current_file_index += 1 | |
os.system("ffmpeg -f concat -safe 0 -i '%s' -c copy %i.mp4" % (file.name, current_file_index)) | |
last = 0 | |
for filepath in files: | |
mtime = os.path.getmtime(filepath) | |
if (mtime - last) > ONE_HOUR/2: | |
next_file() | |
last = mtime | |
file.write("file '%s'\n" % os.path.join(os.getcwd(), filepath)) | |
next_file() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment