refract
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,2 +1,6 @@
|
|||||||
venv/
|
venv/
|
||||||
.idea/
|
.idea/
|
||||||
|
.run/
|
||||||
|
prepare.egg-info/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
|||||||
40
prepare.py
Normal file → Executable file
40
prepare.py
Normal file → Executable file
@@ -1,23 +1,21 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import argparse
|
import argparse
|
||||||
import random
|
import random
|
||||||
from argparse import ArgumentParser
|
import os
|
||||||
from os import makedirs, path
|
import pathlib
|
||||||
from pathlib import Path
|
import moviepy.editor
|
||||||
|
import moviepy.video.io.ffmpeg_tools
|
||||||
from moviepy.editor import *
|
import pymediainfo
|
||||||
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
|
|
||||||
from pymediainfo import MediaInfo
|
|
||||||
|
|
||||||
|
|
||||||
class Args:
|
class Args:
|
||||||
parser: ArgumentParser = argparse.ArgumentParser(
|
parser = ArgumentParser = argparse.ArgumentParser(
|
||||||
description='Extracting mediainfo, sample and screens from random timecodes from video')
|
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('-c', action='store_true', dest='sample', help="extract sample")
|
||||||
parser.add_argument('-m', action='store_true', dest='mediainfo', help='create mediainfo')
|
parser.add_argument('-m', action='store_true', dest='mediainfo', help='create mediainfo')
|
||||||
parser.add_argument('-n', action='store', dest="count", default=10,
|
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)
|
parser.add_argument('-i', action='store', dest='input', help="input file", required=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -30,9 +28,9 @@ def sample(fold, exname, max_time):
|
|||||||
print("sample")
|
print("sample")
|
||||||
sam = fold + "/sample" + exname
|
sam = fold + "/sample" + exname
|
||||||
if max_time <= 360:
|
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:
|
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):
|
def info(mfile, media_info):
|
||||||
@@ -49,7 +47,7 @@ def screens(fold, max_time):
|
|||||||
i = 0
|
i = 0
|
||||||
max_time = round(max_time)
|
max_time = round(max_time)
|
||||||
print("Rounded duration %ss" % 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)
|
mintimescr = round(max_time * 0.05)
|
||||||
maxtimescr = round(max_time * 0.95)
|
maxtimescr = round(max_time * 0.95)
|
||||||
|
|
||||||
@@ -72,23 +70,23 @@ class Head:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
bname: str
|
bname: str
|
||||||
|
|
||||||
bname = path.basename(Args.args.input)
|
bname = moviepy.editor.os.path.basename(Args.args.input)
|
||||||
fname = path.splitext(bname)[0]
|
fname = moviepy.editor.os.path.splitext(bname)[0]
|
||||||
exname = path.splitext(bname)[1]
|
exname = moviepy.editor.os.path.splitext(bname)[1]
|
||||||
print("Filename is %s" % bname)
|
print("Filename is %s" % bname)
|
||||||
fold = str(Path.home()) + "/samples/" + fname
|
fold = str(pathlib.Path.home()) + "/samples/" + fname
|
||||||
if path.isdir(fold):
|
if moviepy.editor.os.path.isdir(fold):
|
||||||
print("Directory %s is exist" % fold)
|
print("Directory %s is exist" % fold)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
makedirs(fold)
|
moviepy.editor.os.makedirs(fold)
|
||||||
except OSError:
|
except OSError:
|
||||||
print("Creation of the directory %s failed" % fold)
|
print("Creation of the directory %s failed" % fold)
|
||||||
else:
|
else:
|
||||||
print("Successfully created the directory %s " % fold)
|
print("Successfully created the directory %s " % fold)
|
||||||
print("\nFiles will be located at %s" % fold)
|
print("\nFiles will be located at %s" % fold)
|
||||||
media_info = MediaInfo.parse(Args.args.input, output="", parse_speed=2)
|
media_info = pymediainfo.MediaInfo.parse(Args.args.input, output="", parse_speed=2)
|
||||||
mi = MediaInfo.parse(Args.args.input)
|
mi = pymediainfo.MediaInfo.parse(Args.args.input)
|
||||||
mfile = fold + "/mediainfo.txt"
|
mfile = fold + "/mediainfo.txt"
|
||||||
duration = mi.tracks[0]
|
duration = mi.tracks[0]
|
||||||
max_time = duration.duration / 1000
|
max_time = duration.duration / 1000
|
||||||
|
|||||||
5
setup.py
5
setup.py
@@ -14,10 +14,9 @@ install_requires = [
|
|||||||
setup(
|
setup(
|
||||||
name='prepare',
|
name='prepare',
|
||||||
version='0.1.1',
|
version='0.1.1',
|
||||||
url='',
|
libraries=['setuptools', 'pymediainfo', 'moviepy'],
|
||||||
zip_safe=True,
|
zip_safe=False,
|
||||||
install_requires=install_requires,
|
install_requires=install_requires,
|
||||||
include_package_data=True,
|
|
||||||
author='beaconborn',
|
author='beaconborn',
|
||||||
author_email='rik.slava@mail.com',
|
author_email='rik.slava@mail.com',
|
||||||
description='Creating screens, Media Info and sample from script'
|
description='Creating screens, Media Info and sample from script'
|
||||||
|
|||||||
Reference in New Issue
Block a user