This commit is contained in:
2022-02-14 22:54:05 +03:00
parent b896fd32e2
commit f551db96c3
3 changed files with 26 additions and 25 deletions

6
.gitignore vendored
View File

@@ -1,2 +1,6 @@
venv/
.idea/
.idea/
.run/
prepare.egg-info/
dist/
build/

40
prepare.py Normal file → Executable file
View File

@@ -1,23 +1,21 @@
#!/usr/bin/python3
import argparse
import random
from argparse import ArgumentParser
from os import makedirs, path
from pathlib import Path
from moviepy.editor import *
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from pymediainfo import MediaInfo
import os
import pathlib
import moviepy.editor
import moviepy.video.io.ffmpeg_tools
import pymediainfo
class Args:
parser: ArgumentParser = argparse.ArgumentParser(
parser = ArgumentParser = argparse.ArgumentParser(
description='Extracting mediainfo, sample and screens from random timecodes from video')
parser.add_argument('-s', action='store_true', dest='screens', help="create screenshos")
parser.add_argument('-s', action='store_true', dest='screens', help="create screenshots")
parser.add_argument('-c', action='store_true', dest='sample', help="extract sample")
parser.add_argument('-m', action='store_true', dest='mediainfo', help='create mediainfo')
parser.add_argument('-n', action='store', dest="count", default=10,
help="number of screenschots, default 10", type=int)
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()
@@ -30,9 +28,9 @@ def sample(fold, exname, max_time):
print("sample")
sam = fold + "/sample" + exname
if max_time <= 360:
ffmpeg_extract_subclip(Args.args.input, max_time / 3, max_time * 2 / 3, targetname=sam)
ffmpeg_tools.ffmpeg_extract_subclip(Args.args.input, max_time / 3, max_time * 2 / 3, targetname=sam)
else:
ffmpeg_extract_subclip(Args.args.input, max_time / 2 - 60, max_time / 2 + 60, targetname=sam)
ffmpeg_tools.ffmpeg_extract_subclip(Args.args.input, max_time / 2 - 60, max_time / 2 + 60, targetname=sam)
def info(mfile, media_info):
@@ -49,7 +47,7 @@ def screens(fold, max_time):
i = 0
max_time = round(max_time)
print("Rounded duration %ss" % max_time)
screen_create = VideoFileClip(Args.args.input)
screen_create = moviepy.editor.VideoFileClip(Args.args.input)
mintimescr = round(max_time * 0.05)
maxtimescr = round(max_time * 0.95)
@@ -72,23 +70,23 @@ class Head:
def __init__(self):
bname: str
bname = path.basename(Args.args.input)
fname = path.splitext(bname)[0]
exname = path.splitext(bname)[1]
bname = moviepy.editor.os.path.basename(Args.args.input)
fname = moviepy.editor.os.path.splitext(bname)[0]
exname = moviepy.editor.os.path.splitext(bname)[1]
print("Filename is %s" % bname)
fold = str(Path.home()) + "/samples/" + fname
if path.isdir(fold):
fold = str(pathlib.Path.home()) + "/samples/" + fname
if moviepy.editor.os.path.isdir(fold):
print("Directory %s is exist" % fold)
else:
try:
makedirs(fold)
moviepy.editor.os.makedirs(fold)
except OSError:
print("Creation of the directory %s failed" % fold)
else:
print("Successfully created the directory %s " % fold)
print("\nFiles will be located at %s" % fold)
media_info = MediaInfo.parse(Args.args.input, output="", parse_speed=2)
mi = MediaInfo.parse(Args.args.input)
media_info = pymediainfo.MediaInfo.parse(Args.args.input, output="", parse_speed=2)
mi = pymediainfo.MediaInfo.parse(Args.args.input)
mfile = fold + "/mediainfo.txt"
duration = mi.tracks[0]
max_time = duration.duration / 1000

View File

@@ -14,10 +14,9 @@ install_requires = [
setup(
name='prepare',
version='0.1.1',
url='',
zip_safe=True,
libraries=['setuptools', 'pymediainfo', 'moviepy'],
zip_safe=False,
install_requires=install_requires,
include_package_data=True,
author='beaconborn',
author_email='rik.slava@mail.com',
description='Creating screens, Media Info and sample from script'