Answers.Body: <p>Use the <a href="https://ffmpeg.org/ffmpeg-filters.html#crop" rel="noreferrer"><code>crop</code> filter</a>:</p>
  <pre><code>ffmpeg -i in.mp4 -vf &quot;crop=out_w:out_h:x:y&quot; out.mp4
  </code></pre>
  <p>Where the options are as follows:</p>
  <ul>
  <li>use &quot;-vf&quot; or -&quot;filter:v&quot; - depending on your version of ffmpeg/avconv</li>
  <li><code>out_w</code> is the width of the output rectangle</li>
  <li><code>out_h</code> is the height of the output rectangle</li>
  <li><code>x</code> and <code>y</code> specify the top left corner of the output rectangle (coordinates start at (0,0) in the top left corner of the input)</li>
  </ul>
  <h2>Original image</h2>
  <p><img src="https://i.sstatic.net/LAW6C.png" alt="original image" /><br />
  <sub>Original 320x240 image</sub></p>
  <h2>How out_w, out_h, w and h fit into the picture</h2>
  <p><a href="https://i.sstatic.net/oZXFK.jpg" rel="noreferrer"><img src="https://i.sstatic.net/oZXFK.jpg" alt="enter image description here" /></a></p>
  <h2>Example 1</h2>
  <p><img src="https://i.sstatic.net/vqW5O.png" alt="80x60" /></p>
  <p>To crop a 80×60 section, starting from position (200, 100):</p>
  <pre><code>ffmpeg -i in.mp4 -vf &quot;crop=80:60:200:100&quot; -c:a copy out.mp4
  </code></pre>
  <ul>
  <li>The audio is <a href="http://ffmpeg.org/ffmpeg.html#Stream-copy" rel="noreferrer">stream copied</a> in this example, so re-encoding is avoided.</li>
  </ul>
  <h2>Example 2</h2>
  <p><img src="https://i.sstatic.net/IwvRw.png" alt="bottom right quarter" /></p>
  <p>To crop the bottom right quarter:</p>
  <pre><code>ffmpeg -i in.mp4 -vf &quot;crop=in_w/2:in_h/2:in_w/2:in_h/2&quot; -c:a copy out.mp4
  </code></pre>
  <p>This is the same as:</p>
  <pre><code>ffmpeg -i in.mp4 -vf &quot;crop=320/2:240/2:320/2:240/2&quot; -c:a copy out.mp4
  </code></pre>
  <p>Which is the same as:</p>
  <pre><code>ffmpeg -i in.mp4 -vf &quot;crop=160:120:160:120&quot; -c:a copy out.mp4
  </code></pre>
  <ul>
  <li>You can refer to the input image size with <code>in_w</code> and <code>in_h</code> as shown in this first example. The output width and height can also be used with <code>out_w</code> and <code>out_h</code>.</li>
  </ul>
  <h2>Example 3</h2>
  <p><img src="https://i.sstatic.net/l1ILH.png" alt="20 pixels from the top, and 20 from the bottom" /></p>
  <p>Crop 20 pixels from the top, and 20 from the bottom:</p>
  <pre><code> ffmpeg -i in.mp4 -vf &quot;crop=in_w:in_h-40&quot; -c:a copy out.mp4
  </code></pre>
  <ul>
  <li>The filter will automatically center the crop if <code>x</code> and <code>y</code> are omitted such as in this example.</li>
  </ul>
  <h2>Previewing</h2>
  <p>You can take a crop (heh heh) and preview it live with <code>ffplay</code>:</p>
  <pre><code>ffplay -i input -vf &quot;crop=in_w:in_h-40&quot;
  </code></pre>
  <p>This way you can experiment and adjust your cropping without the need to encode, view, repeat.</p>
  <h2>Notes</h2>
  <ul>
  <li><p><a href="http://ffmpeg.org/ffmpeg-filters.html#crop" rel="noreferrer"><code>crop</code> filter documentation</a></p>
  </li>
  <li><p>Default encoder for MP4 is <code>libx264</code> (H.264 video) or <code>mpeg4</code> (MPEG-4 Part 2 video) depending on your <code>ffmpeg</code> build. See <a href="https://trac.ffmpeg.org/wiki/Encode/H.264" rel="noreferrer">FFmpeg Wiki: H.264 Video Encoding Guide</a> for more info.</p>
  </li>
  <li><p>Instead of cropping and re-encoding, consider cropping upon playback. This is possible with any player worth using.</p>
  </li>
  <li><p>Ancient <code>ffmpeg</code> builds used <code>-croptop</code>, <code>-cropbottom</code>, <code>-cropleft</code>, <code>-cropright</code> options instead of the <code>crop</code> filter. If this is the case for you then <a href="http://ffmpeg.org/download.html" rel="noreferrer">get a modern <code>ffmpeg</code></a>. Development is very active and there is no reason to use an antique.</p>
  </li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-16T13:52:11.980Z
Answers.Text: This works with 'avconv' now.
Answers.UserDisplayName: Joce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-24T16:18:47.243Z
Answers.Text: I have an 1923x1080 and want 1920x1080. This the the commend I tried: `/Users/kukodajanos/Workspace/ffmpeg -i /Users/kukodajanos/Desktop/video_640x480-2.mp4 -filter:v "crop=1920:1080:0:0" -c:a copy /Users/kukodajanos/Desktop/video_640x480-4.mp4` but the original movie is returned.
Answers.UserDisplayName: János
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-12T10:37:38.537Z
Answers.Text: @Joce JFYI avconv is part of libav — a fork of ffmpeg
Answers.UserDisplayName: andrybak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-14T09:58:45.940Z
Answers.Text: worth to mention this technique (with the `crop` filter) re-encodes the video, see https://stackoverflow.com/questions/33378548/ffmpeg-crop-a-video-without-losing-the-quality if re-encoding matters for you
Answers.UserDisplayName: abernier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-15T00:35:15.163Z
Answers.Text: edited to change the outdated `-filter:v` to the more up to date and simpler to type `-vf`. Cheers!
Answers.UserDisplayName: Elder Geek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-28T23:53:08.820Z
Answers.Text: I'm getting some automatic scale somehow. I guess it comes from the aspect :/ For instance, when I do "crop=80:60:200:100", my final video ends up being 97x60. I tried adding setsar=1:1 next to crop, but then it seems to scale it before crop, so the final size is 80x60, but the contents are the wrong aspect.
Answers.UserDisplayName: endavid
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-06T21:38:37.590Z
Answers.Text: If you're trying to remove black bars around your video (piallarbox, letterbox, windowbox etc.) use `cropdetect` first to have ffmpeg print cropping parameters for you: `ffmpeg.exe -i vid.mp4 -vf cropdetect out.mp4`
Answers.UserDisplayName: Shayan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-10T10:53:26.380Z
Answers.Text: For those who wonder, `-vf` is an alias for `-filter:v`.
Answers.UserDisplayName: Rastapopoulos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-06T04:32:01.700Z
Answers.Text: When I use this solution, my output video has a much lower bitrate. Any idea why?
Answers.UserDisplayName: amzon-ex
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-06T17:20:47.963Z
Answers.Text: You can adjust the output audio/video bitrate with the proper parameters. Please refer to this answer to see a procedure: https://superuser.com/a/521684/83875, basically you "`use the -b:v and -b:a options, respectively. You can use abbreviations like K for kBit/s and M for MBit/s.`". Credits to @slhck.
Answers.UserDisplayName: Geppettvs D'Constanzo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-21T05:58:06.753Z
Answers.Text: If your video is long, you might want to let ffmpeg sample a passage with cropdetect to give you optimum values before you encode. Here's an example that gets the crop value for a 14 minute passage starting at 33 and a half minutes into the video: ffmpeg -ss 00:33:30 -t 00:14:00 -i video.mp4 -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1
Answers.UserDisplayName: Trellis
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-04T21:53:18.030Z
Answers.Text: This crop filter works great! In order to determine the bounding box needed to crop a video, I exported a video frame to an image with ffmpeg. Then open the image with GIMP where I can draw a bounding box for the area I wanted to crop the video and then I can get the X,Y,W, H info from the pointer window. Ask if this is not clear enough.
Answers.UserDisplayName: Harry
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-05T23:15:02.333Z
Answers.Text: @GeppettvsD'Constanzo You could consider starting a new question if any particular part that is not clear for you.
Answers.UserDisplayName: Harry
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-28T18:22:02.920Z
Answers.Text: would it be possible to do the crop just for a specific duration in the video?
Answers.UserDisplayName: Alex
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-02T19:26:31.517Z
Answers.Text: @Alex, sure. You just need to insert the proper parameters in the command line. See this answer for information: https://askubuntu.com/a/59388/9598
Answers.UserDisplayName: Geppettvs D'Constanzo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-02T19:27:52.127Z
Answers.Text: Basically you add `-ss 00:00:30` in order to say the  point where to start the cut, and `-t 00:00:05` to say the duration you may wish.
Answers.UserDisplayName: Geppettvs D'Constanzo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-05T10:18:20.063Z
Answers.Text: Does this remove the cropped data, or is the data recoverable? I want to crop sensitive data.
Answers.UserDisplayName: HappyFace
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-05T19:12:50.093Z
Answers.Text: The process will deliver a new video file which will contain only the portion of video you cropped. No additional recoverable data will be available in that file. Nevertheless, you will keep the original video file alongside with the new cropped file.
Answers.UserDisplayName: Geppettvs D'Constanzo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-04T17:05:47.913Z
Answers.Text: `-c:a copy` isn't included in the first command presented. What do they do?
Answers.UserDisplayName: user2023370
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-04T16:17:45.890Z
Answers.Text: how would i convert the result to gif?
Answers.UserDisplayName: Kong
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-06T19:10:31.667Z
Answers.Text: @Kong, you can either use `ffmpeg -i VIDEO-ORIGINAL.EXT IMAGE.GIF` or `convert VIDEO-ORIGINAL.EXT IMAGE.GIF`, in both cases `VIDEO-ORIGINAL` is the source file name and `.EXT` is the file extension. The `IMAGE.GIF` can be anything you may wish but keep the `.GIF` (lowercase perhaps) to get the results. Please have in mind the `ffmpeg` will be faster but the `convert` will provide you with a high quality GIF animation. Additional parameters can be used to improve the final gif animation performance.
Answers.UserDisplayName: Geppettvs D'Constanzo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-01T21:52:40.103Z
Answers.Text: Your answer has mixed terminology. At the top you say that crop has `x:y` at the end, but later you define w,h at the start.
Answers.UserDisplayName: Aaron Franke
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-05T19:38:51.123Z
Answers.Text: @AaronFranke, yes, you're right. X and Y are for coordinates, W and H is to clarify on Width and Height respectively. Thanks for pointing that. The answer has suffered additions, updates and corrections from the community. Nowadays is quite different from what I answered first.
Answers.UserDisplayName: Geppettvs D'Constanzo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-30T13:42:50.743Z
Answers.Text: Sorry in the second image the variables are wrong. `w` should be swapped with `out_w` and `h` should be swapped with `out_h`
Answers.UserDisplayName: robertspierre
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2012-08-15T02:53:29.937Z
Answers.LastActivityDate: 2024-02-06T19:47:06.553Z
Answers.LastEditDate: 2024-02-06T19:47:06.553Z
Answers.UserDisplayName: Geppettvs D'Constanzo
Body: <p>I have an MP4 file of a screen recording that I need to crop. How can I do this with <code>ffmpeg</code>?</p>
  
Tags: <video><editing><ffmpeg>
Title: How can I crop a video with ffmpeg?
UserDisplayName: stephenwade
ThreadText: # How can I crop a video with ffmpeg?
  
  (Asked by: username_0 on 2012-08-13)
  
  I have an MP4 file of a screen recording that I need to crop. How can I do this with `ffmpeg`?
  
  **Tags:** video, editing, ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2012-08-15. Score: 607 | Accepted answer
  
  Use the [`crop` filter](https://ffmpeg.org/ffmpeg-filters.html#crop):
  
  ```
  ffmpeg -i in.mp4 -vf "crop=out_w:out_h:x:y" out.mp4
  
  ```
  
  Where the options are as follows:
  
  * use "-vf" or -"filter:v" - depending on your version of ffmpeg/avconv
  * `out_w` is the width of the output rectangle
  * `out_h` is the height of the output rectangle
  * `x` and `y` specify the top left corner of the output rectangle (coordinates start at (0,0) in the top left corner of the input)
  
  ## Original image
  
  ![original image](https://i.sstatic.net/LAW6C.png)  
  Original 320x240 image
  
  ## How out\_w, out\_h, w and h fit into the picture
  
  [![enter image description here](https://i.sstatic.net/oZXFK.jpg)](https://i.sstatic.net/oZXFK.jpg)
  
  ## Example 1
  
  ![80x60](https://i.sstatic.net/vqW5O.png)
  
  To crop a 80×60 section, starting from position (200, 100):
  
  ```
  ffmpeg -i in.mp4 -vf "crop=80:60:200:100" -c:a copy out.mp4
  
  ```
  
  * The audio is [stream copied](http://ffmpeg.org/ffmpeg.html#Stream-copy) in this example, so re-encoding is avoided.
  
  ## Example 2
  
  ![bottom right quarter](https://i.sstatic.net/IwvRw.png)
  
  To crop the bottom right quarter:
  
  ```
  ffmpeg -i in.mp4 -vf "crop=in_w/2:in_h/2:in_w/2:in_h/2" -c:a copy out.mp4
  
  ```
  
  This is the same as:
  
  ```
  ffmpeg -i in.mp4 -vf "crop=320/2:240/2:320/2:240/2" -c:a copy out.mp4
  
  ```
  
  Which is the same as:
  
  ```
  ffmpeg -i in.mp4 -vf "crop=160:120:160:120" -c:a copy out.mp4
  
  ```
  
  * You can refer to the input image size with `in_w` and `in_h` as shown in this first example. The output width and height can also be used with `out_w` and `out_h`.
  
  ## Example 3
  
  ![20 pixels from the top, and 20 from the bottom](https://i.sstatic.net/l1ILH.png)
  
  Crop 20 pixels from the top, and 20 from the bottom:
  
  ```
   ffmpeg -i in.mp4 -vf "crop=in_w:in_h-40" -c:a copy out.mp4
  
  ```
  
  * The filter will automatically center the crop if `x` and `y` are omitted such as in this example.
  
  ## Previewing
  
  You can take a crop (heh heh) and preview it live with `ffplay`:
  
  ```
  ffplay -i input -vf "crop=in_w:in_h-40"
  
  ```
  
  This way you can experiment and adjust your cropping without the need to encode, view, repeat.
  
  ## Notes
  
  * [`crop` filter documentation](http://ffmpeg.org/ffmpeg-filters.html#crop)
  * Default encoder for MP4 is `libx264` (H.264 video) or `mpeg4` (MPEG-4 Part 2 video) depending on your `ffmpeg` build. See [FFmpeg Wiki: H.264 Video Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264) for more info.
  * Instead of cropping and re-encoding, consider cropping upon playback. This is possible with any player worth using.
  * Ancient `ffmpeg` builds used `-croptop`, `-cropbottom`, `-cropleft`, `-cropright` options instead of the `crop` filter. If this is the case for you then [get a modern `ffmpeg`](http://ffmpeg.org/download.html). Development is very active and there is no reason to use an antique.
  
  > **Comments:**
  > **username_2**: This works with 'avconv' now.  
  > **username_3**: I have an 1923x1080 and want 1920x1080. This the the commend I tried: `/Users/kukodajanos/Workspace/ffmpeg -i /Users/kukodajanos/Desktop/video_640x480-2.mp4 -filter:v "crop=1920:1080:0:0" -c:a copy /Users/kukodajanos/Desktop/video_640x480-4.mp4` but the original movie is returned.  
  > **username_4**: @username_2 JFYI avconv is part of libav — a fork of ffmpeg  
  > **username_5**: worth to mention this technique (with the `crop` filter) re-encodes the video, see https://stackoverflow.com/questions/33378548/ffmpeg-crop-a-video-without-losing-the-quality if re-encoding matters for you  
  > **username_6**: edited to change the outdated `-filter:v` to the more up to date and simpler to type `-vf`. Cheers!  
  > **username_7**: I'm getting some automatic scale somehow. I guess it comes from the aspect :/ For instance, when I do "crop=80:60:200:100", my final video ends up being 97x60. I tried adding setsar=1:1 next to crop, but then it seems to scale it before crop, so the final size is 80x60, but the contents are the wrong aspect.  
  > **username_8**: If you're trying to remove black bars around your video (piallarbox, letterbox, windowbox etc.) use `cropdetect` first to have ffmpeg print cropping parameters for you: `ffmpeg.exe -i vid.mp4 -vf cropdetect out.mp4`  
  > **username_9**: For those who wonder, `-vf` is an alias for `-filter:v`.  
  > **username_10**: When I use this solution, my output video has a much lower bitrate. Any idea why?  
  > **username_1**: You can adjust the output audio/video bitrate with the proper parameters. Please refer to this answer to see a procedure: https://superuser.com/a/521684/83875, basically you "`use the -b:v and -b:a options, respectively. You can use abbreviations like K for kBit/s and M for MBit/s.`". Credits to @slhck.  
  > **username_11**: If your video is long, you might want to let ffmpeg sample a passage with cropdetect to give you optimum values before you encode. Here's an example that gets the crop value for a 14 minute passage starting at 33 and a half minutes into the video: ffmpeg -ss 00:33:30 -t 00:14:00 -i video.mp4 -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1  
  > **username_12**: This crop filter works great! In order to determine the bounding box needed to crop a video, I exported a video frame to an image with ffmpeg. Then open the image with GIMP where I can draw a bounding box for the area I wanted to crop the video and then I can get the X,Y,W, H info from the pointer window. Ask if this is not clear enough.  
  > **username_12**: @username_1 You could consider starting a new question if any particular part that is not clear for you.  
  > **username_13**: would it be possible to do the crop just for a specific duration in the video?  
  > **username_1**: @username_13, sure. You just need to insert the proper parameters in the command line. See this answer for information: https://askubuntu.com/a/59388/9598  
  > **username_1**: Basically you add `-ss 00:00:30` in order to say the  point where to start the cut, and `-t 00:00:05` to say the duration you may wish.  
  > **username_14**: Does this remove the cropped data, or is the data recoverable? I want to crop sensitive data.  
  > **username_1**: The process will deliver a new video file which will contain only the portion of video you cropped. No additional recoverable data will be available in that file. Nevertheless, you will keep the original video file alongside with the new cropped file.  
  > **username_15**: `-c:a copy` isn't included in the first command presented. What do they do?  
  > **username_16**: how would i convert the result to gif?  
  > **username_1**: @username_16, you can either use `ffmpeg -i VIDEO-ORIGINAL.EXT IMAGE.GIF` or `convert VIDEO-ORIGINAL.EXT IMAGE.GIF`, in both cases `VIDEO-ORIGINAL` is the source file name and `.EXT` is the file extension. The `IMAGE.GIF` can be anything you may wish but keep the `.GIF` (lowercase perhaps) to get the results. Please have in mind the `ffmpeg` will be faster but the `convert` will provide you with a high quality GIF animation. Additional parameters can be used to improve the final gif animation performance.  
  > **username_17**: Your answer has mixed terminology. At the top you say that crop has `x:y` at the end, but later you define w,h at the start.  
  > **username_1**: @username_17, yes, you're right. X and Y are for coordinates, W and H is to clarify on Width and Height respectively. Thanks for pointing that. The answer has suffered additions, updates and corrections from the community. Nowadays is quite different from what I answered first.  
  > **username_18**: Sorry in the second image the variables are wrong. `w` should be swapped with `out_w` and `h` should be swapped with `out_h`  
  
  ---
  
  