Dynamically Change Video Crop Width, Height, X And Y Using Ffmpeg
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/coordinate
Solution 1:
Use the sendcmd filter.
Make
commands.txt
:0 crop w 148, crop h 254, crop x 925, crop y 108; 0.04 crop w 142, crop h 252, crop x 927, crop y 107; 0.08 crop w 147, crop h 258, crop x 928, crop y 102;
- The text does not have to be formatted exactly as above. I added line breaks for readability. You can place each timestamp on its own line if you prefer.
- sendcmd works with timestamps, not frame numbers. This example shows frames 1-3 and assumes a frame rate of 25 (1/25 = 0.04).
- Not all filters can use sendcmd (or the audio version asendcmd). See output of
ffmpeg -filters
. If the filter supports (a)sendcmd it will have aT
preceding the filter name in the list. - Not all filter options can be used with sendcmd. See FFmpeg Filters Documentation and look for "Commands".
Run
ffmpeg
:ffmpeg -i input.mp4 -filter_complex "[0:v]sendcmd=f=commands.txt,crop" output_%03d.png
Post a Comment for "Dynamically Change Video Crop Width, Height, X And Y Using Ffmpeg"