Programming/Etc.

[FFmpeg] 비디오 자르기(video crop)

꾸준희 2022. 1. 24. 17:26
728x90
반응형

 

command

ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" -c:a copy output.mp4

 

 

  • -i
    • input.mp4 specifies the input video (input.mp4 being the input / original video in this case)
  • -filter:v (can be abbreviated to -vf)
    • specifies we're using a video filter
  • "crop=W:H:X:Y" 
    • means we're using the "crop" video filter, with 4 values:
      • w the width of the output video (so the width of the cropped region), which defaults to the input video width (input video width = iw, which is the same as in_w); out_w may also be used instead of w
      • h the height of the output video (the height of the cropped region), which defaults to the input video height (input video height = ih, with in_h being another notation for the same thing); out_h may also be used instead of h
      • x the horizontal position from where to begin cropping, starting from the left (with the absolute left margin being 0)
      • y the vertical position from where to begin cropping, starting from the top of the video (the absolute top being 0)
  • output.mp4 
    • is the new, cropped video file

 

 

A few notes:
The filter will automatically center the crop if x and y are omitted, so x defaults to (iw-w)/2, and y to (ih-h)/2

  • There is also an optional keep_aspect option that you can set to 1 to force the output display aspect ratio to be the same of the input (example usage: "crop=100:100:0:0:keep_aspect=1"). This won't work with images, that's why you don't see a separate example with screenshot here
  • FFmpeg gets the original input video width (iw) and height (ih) values automatically, so you can perform mathematical operations using those values (e.g. iw/2 for half the input video width, or ih-100 to subtract 100 pixels from the input video height).

 

 

 

 

 

 

참고자료 1 : https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-with-ffmpeg

 

How can I crop a video with ffmpeg?

I have an MP4 file of a screen recording that I need to crop down. How can I accomplish this without using expensive tools like Adobe Premier or Final Cut? I prefer ffmpeg because I have used it be...

video.stackexchange.com

 

 

참고자료 2 : https://www.linuxuprising.com/2020/01/ffmpeg-how-to-crop-videos-with-examples.html

 

FFmpeg: How To Crop Videos, With Examples

This article explains how to crop videos using FFmpeg (with examples) from the command line. It's especially useful for batch cropping multiple videos, but some (me included) might also prefer this over a fully fledged video editor for doing some video cro

www.linuxuprising.com

 

728x90
반응형