Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import os
- import glob
- from pathlib import Path
- #takes in 9 input youtube videos and creates an output named 'output.webm'
- LENGTH = 7 #length of each clip
- totallength = LENGTH*9
- #input videos, must be square, must be 9 videos
- #second value is the start time of the audio clip in seconds, adjust to desired time
- videos = [
- ("INSERT VIDEO 1 URL", 25),
- ("INSERT VIDEO 2 URL", 25),
- ("INSERT VIDEO 3 URL", 25),
- ("INSERT VIDEO 4 URL", 25),
- ("INSERT VIDEO 5 URL", 25),
- ("INSERT VIDEO 6 URL", 25),
- ("INSERT VIDEO 7 URL", 25),
- ("INSERT VIDEO 8 URL", 25),
- ("INSERT VIDEO 9 URL", 25)
- ]
- if not os.path.isdir('videos'):
- os.mkdir('videos')
- count = 0
- for vid in videos:
- subprocess.run(["youtube-dl", "-o",f"videos/{count}.%(ext)s",vid[0]])
- count += 1
- files = sorted(list(map(lambda x: str(Path(x)),glob.glob("./videos/*.*"))))
- subprocess.run([
- "ffmpeg", "-i", files[0], "-i", files[1], "-i", files[2], "-i", files[3], "-i", files[4], "-i", files[5], "-i", files[6], "-i", files[7], "-i", files[8],
- "-filter_complex", '[0:v]scale=300:300[a];[1:v]scale=300:300[b];[2:v]scale=300:300[c];[3:v]scale=300:300[d];[4:v]scale=300:300[e];[5:v]scale=300:300[f];[6:v]scale=300:300[g];[7:v]scale=300:300[h];[8:v]scale=300:300[i];' +
- f'[0:a]atrim={videos[0][1]}:{videos[0][1]+7}[j];[1:a]atrim={videos[1][1]}:{videos[1][1]+7}[k];[2:a]atrim={videos[2][1]}:{videos[2][1]+7}[l];[3:a]atrim={videos[3][1]}:{videos[3][1]+7}[m];[4:a]atrim={videos[4][1]}:{videos[4][1]+7}[n];[5:a]atrim={videos[5][1]}:{videos[5][1]+7}[o];[6:a]atrim={videos[6][1]}:{videos[6][1]+7}[p];[7:a]atrim={videos[7][1]}:{videos[7][1]+7}[q];[8:a]atrim={videos[8][1]}:{videos[8][1]+7}[r];' +
- '[j][k][l][m][n][o][p][q][r]concat=n=9:v=0:a=1[s];' +
- f'[a][b][c]hstack=inputs=3[t]; [d][e][f]hstack=inputs=3[u]; [g][h][i]hstack=inputs=3[v]; [t][u][v]vstack=inputs=3[w]; [w]setpts=N/FRAME_RATE/TB[x]; [x]trim=0:{totallength}[y]; [s]asetpts=N/SR/TB[z]',
- '-map', '[y]', '-map', '[z]', '-c:a', 'libvorbis', '-c:v', 'libvpx', "-q:a","6","-b:v","1000k","-shortest", 'output3.webm'
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement