Created
November 5, 2019 05:58
-
-
Save JohannMG/11582233ac3f11b036f9ae8ccc3855a0 to your computer and use it in GitHub Desktop.
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
from moviepy.editor import VideoFileClip | |
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip | |
import os.path | |
import sys | |
import time | |
import math | |
def main(args): | |
clipCount = 0 | |
# # clip = VideoFileClip("/Users/johannmg/localdev/LiveVidSnipets/recordin/2019-11-04_18-56-06.flv") | |
# # print(clip.duration) | |
# # print(sys.version) | |
# # ffmpeg_extract_subclip("full.mp4", start_seconds, end_seconds, targetname="cut.mp4") | |
# # whole = "/Users/johannmg/localdev/LiveVidSnipets/recordin/2019-11-04_18-56-06.flv" | |
# # clip = "/Users/johannmg/localdev/LiveVidSnipets/recordin/clip.flv" | |
# # ffmpeg_extract_subclip(whole, 0, 60, targetname=clip) | |
# clipCount+=1 | |
# print (clipCount) | |
directory = args[0] | |
print (directory) | |
filename = args[1] | |
fileMadeTime = os.stat(directory+filename).st_birthtime | |
fileMadeTime = math.floor(fileMadeTime) | |
print(fileMadeTime) | |
while True: | |
clipCount +=1 | |
print(clipCount) | |
length = input("Next clip length (defaults to 10s)") | |
if length == '': | |
lengthInt = 10 | |
else: | |
lengthInt = int(length) | |
captureClip(lengthInt, filename, fileMadeTime, directory, clipCount) | |
clipCount += 1 | |
def captureClip(lengthInt, filename, fileMadeTime, dir, count): | |
now = math.floor(time.time()) | |
fileLengthSeconds = now - fileMadeTime | |
bufferSeconds = 5 #offset 5 seconds from last | |
clipTimeStartSeconds = fileLengthSeconds - lengthInt - bufferSeconds | |
clipTimeEndSeconds = fileLengthSeconds - bufferSeconds | |
videoFilePath = dir+filename | |
newClipFilePath = dir + filename + "_CLIPPED" + paddedInt(count,3) + "-" + paddedInt(lengthInt,2) + "s" + ".flv" # OBS2019-11-04_18-56-06_CLIPPED-002-22s.flv | |
ffmpeg_extract_subclip(videoFilePath, clipTimeStartSeconds, clipTimeEndSeconds, newClipFilePath) | |
print ("created: " + newClipFilePath) | |
def paddedInt(num, len): | |
return str(num).rjust(len, "0") | |
if __name__ == "__main__": | |
"""PASS IN DIRECTORY with / , filename of main clip""" | |
import sys | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment