Last active
July 25, 2023 13:41
-
-
Save mushoku-ningen/ecdbb5cd2d098797d9fe97a19d5221d4 to your computer and use it in GitHub Desktop.
ffmpeg combining videos generalizing this https://ffmpeg.org/ffmpeg-filters.html#toc-Examples-138
This file contains 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
import os | |
def command(filename,x=2,y=2): | |
command="ffmpeg" | |
for i in range(x*y): | |
command+=f" -i '{filename}'" | |
command+=' -filter_complex "' | |
for i in range(x*y): | |
command+=f"[{i}]".format(i) | |
command+=f"xstack=inputs={x*y}:" | |
#### generalizing this part "layout=0_0|0_h0|w0_0|w0_h0" | |
def a(grid,num,s): | |
if num==0: | |
return "0" | |
res="" | |
for i in range(num): | |
res+=f"{s}{i}+" | |
return res[0:-1] | |
add1="" | |
for h in range(x): | |
for w in range(y): | |
add1+=a(x,h,'w') | |
add1+="_" | |
add1+=a(y,w,'h') | |
add1+="|" | |
################################################### | |
#scale to width 1280 and auto height | |
#command+=f'layout={add1}[v];[v]scale=1280:-1[g]" -map "[g]" -map "0:a" o.{filename.split(".")[-1]}' | |
command+=f'layout={add1}[v];" -map "[v]" -map "0:a" o.{filename.split(".")[-1]}' | |
print(command) | |
return command | |
os.system(command(filename='output.webm',x=3,y=3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment