Added video generator
This commit is contained in:
parent
fb7991d856
commit
862b0783d7
22
README.md
22
README.md
|
@ -1,6 +1,6 @@
|
||||||
# vaporwave generator 旺育栄
|
# vaporwave generator 旺育栄
|
||||||
|
|
||||||
A vaporwave music (+art, +video soon, I promise) generator bodged together using code from various sources. Runs on Python3
|
A vaporwave music + image + video (+art soon, I promise) generator bodged together using code from various sources. Runs on Python 3. VHSVideo option is really really slow (Seconds per frame is 7.)
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: main.py [-h] [-M] [-P] [-V] [-i INPUT]
|
usage: main.py [-h] [-M] [-P] [-V] [-i INPUT]
|
||||||
|
@ -35,6 +35,10 @@ Linking to Bandcamp soon
|
||||||
|
|
||||||
![](assets/out-vhs.jpg?raw=true "Output VHS")
|
![](assets/out-vhs.jpg?raw=true "Output VHS")
|
||||||
|
|
||||||
|
### V H S V I D E O
|
||||||
|
|
||||||
|
See the in.mp4 and out.mp4 in the assets folder
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
This was tested on macOS Catalina ( so should work on almost all macOS versions).
|
This was tested on macOS Catalina ( so should work on almost all macOS versions).
|
||||||
|
@ -45,7 +49,7 @@ Windows is unsupported at this time ( I need to find a way to use aubio's python
|
||||||
#### Linux
|
#### Linux
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt install ffmpeg libavl1 sox
|
sudo apt install ffmpeg ffprobe libavl1 sox
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -76,9 +80,19 @@ python3 main.py -M -i Song Title
|
||||||
|
|
||||||
`python3 main.py -P -i "image.jpg"`
|
`python3 main.py -P -i "image.jpg"`
|
||||||
|
|
||||||
|
### V H S V I D E O
|
||||||
|
|
||||||
|
`python3 main.py -V -i "video.mp4" -o "output.mp4"`
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
|
|
||||||
This project is a result of bodging and therefore has tons of bugs which need to be ironed out
|
This project is a result of bodging and therefore has tons of bugs which need to be ironed out. I need to swat some bugs in the VHSVideo file.
|
||||||
|
|
||||||
|
There might be a problem with the generated video not having audio, for that run the following
|
||||||
|
|
||||||
|
`ffmpeg -i video.mp4 -vn -acodec copy output-audio.aac`
|
||||||
|
`ffmpeg -i output.mp4 -i output-audio.aac -c copy output-with-audio.mp4'
|
||||||
|
|
||||||
|
|
||||||
## To-Do
|
## To-Do
|
||||||
|
|
||||||
|
@ -86,7 +100,7 @@ This project is a result of bodging and therefore has tons of bugs which need to
|
||||||
[] Clean the Code
|
[] Clean the Code
|
||||||
[] Add Artwork Generator
|
[] Add Artwork Generator
|
||||||
[x] VHS Picture Styler ( Added in v1.5 )
|
[x] VHS Picture Styler ( Added in v1.5 )
|
||||||
[] Add Video Generator
|
[x] Add Video Generator
|
||||||
[] Add Custom Date to VHS Styler
|
[] Add Custom Date to VHS Styler
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
Binary file not shown.
Binary file not shown.
14
main.py
14
main.py
|
@ -1,5 +1,6 @@
|
||||||
from src.VaporSong import VaporSong
|
from src.VaporSong import VaporSong
|
||||||
from src.VHSImage import generateVHSStyle
|
from src.VHSImage import generateVHSStyle
|
||||||
|
from src.VHSVideo import VHS_Vid
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
|
@ -12,7 +13,7 @@ import urllib.parse
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
|
|
||||||
version = 1.5
|
version = 2.0
|
||||||
style = False
|
style = False
|
||||||
|
|
||||||
text = 'This program takes YouTube URL or title of a song and converts it into vaporwave'
|
text = 'This program takes YouTube URL or title of a song and converts it into vaporwave'
|
||||||
|
@ -20,14 +21,17 @@ text = 'This program takes YouTube URL or title of a song and converts it into v
|
||||||
parser = argparse.ArgumentParser(description = text)
|
parser = argparse.ArgumentParser(description = text)
|
||||||
parser.add_argument("-M", "--music", help="generate v a p o r w a v e music", action="store_true")
|
parser.add_argument("-M", "--music", help="generate v a p o r w a v e music", action="store_true")
|
||||||
parser.add_argument("-P", "--picture", help="generate VHS Style image", action="store_true")
|
parser.add_argument("-P", "--picture", help="generate VHS Style image", action="store_true")
|
||||||
parser.add_argument("-V", "--version", help="show program version", action="store_true")
|
parser.add_argument("-V","--video", help="VHS Style Video", action="store_true")
|
||||||
|
parser.add_argument("-v", "--version", help="show program version", action="store_true")
|
||||||
parser.add_argument("-i", "--input")
|
parser.add_argument("-i", "--input")
|
||||||
|
parser.add_argument("-o","--output", help="Output for specifying output video")
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
music = False
|
music = False
|
||||||
picture = False
|
picture = False
|
||||||
|
video = False
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
print("vaporwave generator 旺育栄", version)
|
print("vaporwave generator 旺育栄", version)
|
||||||
|
@ -36,8 +40,12 @@ if args.music:
|
||||||
music = True
|
music = True
|
||||||
elif args.picture:
|
elif args.picture:
|
||||||
picture = True
|
picture = True
|
||||||
|
elif args.video:
|
||||||
|
video = True
|
||||||
if args.input:
|
if args.input:
|
||||||
query = args.input
|
query = args.input
|
||||||
|
if args.output:
|
||||||
|
outfile = args.output
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit
|
exit
|
||||||
|
@ -160,4 +168,6 @@ if music:
|
||||||
gen_vapor(name, title)
|
gen_vapor(name, title)
|
||||||
elif picture:
|
elif picture:
|
||||||
generateVHSStyle(query,"out.jpg")
|
generateVHSStyle(query,"out.jpg")
|
||||||
|
elif video:
|
||||||
|
VHS_Vid(query, outfile)
|
||||||
|
|
|
@ -146,25 +146,39 @@ if __name__ == "__main__":
|
||||||
build_background("bkg.jpg", 25)
|
build_background("bkg.jpg", 25)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def generateVHSStyle(infile, outfile):
|
def generateVHSStyle(infile, outfile, silence=False):
|
||||||
cut_rows = bool(random.getrandbits(1))
|
if silence:
|
||||||
offset = random.choice([0,5,10,15,20,25])
|
cut_rows = bool(random.getrandbits(1))
|
||||||
logger.info("Saturating the image")
|
offset = random.choice([0,5,10,15,20,25])
|
||||||
offset_hue(infile,"saturated.jpg")
|
offset_hue(infile,"saturated.jpg")
|
||||||
if cut_rows:
|
if cut_rows:
|
||||||
logger.info("Shifting the image")
|
mod_image_repeat_rows("saturated.jpg", 0.012, 50, 10, True, "shifted.jpg")
|
||||||
mod_image_repeat_rows("saturated.jpg", 0.012, 50, 10, True, "shifted.jpg")
|
else:
|
||||||
|
mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg")
|
||||||
|
add_date("shifted.jpg","noisy.jpg")
|
||||||
|
add_date("noisy.jpg",outfile, bottom_offset=offset)
|
||||||
|
os.remove("shifted.jpg")
|
||||||
|
os.remove("saturated.jpg")
|
||||||
|
os.remove("noisy.jpg")
|
||||||
else:
|
else:
|
||||||
logger.info("Not applying lines effect")
|
cut_rows = bool(random.getrandbits(1))
|
||||||
mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg")
|
offset = random.choice([0,5,10,15,20,25])
|
||||||
logger.info("Adding noise")
|
logger.info("Saturating the image")
|
||||||
add_date("shifted.jpg","noisy.jpg")
|
offset_hue(infile,"saturated.jpg")
|
||||||
logger.info("Adding text")
|
if cut_rows:
|
||||||
add_date("noisy.jpg",outfile, bottom_offset=offset)
|
logger.info("Shifting the image")
|
||||||
logger.info("Generated Image: out.jpg")
|
mod_image_repeat_rows("saturated.jpg", 0.012, 50, 10, True, "shifted.jpg")
|
||||||
logger.info("Removing residual files")
|
else:
|
||||||
os.remove("shifted.jpg")
|
logger.info("Not applying lines effect")
|
||||||
os.remove("saturated.jpg")
|
mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg")
|
||||||
os.remove("noisy.jpg")
|
logger.info("Adding noise")
|
||||||
|
add_date("shifted.jpg","noisy.jpg")
|
||||||
|
logger.info("Adding text")
|
||||||
|
add_date("noisy.jpg",outfile, bottom_offset=offset)
|
||||||
|
logger.info("Generated Image: out.jpg")
|
||||||
|
logger.info("Removing residual files")
|
||||||
|
os.remove("shifted.jpg")
|
||||||
|
os.remove("saturated.jpg")
|
||||||
|
os.remove("noisy.jpg")
|
||||||
|
|
||||||
#generateVHSStyle("s.jpg","o.jpg")
|
#generateVHSStyle("s.jpg","o.jpg")
|
|
@ -0,0 +1,87 @@
|
||||||
|
import os
|
||||||
|
import cv2
|
||||||
|
from src.VHSImage import generateVHSStyle
|
||||||
|
from os.path import isfile, join
|
||||||
|
import numpy as np
|
||||||
|
import subprocess
|
||||||
|
import logzero
|
||||||
|
from logzero import logger
|
||||||
|
from logzero import setup_logger
|
||||||
|
|
||||||
|
def SaveVid(path):
|
||||||
|
vidObj = cv2.VideoCapture(path)
|
||||||
|
count = 0
|
||||||
|
success = 1
|
||||||
|
while success:
|
||||||
|
success, image = vidObj.read()
|
||||||
|
cv2.imwrite("frames/"+str(count)+".jpg", image)
|
||||||
|
#os.rename("frames/"+str(count)+".jpg", os.path.splitext("frames/"+str(count)+".jpg")[0])
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
def Style(pathToFrames):
|
||||||
|
files = [f for f in os.listdir(pathToFrames) if isfile(join(pathToFrames, f))]
|
||||||
|
count = 0
|
||||||
|
for i in files:
|
||||||
|
count += 1
|
||||||
|
f = str(i)
|
||||||
|
fi = pathToFrames + f
|
||||||
|
out = fi + ".jpg"
|
||||||
|
|
||||||
|
generateVHSStyle(fi, out, silence=True)
|
||||||
|
os.rename(out, fi)
|
||||||
|
print("--------")
|
||||||
|
print("On Frame: ")
|
||||||
|
print(count)
|
||||||
|
print("Out of")
|
||||||
|
print(len(files))
|
||||||
|
print("--------")
|
||||||
|
cwd = os.getcwd()
|
||||||
|
os.chdir(pathToFrames)
|
||||||
|
c = "find ./ -name \"*.jpg\" -exec sh -c 'mv $0 `basename \"$0\" .jpg`' '{}' \; ;"
|
||||||
|
os.system(c)
|
||||||
|
os.chdir(cwd)
|
||||||
|
|
||||||
|
def generateVideo(outfile, path, infile):
|
||||||
|
frame_array = []
|
||||||
|
files = [int(f) for f in os.listdir(path) if isfile(join(path, f))]
|
||||||
|
files.sort()
|
||||||
|
|
||||||
|
duration = subprocess.check_output(['ffprobe', '-i', infile, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv=%s' % ("p=0")])
|
||||||
|
fps = len(files)/float(duration)
|
||||||
|
print("FPS", fps)
|
||||||
|
|
||||||
|
for i in range(len(files)):
|
||||||
|
filename=path + str(files[i])
|
||||||
|
img = cv2.imread(filename)
|
||||||
|
height, width, layers = img.shape
|
||||||
|
size = (width,height)
|
||||||
|
frame_array.append(img)
|
||||||
|
out = cv2.VideoWriter(outfile,cv2.VideoWriter_fourcc(*'MP4V'), fps, size)
|
||||||
|
for i in range(len(frame_array)):
|
||||||
|
out.write(frame_array[i])
|
||||||
|
out.release()
|
||||||
|
|
||||||
|
|
||||||
|
def VHS_Vid(infile, outfile):
|
||||||
|
path = './frames/'
|
||||||
|
os.system("rm frames/*")
|
||||||
|
os.system("mkdir frames")
|
||||||
|
logger.info("Exctracting Frames")
|
||||||
|
try:
|
||||||
|
SaveVid(infile)
|
||||||
|
except:
|
||||||
|
logger.debug("Extracted Frames")
|
||||||
|
logger.info("Applying A E S T H E T I C S")
|
||||||
|
Style(path)
|
||||||
|
logger.info("Generating Vidio")
|
||||||
|
generateVideo("temp.mp4", path, infile)
|
||||||
|
logger.info("Extracting audio of original video")
|
||||||
|
os.system("ffmpeg -i %(infile)s -vn -acodec copy output-audio.aac")
|
||||||
|
logger.info("Merging audio")
|
||||||
|
os.system("ffmpeg -i temp.mp4 -i output-audio.aac -c copy %(outfile)s")
|
||||||
|
logger.info("Removing residual files")
|
||||||
|
os.remove("temp.mp4")
|
||||||
|
os.remove("output-audio.aac")
|
||||||
|
|
||||||
|
|
||||||
|
#VHS_Vid("video.mp4","video2.mp4")
|
Loading…
Reference in New Issue