Search code examples
videoffmpegcrop

ffmpeg - offset cropped part of a video


Problem:

  • I have a video that is made of two separate Videos next to each other
-------------------------
|   -------             |
|   |vid2 |             |
|   |     |    vid1     |
|   -------             |
|                       |
|                       |
|                       |
-------------------------
  • the 2nd video is delayed in respect to the first, that's why I want to offset the second video by the difference

For the cropping part, I figured using the crop-option might work, but I don't quite know, how to put the video back together, so that the cropped part of the video ends up at the same place as before, i.e. how to set the position, while overlaying the 2 videos.


Solution

  • Let's say the vid2 window is 2.5 seconds late, is of size WxH and is located at (X,Y) from top-left corner of full frame.

    You would use

    ffmpeg -i input -vf "split=2[v1][v2];[v2]trim=2.5,setpts=PTS-STARTPTS,crop=W:H:X:Y[v2];[v1][v2]overlay=X:Y" -c:a copy out.mp4