Skip to content

Instantly share code, notes, and snippets.

@SubhrajitPrusty
Last active September 14, 2019 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SubhrajitPrusty/5f303202c615e42e12b1a640322f9fec to your computer and use it in GitHub Desktop.
Save SubhrajitPrusty/5f303202c615e42e12b1a640322f9fec to your computer and use it in GitHub Desktop.
Make a poly video using wallgen
from wallgen import *
import os
from PIL import Image
import numpy as np
import cv2
import sys
if len(sys.argv) < 1:
print("Needs file path ")
sys.exit(1)
fn = sys.argv[1]
if not os.path.exists(fn):
print("Invalid path")
sys.exit(1)
ERASE_LINE = '\x1b[2K'
CURSOR_UP_ONE = '\x1b[1A'
cap = cv2.VideoCapture(fn)
ret, frame = cap.read()
img = Image.fromarray(frame)
width = img.width
height = img.height
wshift = img.width//10
hshift = img.height//10
width += wshift*2
height += hshift*2
pts = genPoints(10000, width, height)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('vid.avi', fourcc, 24, (img.width, img.height))
fr = 1
while(cap.isOpened()):
ret, frame = cap.read()
if ret:
print(CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE)
print(fr)
fr+=1
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame)
pimg = genPoly(img.width, img.height, img, pts, wshift, hshift, False, pic=True)
cimg = cv2.cvtColor(np.array(pimg), cv2.COLOR_RGB2BGR)
out.write(cimg)
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
getMusic = "ffmpeg -i '{}' audio.mp3 -y".format(fn)
os.system(getMusic)
stitchVideo = "ffmpeg -i audio.mp3 -i vid.avi -c:v libx264 out.mp4 -y"
os.system(stitchVideo)
@Noisk8
Copy link

Noisk8 commented Sep 9, 2019

hi im trying run this code but have this message on the terminal

Traceback (most recent call last):
File "video.py", line 12, in
fn = sys.argv[1]
IndexError: list index out of range

exactly idont know what is the problem .

cun u help me?

@SubhrajitPrusty
Copy link
Author

Hello,

The script needs a video file as a command line argument to work.
eg: python wallgen-vid.py /path/to/some_video.mp4

You also need ffmpeg installed.

Nevertheless, the script is really old and lots of code have changed in wallgen.
You can try to run it, but I don't guarantee it working smoothly.

@Noisk8
Copy link

Noisk8 commented Sep 14, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment