title: Moviepy - Crop video with frame (region of interest) moving from left to right with time
body: <p>I'm working on creating GIF from video clips automatically on the server using MoviePy. The library helped in various transformations and trimming of video to create GIFs.  </p>
  
  <p>In my current project, I have a video clip with lots of moving objects making it difficult to do automatic tracking of the region of interest. 
  <em>(A quick gif below shows the scene, though the background there can be easy to eliminate and do the tracking of object. But let's say tracking object is out of scope of the project).</em></p>
  
  <p>As shown in the gif below the red rectangle is the region of interest which moves from left to right with time. 
  I want to crop that region and create a GIF. </p>
  
  <p><a href="https://i.stack.imgur.com/rGfeK.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/rGfeK.gif" alt="enter image description here"></a></p>
  
  <p>I'm using MoviePy where I cropped a rectangle from a video to create a gif. But the rectangle is fixed at its original coordinates position. I'm looking for a way to move that rectangle with time and crop it to create a GIF.</p>
  
  <pre><code>clip = (VideoFileClip("my_video.mp4")
           .subclip((1,10.1),(1,14.9))
           .resize(0.5)
           .crop(x1=145,y1=110,x2=400,y2=810)) 
  
  clip.write_gif("my_gif.gif")
  </code></pre>
  
  <p>How to add time factor so that this coordinates change with the time.</p>
  
  <p>Any suggestions welcome. </p>