Required:
- ffmpeg installed;
- ffprobe installed;
Using: python video-wall.py video-file nxn
- video-file - path to video file
- nxn - matriz of video wall
Ex.: python video-wall.py videoToCrop.mp4 2x3
import sys, re, os.path, os, json | |
patternVideoWall = re.compile("\d*[x]\d*"); | |
args = sys.argv | |
videoFile = args[1]; | |
matrizVideoWall = args[2]; | |
if not patternVideoWall.match(matrizVideoWall): | |
print "Error video wall parameters. Ex. python video-wall.py videoFile.mp4 2x2"; | |
sys.exit(); | |
if not os.path.exists(videoFile): | |
print "Error video file doesn't exists"; | |
sys.exit(); | |
matrizVideoWall = matrizVideoWall.split('x'); | |
rows = int(matrizVideoWall[0]); | |
columns = int(matrizVideoWall[1]); | |
cmdGetSettings = "ffprobe -v error -show_entries stream=width,height \-of default=noprint_wrappers=1 " + videoFile; | |
videoFileSettings = os.popen(cmdGetSettings).read().split("\n"); | |
width = int(videoFileSettings[0].replace("width=","")); | |
height = int(videoFileSettings[1].replace("height=","")); | |
widthPart = width/columns; | |
heightPart = height/rows; | |
print widthPart; | |
print heightPart; | |
for row in range(1, rows + 1): | |
print "Row " + str(row); | |
for column in range(1, columns+1): | |
xIni = str((column - 1) * widthPart); | |
yIni = str((row - 1) * heightPart); | |
cmdCropVideo = "ffmpeg -i " + videoFile + " -filter:v crop="+ str(widthPart) + ":" + str(heightPart) + ":" + xIni + ":" + yIni + " out_" + str(row) + "_" + str(column) + ".mp4 -y"; | |
print cmdCropVideo; | |
result = os.popen(cmdCropVideo).read(); | |
print result; |