Skip to content

Instantly share code, notes, and snippets.

@mushoku-ningen
Last active July 25, 2023 13:41
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 mushoku-ningen/ecdbb5cd2d098797d9fe97a19d5221d4 to your computer and use it in GitHub Desktop.
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
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