videoffmpegcropvideo-editing

crop, rearrange middle of video frame with ffmpeg


I have a few hundred video files from a security camera. Let's say here's the full frame:

+---------------------+-------------------------+
| 2018-10-10 03:02:12 |                         |
+---------------------+                         |
|                         +--------------+      |
|                         | IMPORTANT    |      |
|                         +--------------+      |
|                                               |
+-----------------------------------------------+

I have 2 areas that I want to keep: the date and the inner box. I know how to crop to either of them, for example:

ffmpeg -i in.mp4 -filter:v "crop=1120:320:40:60" -c:a copy out.mpg

However what I'd like to be able to do is to rearrange the frame to get this in the output:

+---------------------+
| 2018-10-10 03:02:12 |
+------+--------------+
| X X X|  IMPORTANT   |
+------+--------------+

(X X X would be just black, or if that's hard to do then it can be whatever part of the original video) Any idea how can I do this?


Solution

  • You can crop the two segments and then stack them vertically.

    ffmpeg -i in.mp4 -filter_complex "[0]split=2[tc][imp];[tc]crop=1120:320:40:60[tc];
                                      [imp]crop=800:400:1300:150,pad=1120:ih:1120-iw:0[imp];
                                      [tc][imp]vstack" -c:a copy out.mpg
    

    When stacked vertically, the segments have to be the same width so (black) padding is added.