diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2020-03-10 23:43:12 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2020-03-10 23:43:12 +0530 |
commit | 862b0783d731dd8980698fb035b78300703b9076 (patch) | |
tree | 80aa5d99be0fc870ac1e64410b8784c3a23fffd4 | |
parent | fb7991d856fa615a8498b24679e41d82688c347e (diff) |
Added video generator
-rw-r--r-- | README.md | 22 | ||||
-rw-r--r-- | assets/in.mp4 | bin | 0 -> 263267 bytes | |||
-rw-r--r-- | assets/out.mp4 | bin | 0 -> 1776458 bytes | |||
-rw-r--r-- | main.py | 14 | ||||
-rw-r--r-- | src/VHSImage.py | 52 | ||||
-rw-r--r-- | src/VHSVideo.py | 87 |
6 files changed, 150 insertions, 25 deletions
@@ -1,6 +1,6 @@ # 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] @@ -35,6 +35,10 @@ Linking to Bandcamp soon ![](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 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 ``` -sudo apt install ffmpeg libavl1 sox +sudo apt install ffmpeg ffprobe libavl1 sox pip install -r requirements.txt ``` @@ -76,9 +80,19 @@ python3 main.py -M -i Song Title `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 -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 @@ -86,7 +100,7 @@ This project is a result of bodging and therefore has tons of bugs which need to [] Clean the Code [] Add Artwork Generator [x] VHS Picture Styler ( Added in v1.5 ) -[] Add Video Generator +[x] Add Video Generator [] Add Custom Date to VHS Styler ## Credits diff --git a/assets/in.mp4 b/assets/in.mp4 Binary files differnew file mode 100644 index 0000000..9ffe713 --- /dev/null +++ b/assets/in.mp4 diff --git a/assets/out.mp4 b/assets/out.mp4 Binary files differnew file mode 100644 index 0000000..fc0616b --- /dev/null +++ b/assets/out.mp4 @@ -1,5 +1,6 @@ from src.VaporSong import VaporSong from src.VHSImage import generateVHSStyle +from src.VHSVideo import VHS_Vid import os import sys import youtube_dl @@ -12,7 +13,7 @@ import urllib.parse import argparse import time -version = 1.5 +version = 2.0 style = False 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.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("-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("-o","--output", help="Output for specifying output video") args = parser.parse_args() music = False picture = False +video = False if args.version: print("vaporwave generator 旺育栄", version) @@ -36,8 +40,12 @@ if args.music: music = True elif args.picture: picture = True +elif args.video: + video = True if args.input: query = args.input +if args.output: + outfile = args.output else: parser.print_help() exit @@ -160,4 +168,6 @@ if music: gen_vapor(name, title) elif picture: generateVHSStyle(query,"out.jpg") +elif video: + VHS_Vid(query, outfile)
\ No newline at end of file diff --git a/src/VHSImage.py b/src/VHSImage.py index 51688b1..81f446d 100644 --- a/src/VHSImage.py +++ b/src/VHSImage.py @@ -146,25 +146,39 @@ if __name__ == "__main__": build_background("bkg.jpg", 25) """ -def generateVHSStyle(infile, outfile): - cut_rows = bool(random.getrandbits(1)) - offset = random.choice([0,5,10,15,20,25]) - logger.info("Saturating the image") - offset_hue(infile,"saturated.jpg") - if cut_rows: - logger.info("Shifting the image") - mod_image_repeat_rows("saturated.jpg", 0.012, 50, 10, True, "shifted.jpg") +def generateVHSStyle(infile, outfile, silence=False): + if silence: + cut_rows = bool(random.getrandbits(1)) + offset = random.choice([0,5,10,15,20,25]) + offset_hue(infile,"saturated.jpg") + if cut_rows: + 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: - logger.info("Not applying lines effect") - mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.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") + cut_rows = bool(random.getrandbits(1)) + offset = random.choice([0,5,10,15,20,25]) + logger.info("Saturating the image") + offset_hue(infile,"saturated.jpg") + if cut_rows: + logger.info("Shifting the image") + mod_image_repeat_rows("saturated.jpg", 0.012, 50, 10, True, "shifted.jpg") + else: + logger.info("Not applying lines effect") + mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.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")
\ No newline at end of file diff --git a/src/VHSVideo.py b/src/VHSVideo.py new file mode 100644 index 0000000..e644074 --- /dev/null +++ b/src/VHSVideo.py @@ -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")
\ No newline at end of file |