Last active
November 16, 2023 03:24
-
-
Save fenderrex/73b5b62564bc4cfb31781f72e6f00001 to your computer and use it in GitHub Desktop.
I was just trying to find how I can remove reduce hard drive space while producing a commercial amount of video idea here works but you need to read it and understand that it was done on a phone with long video clips
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
#Rex Baird <[email protected]> | |
#Fri, Oct 6, 2:49 PM | |
#to me | |
#i made this on py droid so ill make a few branches? | |
#what: is reduction? ok so the goil is to hilight changes in a video stream currently drops the output to a gif | |
#why: because this ran on my phone the filter of frames was vittal | |
#i wantted to record what i was doing in a way that i could review latter | |
#I want to make the filter customizable got for now | |
#this is a demo and it shows the root idea, some numbers need be changed to | |
#reduce gitter i want the leading resaloution and trailing resalution to be customizable | |
#TODO: add pool max and pool avg and face detection and other fileter like 3d face masks | |
#i belive with cude i can hash the images faster and fill a matrix of changes | |
#we maybe able to detect unstable video segments and relative depth | |
#isolate image segmants and build custom video format | |
#plan: before we can add any of the TODO content we need to take a moment to make what we already have a pipeline builder framework | |
#it will be nice to disbatch frames in a fashion that can latter be parallarized | |
#as such we may want to crop compress cross refrance with prior soft max | |
#i want to build a batching mechanism with a content disreguard masks | |
#i want a predictive tool set with the most basic of tools | |
# i want hooks and a rich set of features! | |
#pylint:disable=E0001 | |
from os import walk | |
import imageio,os,glob,math | |
import numpy as np | |
baseImgID=False | |
folder=[] | |
f = [] | |
def displaygraph(arin): | |
map=[] | |
for y in range(int(math.floor(min(arin))/10),int(math.floor(max(arin))/10)): | |
col=[] | |
tag=0 | |
for x in range(len(arin)): | |
# | |
if math.floor(arin[x]/10)-1<y and math.floor(arin[x]/10)+1>y: | |
col.append("{num:2.0f}".format(num = y)) | |
tag+=y | |
else: | |
col.append(" ") | |
if tag!=0: | |
col.append(str(tag)) | |
#map.append(col) | |
map.append("".join(col)) | |
# print("".join(col)) | |
map.reverse() | |
for row in map: | |
print(row) | |
#e=range(0,6) | |
#displaygraph(e) | |
#input("%") | |
#for (dirpath, dirnames, filenames) in walk("./../../"): | |
# f.append(filenames) | |
#os.chdir("./../../DCIM/Screen recordings/") | |
#for item in f: | |
# print(item) | |
# Create a video writer | |
current_dir = os.getcwd() | |
output_filename = 'output_video.avi' | |
output_filepath = os.path.join(current_dir, output_filename) | |
#print(os.path.join(os.environ['EXTERNAL_STORAGE'], 'output_video') ) | |
print(output_filepath ) | |
import cv2 | |
import os | |
kimages=[] | |
currentFile=0 | |
def MilRow(cropingA): | |
size=len(cropingA) | |
outPut=[] | |
for x in range(0,size): | |
row=cropingA[x,0:-1] | |
head=1 | |
for item in row: | |
head*=item | |
outPut.append(head) | |
return np.array(outPut) | |
def filterByHash(source,fileSystem_): | |
global baseImgID | |
vidcap = cv2.VideoCapture(source) | |
success,image = vidcap.read() | |
count = 0 | |
out=[] | |
frameLimit=45 | |
countInBatch=batch=0 | |
ustep=5000 | |
ucycle=0 | |
chart=[] | |
while success: | |
if count in range(0,10000,60*60): | |
out.append(image) | |
if count%ustep==0: | |
hsh= cv2.img_hash.BlockMeanHash_create()#it works | |
# hsh.compute(a_1) | |
imageHash=hsh.compute(image) | |
if (str(imageHash)in kimages): | |
ustep=2#50000 | |
# ucycle=ucycle+5 | |
else: | |
e=np.array(imageHash[0]) | |
cropingA=e.reshape(8,4) | |
# cropingB=e.reshape(4,8) | |
# cropingC=e.reshape(16,2) | |
#a0=cropingA.sum(axis=0) | |
a1=MilRow(cropingA) | |
#a1=cropingA.sum(axis=1) | |
# b0=cropingB.sum(axis=0) | |
# b1=cropingB.sum(axis=1) | |
# c0=cropingC.sum(axis=0) | |
# c1=cropingC.sum(axis=1) | |
temprVar=str(a1.sum()) | |
if baseImgID==False: | |
baseImgID=temprVar | |
if temprVar!=baseImgID: | |
##baseImgID=temprVar | |
print(int(temprVar)-int(baseImgID)) | |
chart.append(int(temprVar)-int(baseImgID)) | |
baseImgID=temprVar | |
#blockCommentThisIsFunnyIfYouAreSelfToughtBecauseYouKnowAboutTheGCAndExcLinkedsAndHowMicroPyProjectHasPushedTypeScriptToMicroJsAndJs | |
mm= """ print("A0\n"+ | |
str(a0)+ | |
# "a0 total"+ | |
# str(a0.sum())+ | |
"\nA1\n"+ | |
str(a1)+ | |
"a1 total"+ | |
str(a1.sum())+ | |
"\nB0\n"+ | |
str(b0)+ | |
# "b0 total"+ | |
# str(b0.sum())+ | |
"\nB1\n"+ | |
str(b1)+ | |
"b1 total"+ | |
str(b1.sum())+ | |
"\nC0\n"+ | |
str(c0)+ | |
# "c0 total"+ | |
# str(c0.sum())+ | |
"\nC1\n"+ | |
"c total"+ | |
str(c1.sum())+ | |
str(c1) | |
)"""#lol | |
# print("d"+str(sum(imageHash[0,15:20]))) | |
#print(len(imageHash[0])) | |
ustep=120 | |
ucycle=ucycle+1#continous scaning | |
if(ucycle>5): | |
# out.release() | |
#displaygraph(chart) | |
chart=[] | |
ustep=1000 | |
ucycle=0#if we get a long clip of movment take one pic | |
kimages.append(str(imageHash)) | |
out.append(image) | |
#out.release() | |
print("%s: %s"%(str(count),str(imageHash))) | |
if len(out)>=frameLimit: | |
#saveGifFromList( | |
fileSystem_(out,str(currentFile)+"___"+str(batch)) | |
batch+=1 | |
out=[] | |
countInBatch=0 | |
success,image = vidcap.read() | |
## print('Read a new frame: ', count) | |
count += 1 | |
def saveGifFromList(image_lst,index): | |
print("saving "+str(len(image_lst))+" images") | |
imageio.mimsave(os.getcwd()+"/"+index+"videoC.gif", image_lst, duration=len(image_lst)+(len(image_lst)*.6)) | |
def prepImageList(filterSystem,fileSystem,cap): | |
key=0 | |
image_list=filterSystem(cap,fileSystem) | |
print("filter compleated") | |
return image_list | |
#cv2.destroyAllWindows() | |
index=0 | |
def saveGif(filterSystem,capture,fileSystem=saveGifFromList,index="0001"): | |
prepImageList(filterSystem,fileSystem,capture)#todo | |
for file in glob.glob("../*") : | |
print(file) | |
if index in[2]:#skip | |
index+=1 | |
continue | |
saveGif(filterByHash,file,index="1000"+str(index)) | |
currentFile+=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adaptive rates not working well when source videos length cuts buffer short