Commands to cut videos in half horizontally or vertically, and rejoin them later
Asked Answered
B

1

10

How can I use ffmpeg to cut video in half, vertically or horizontally by resolution; so for a 640 x 480 video, I want to separate that into two halves with a resolution of 320 x 480, or to separate it into two halves horizontally with a resolution of 640 x 240; and afterward, I need to be able to join the separated videos again to make a single video with the original resolution. How can this be done?

Billiot answered 30/9, 2018 at 21:12 Comment(0)
V
9

separate into two halves

Use the crop filter:

vertical (top/bottom)

ffmpeg -i input -filter_complex "[0]crop=iw:ih/2:0:0[top];[0]crop=iw:ih/2:0:oh[bottom]" -map "[top]" top.mp4 -map "[bottom]" bottom.mp4

horizontal (left/right)

ffmpeg -i input -filter_complex "[0]crop=iw/2:ih:0:0[left];[0]crop=iw/2:ih:ow:0[right]" -map "[left]" left.mp4 -map "[right]" right.mp4

join the separated videos

Use the vstack/hstack filters as shown in Vertically or horizontally stack several videos using ffmpeg?

Vaden answered 1/10, 2018 at 18:58 Comment(2)
For the horizontal portion, Shouldn't the "right" portion be ow+1 instead of ow? If using ow, then you start (for instance) a 1440x1080p video at 0 for 720px for left side and 720 for 720px for right, when that would only take you to 1439th pixel, or am I wrong? (ie: you're duplicating the 720th vertical row of pixels when you put them back together)Asta
This is fantastic and works for VR360! Thank you!Rist

© 2022 - 2024 — McMap. All rights reserved.