<p>I recommend <a href="http://avisynth.nl/index.php/Main_Page" rel="nofollow noreferrer">AVISynth</a> (a script based video editor for VirtualDub) and the <a href="http://www.guthspot.se/video/deshaker.htm" rel="nofollow noreferrer">DeShaker</a> plugin.</p>

<p>You can learn a minimum amount about AVISynth and simply load DeShaker, have it stabilize on the person's body and it will follow them smoothly as they move.</p>

<p>You will have a finished product that is stabilized as a bonus. </p>

<p>You can also learn more about AVISynth, establish precise crops that are animated to follow the person, and get a perfect result (based on the quality of the input). You can set your moves with frame and pixel accuracy by typing numbers into the script and reloading the frame in VirtualDub.</p>

<p>It might be worth 5 mins. exploring those links to see if you want to try another video editor. </p>

<p>If one of the current video editors you've installed has image stabilization you can try it, but DeShaker is one of the better free ones (as of a year ago) that I've used.</p>

CC BY-SA 3.0
2017-12-13T16:03:16.260Z
Thanks Rob. I was hoping to preferably to get a solution for Linux as this is my much more powerful machine. My Windows PC is not really for video editing. Still, I will check AviSynth out if everything else fails.

In the meanwhile please suggest more stuff!
user3185993
CC BY-SA 3.0
2017-12-13T16:08:17.523Z
OK, while there may be a port of AVISynth the deshaker plugin isn't available for Linux. Can you use stabilization in the Linux Video Editors that you have, choose the person and crop to the moving frame?
Rob
CC BY-SA 3.0
2017-12-20T13:56:28.637Z
I did a bit of research. Basically image stabilization is technically what I need but the way it is done (for example in Blender: https://www.youtube.com/watch?v=DpIXqAepfxY) is more of an automated approach. As I said, I want to move a fixed crop window around manually to crop out a person. If the person does not move I just define the crop window position for the first frame of the video.
user3185993
CC BY-SA 3.0
2017-12-20T13:56:33.187Z
If the person moves a lot I have to define new crop window positions for several frames of the video and the cropping is interpolated between the specified crop window positions. It seems really simple and I can do it with A LOT of effort using only ffmpeg. The same job could be done in seconds having a GUI that supports defining a fixed crop window and moving it around.
user3185993
CC BY-SA 3.0
2017-12-12T23:30:59.670Z
2017-12-12T23:30:59.670Z
Rob
<p>The best and easiest (and only) way that I have found to do this in Linux is to use OBS with the window size set to the desired crop output dimension. Add your video file as an input source, arrange the video output relative to the OBS window so that the desired rectangle that you wish to display initially is lined up with the OBS window, and start recording in OBS at the same time as you start playing the video. While the video plays, use your mouse to drag the video around in real time so that the part which you wish to view continues to line up with the OBS window. If you have a slow moving subject and you only need a couple of slow pans within a 3-minute window, this works really well. It can be a little more annoying if your crop area shifts around a lot.</p>
<p>If you only need to crop in one dimension (e.g. 1920x1080 to 1080x1080) then you can temporarily lock your mouse pointer to move in one direction only, at least on X (not sure about Wayland). For example:</p>
<pre><code>xinput set-prop 'Microsoft Corporation Microsoft ® Laser Mouse 6000' 'Coordinate Transformation Matrix' 1 0 1 0 0 0 0 0 1
</code></pre>
<p>is what I use with my hardware (the idea for this comes from <a href="https://askubuntu.com/questions/1153697/screen-detection-and-mouse-reverse-x-y-axis">https://askubuntu.com/questions/1153697/screen-detection-and-mouse-reverse-x-y-axis</a>). To get back normal mouse movement:</p>
<pre><code>xinput set-prop 'Microsoft Corporation Microsoft ® Laser Mouse 6000' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
</code></pre>
<p>Of course the details will differ if you have a different mouse. This is useful while recording your crop because it prevents you from dragging the video in any direction other than the direction in which you need to pan.</p>

CC BY-SA 4.0
2022-01-23T15:48:42.457Z
2022-01-23T15:48:42.457Z
djao
<p>I have 3840 × 2160 videos where I want to cut out a moving person on stage (e.g. music video). The crop area is fixed (1080 x 1920). The problem is, the person is moving around. Not much, but in a 3min. video the crop area would move a couple of times.</p>

<p>Example: Frame 0-889, area(500,34,1080,1920) - Frame 950-1735, area (800,10,1080,1920) - Frame 1820-2530, area(600,40,1080,1920)</p>

<p>I gave some example numbers above. The solution should interpolate the crop area between Frame 889 and Frame 950; Frame 1735 and Frame 1820. Ideally I would like to define those areas in a visual editor which allows me to move a fixed size crop rectangle for the Frames and coordinates given above.</p>

<p>Optionally I could also figure out the crop areas without visual help and then use that data to crop the video in something like ffmpeg (although I don't know how to do this properly including the interpolation step).</p>

<p>I am on Linux and tried different video editors but their crop filters are not useful to solve my task. I have Windows available but no commercial editing software installed at the moment.</p>

<p>Thanks for the help!</p>

CC BY-SA 4.0
2019-04-24T05:11:39.110Z
related https://video.stackexchange.com/questions/15417/moving-crop-in-video has laborious but workable ffmpeg command line solution
matt wilkie
<ffmpeg><video-editor><post-production>
Crop a video with a moving crop area of fixed size
user3185993
# Crop a video with a moving crop area of fixed size

(Asked by: username_0 on 2017-12-12)

I have 3840 × 2160 videos where I want to cut out a moving person on stage (e.g. music video). The crop area is fixed (1080 x 1920). The problem is, the person is moving around. Not much, but in a 3min. video the crop area would move a couple of times.

Example: Frame 0-889, area(500,34,1080,1920) - Frame 950-1735, area (800,10,1080,1920) - Frame 1820-2530, area(600,40,1080,1920)

I gave some example numbers above. The solution should interpolate the crop area between Frame 889 and Frame 950; Frame 1735 and Frame 1820. Ideally I would like to define those areas in a visual editor which allows me to move a fixed size crop rectangle for the Frames and coordinates given above.

Optionally I could also figure out the crop areas without visual help and then use that data to crop the video in something like ffmpeg (although I don't know how to do this properly including the interpolation step).

I am on Linux and tried different video editors but their crop filters are not useful to solve my task. I have Windows available but no commercial editing software installed at the moment.

Thanks for the help!

**Tags:** ffmpeg, video-editor, post-production

> **Comments:**
> **username_1**: related https://video.stackexchange.com/questions/15417/moving-crop-in-video has laborious but workable ffmpeg command line solution  

---

## 2 answers

### Answer by username_2 on 2017-12-12. Score: 2

I recommend [AVISynth](http://avisynth.nl/index.php/Main_Page) (a script based video editor for VirtualDub) and the [DeShaker](http://www.guthspot.se/video/deshaker.htm) plugin.

You can learn a minimum amount about AVISynth and simply load DeShaker, have it stabilize on the person's body and it will follow them smoothly as they move.

You will have a finished product that is stabilized as a bonus.

You can also learn more about AVISynth, establish precise crops that are animated to follow the person, and get a perfect result (based on the quality of the input). You can set your moves with frame and pixel accuracy by typing numbers into the script and reloading the frame in VirtualDub.

It might be worth 5 mins. exploring those links to see if you want to try another video editor.

If one of the current video editors you've installed has image stabilization you can try it, but DeShaker is one of the better free ones (as of a year ago) that I've used.

> **Comments:**
> **username_0**: Thanks username_2. I was hoping to preferably to get a solution for Linux as this is my much more powerful machine. My Windows PC is not really for video editing. Still, I will check AviSynth out if everything else fails.  In the meanwhile please suggest more stuff!  
> **username_2**: OK, while there may be a port of AVISynth the deshaker plugin isn't available for Linux. Can you use stabilization in the Linux Video Editors that you have, choose the person and crop to the moving frame?  
> **username_0**: I did a bit of research. Basically image stabilization is technically what I need but the way it is done (for example in Blender: https://www.youtube.com/watch?v=DpIXqAepfxY) is more of an automated approach. As I said, I want to move a fixed crop window around manually to crop out a person. If the person does not move I just define the crop window position for the first frame of the video.  
> **username_0**: If the person moves a lot I have to define new crop window positions for several frames of the video and the cropping is interpolated between the specified crop window positions. It seems really simple and I can do it with A LOT of effort using only ffmpeg. The same job could be done in seconds having a GUI that supports defining a fixed crop window and moving it around.  

---

### Answer by username_3 on 2022-01-23. Score: 0

The best and easiest (and only) way that I have found to do this in Linux is to use OBS with the window size set to the desired crop output dimension. Add your video file as an input source, arrange the video output relative to the OBS window so that the desired rectangle that you wish to display initially is lined up with the OBS window, and start recording in OBS at the same time as you start playing the video. While the video plays, use your mouse to drag the video around in real time so that the part which you wish to view continues to line up with the OBS window. If you have a slow moving subject and you only need a couple of slow pans within a 3-minute window, this works really well. It can be a little more annoying if your crop area shifts around a lot.
If you only need to crop in one dimension (e.g. 1920x1080 to 1080x1080) then you can temporarily lock your mouse pointer to move in one direction only, at least on X (not sure about Wayland). For example:
xinput set-prop 'Microsoft Corporation Microsoft ® Laser Mouse 6000' 'Coordinate Transformation Matrix' 1 0 1 0 0 0 0 0 1

is what I use with my hardware (the idea for this comes from https://askubuntu.com/questions/1153697/screen-detection-and-mouse-reverse-x-y-axis). To get back normal mouse movement:
xinput set-prop 'Microsoft Corporation Microsoft ® Laser Mouse 6000' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1

Of course the details will differ if you have a different mouse. This is useful while recording your crop because it prevents you from dragging the video in any direction other than the direction in which you need to pan.


---

