cont refract

This commit is contained in:
2022-02-16 18:05:27 +03:00
parent 807b2c179c
commit 39e945cdd2

View File

@@ -4,8 +4,8 @@ import random
import os
import pathlib
import moviepy.editor
import moviepy
import pymediainfo
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from pymediainfo import MediaInfo
import threading
@@ -19,7 +19,8 @@ class Args:
help="number of screenshots, default 10", type=int)
parser.add_argument('-i', action='store', dest='input', help="input file", required=True)
args = parser.parse_args()
# args.input = "D:/ReLive/Escape from Tarkov/2021.02.18-22.15.mp4"
args.input = "D:/ReLive/Escape from Tarkov/2021.02.18-22.15.mp4"
args.screens = True
def sample(fold, exname, max_time):
@@ -28,29 +29,27 @@ def sample(fold, exname, max_time):
"""
print("sample")
sam = fold + "/sample" + exname
sam = fold + "/sample/" + exname
if max_time <= 360:
moviepy.video.io.ffmpeg_tools.ffmpeg_extract_subclip(Args.args.input, max_time / 3, max_time * 2 / 3, targetname=sam)
ffmpeg_extract_subclip(Args.args.input, max_time / 3, max_time * 2 / 3, targetname=sam)
else:
moviepy.video.io.ffmpeg_tools.ffmpeg_extract_subclip(Args.args.input, max_time / 2 - 60, max_time / 2 + 60, targetname=sam)
ffmpeg_extract_subclip(Args.args.input, max_time / 2 - 60, max_time / 2 + 60, targetname=sam)
def info(mfile, media_info):
print("Creating MediaInfo")
# print(media_info)
f = open(mfile, "w")
f.write(str(media_info))
f.close()
print("Created MediaInfo")
def screens(fold, mintimescr, maxtimescr, screen_create):
def screens(fold, mintimescr, maxtimescr, screen_create, num_screen):
time = random.randint(mintimescr, maxtimescr)
imgname = fold + "/" + str(time) + ".png"
print(" time %ds" % time)
make_screen = screen_create.save_frame(imgname, t=time)
print(f"{num_screen + 1} time {time}s")
screen_create.save_frame(imgname, t=time)
screen_create.reader.close()
screen_create.audio.reader.close_proc()
@@ -60,7 +59,7 @@ class Head:
Creates mediainfo, screenshots and sample from file
"""
def __init__(self):
def body():
bname: str
bname = moviepy.editor.os.path.basename(Args.args.input)
@@ -68,7 +67,8 @@ class Head:
exname = moviepy.editor.os.path.splitext(bname)[1]
print("Filename is %s" % bname)
fold = str(pathlib.Path.home()) + "/samples/" + fname
if moviepy.editor.os.path.isdir(fold):
if os.path.isdir(fold):
print("Directory %s is exist" % fold)
else:
try:
@@ -78,8 +78,9 @@ class Head:
else:
print("Successfully created the directory %s " % fold)
print("\nFiles will be located at %s" % fold)
media_info = pymediainfo.MediaInfo.parse(Args.args.input, output="", parse_speed=2)
mi = pymediainfo.MediaInfo.parse(Args.args.input)
media_info = MediaInfo.parse(Args.args.input, output="", parse_speed=2)
mi = MediaInfo.parse(Args.args.input)
mfile = fold + "/mediainfo.txt"
duration = mi.tracks[0]
max_time = duration.duration / 1000
@@ -87,24 +88,20 @@ class Head:
if Args.args.sample:
sample(fold, exname, max_time)
if Args.args.screens:
print("Creating %s screenschots" % Args.args.count)
i = 0
print("Creating %s screenshots" % Args.args.count)
max_time = round(max_time)
print("Rounded duration %ss" % max_time)
screen_create = moviepy.editor.VideoFileClip(Args.args.input)
mintimescr = round(max_time * 0.05)
maxtimescr = round(max_time * 0.95)
return mintimescr, maxtimescr, fold, screen_create
# screens(fold, mintimescr, maxtimescr, screen_create)
for i in range(Args.args.count):
num_screen = i
thread = threading.Thread(name="screenshot",
target=screens(fold, mintimescr, maxtimescr, screen_create, num_screen))
thread.start()
if Args.args.mediainfo:
info(mfile, media_info)
if __name__ == '__main__':
Head()
if Args.args.screens:
for i in range (Args.args.count):
condition = threading.Condition()
thread = threading.Thread(name="screenshot", target=screens, args=(Head.mintimescr, Head.maxtimescr, Head.fold, Head.screen_create))
thread.start()
Head.body()