33import numpy as np
44from musicalgestures ._utils import MgImage , generate_outfilename , ffmpeg_cmd , get_length
55
6- def mg_grid (self , height = 300 , rows = 3 , cols = 3 , padding = 0 , margin = 0 , target_name = None , overwrite = False , return_array = False ):
6+ def mg_grid (self , height = 300 , rows = 3 , columns = 3 , padding = 0 , margin = 0 , target_name = None , overwrite = False , return_array = False ):
77 """
88 Generates frame strip video preview using ffmpeg.
99
1010 Args:
1111 height (int, optional): Frame height, width is adjusted automatically to keep the correct aspect ratio. Defaults to 300.
1212 rows (int, optional): Number of rows of the grid. Defaults to 3.
13- cols (int, optional): Number of columns of the grid. Defaults to 3.
13+ columns (int, optional): Number of columns of the grid. Defaults to 3.
1414 padding (int, optional): Padding size between the frames. Defaults to 0.
1515 margin (int, optional): Margin size for the grid. Defaults to 0.
1616 target_name ([type], optional): Target output name for the grid image. Defaults to None.
@@ -33,19 +33,19 @@ def mg_grid(self, height=300, rows=3, cols=3, padding=0, margin=0, target_name=N
3333 # Get the number of frames
3434 cap = cv2 .VideoCapture (self .filename )
3535 nb_frames = int (cap .get (cv2 .CAP_PROP_FRAME_COUNT ))
36- nth_frame = int (nb_frames / (rows * cols ))
36+ nth_frame = int (nb_frames / (rows * columns ))
3737
3838 # Define the grid specifications
3939 width = int ((float (self .width ) / self .height ) * height )
40- grid = f"select=not(mod(n\,{ nth_frame } )),scale={ width } :{ height } ,tile={ cols } x{ rows } :padding={ padding } :margin={ margin } "
40+ grid = f"select=not(mod(n\,{ nth_frame } )),scale={ width } :{ height } ,tile={ columns } x{ rows } :padding={ padding } :margin={ margin } "
4141
4242 # Declare the ffmpeg commands
4343 if return_array :
4444 cmd = ['ffmpeg' , '-y' , '-i' , self .filename , '-frames' , '1' , '-q:v' , '0' , '-vf' , grid ]
4545 process = ffmpeg_cmd (cmd , get_length (self .filename ), pb_prefix = 'Rendering video frame grid:' , pipe = 'load' )
4646
4747 # Convert bytes to array and convert from BGR to RGB
48- array = np .frombuffer (process .stdout , dtype = np .uint8 ).reshape ([height * rows , int (width * cols ), 3 ])[...,::- 1 ]
48+ array = np .frombuffer (process .stdout , dtype = np .uint8 ).reshape ([height * rows , int (width * columns ), 3 ])[...,::- 1 ]
4949
5050 return array
5151 else :
0 commit comments