I am doing object detection on a video and so far I've gotten the coordinates of the objects in the video.
now I want to crop the video frame by frame given the location/coordinates of the object
My code so far:
def crop_video(input_video_path, output_video_path, coordinate_list):
crop_ratio = 'crop=%s:%s:%s:%s' % (coordinate_list[0][0], coordinate_list[0][1], coordinate_list[0][2],coordinate_list[0][3])
subprocess.run(['ffmpeg', '-i', input_video_path, '-filter:v', crop_ratio, output_video_path])
the crop_video
function crops the entire video using only the first index in the coordinate_list list. How can I improve the code to change dynamically.
coordinate list looks similar to this:
coordinate_list = [[147.5, 253.5, 927, 107],
[147.5, 253.5, 927, 107],
[147.0, 257.5, 928, 102],
[148.5, 258.5, 925, 104],
[148.5, 258.5, 925, 104],
[155.0, 258.5, 918, 103],
[155.0, 258.5, 918, 103],]
How can I dynamically change the crop width, height, x and y using the coordinate_list. I am new to using ffmpeg