Skip to content

Instantly share code, notes, and snippets.

@zackbloom
Last active January 17, 2020 04:12
Show Gist options
  • Select an option

  • Save zackbloom/2bf0971cc7a8f2d7a9aa84079bb00587 to your computer and use it in GitHub Desktop.

Select an option

Save zackbloom/2bf0971cc7a8f2d7a9aa84079bb00587 to your computer and use it in GitHub Desktop.

Revisions

  1. zackbloom revised this gist Jan 17, 2020. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions join_paralenz.py
    Original file line number Diff line number Diff line change
    @@ -16,13 +16,14 @@
    file = None

    def next_file():
    global file
    global file

    if file is not None:
    file.flush()
    join_videos()
    if file is not None:
    file.flush()
    join_videos()
    file.close()

    file = tempfile.NamedTemporaryFile()
    file = tempfile.NamedTemporaryFile()

    def join_videos():
    global current_file_index, file
    @@ -31,6 +32,7 @@ def join_videos():
    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)
  2. zackbloom created this gist Jan 17, 2020.
    45 changes: 45 additions & 0 deletions join_paralenz.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/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 = 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()