Answers.Body: <p>This being the first result I got from searching, I decided to use WYSIWYG answer and write a bash script that simplifies this significantly (at least for me):</p>
  <pre class="lang-bash prettyprint-override"><code>#!/bin/bash
  if [[ -z $6 ]];then
          printf &quot;Usage:\n&quot;
          printf &quot;        $0 [input file] [output file] [top crop] [bottom crop] [left crop] [right crop]\n&quot;
          printf &quot;Any edges you do not want to crop, enter 0.\n&quot;
          printf &quot;For example, to crop 10 pixels from the top, 11 from the botom, none from the left and 8 from the right:\n&quot;
          printf &quot;        $0 input-file.jpg output-file.jpg 10 11 0 8\n&quot;
          exit 2
  fi
  
  inpFile=$1
  outFile=$2
  tCrop=$3
  bCrop=$4
  lCrop=$5
  rCrop=$6
  let xCrop=$lCrop+$rCrop
  let yCrop=$tCrop+$bCrop
  
  ffmpeg -i $inpFile -vf crop=iw-$xCrop:ih-$yCrop:$lCrop:$tCrop $outFile
  exit $?
  </code></pre>
  <p>Run this script without any arguments to get a how-to printout.</p>
  <p>When you specify your crop values for each edge, it does the math for you.  Saves you from having to add up your top &amp; bottom / left &amp; right crops.</p>
  <p>A full explanation for the ffmpeg's <code>crop</code> formatting is below. Each of these values represent what they should be in the <em>output</em> file.</p>
  <p><code>crop=w:h:x:y</code></p>
  <p>w = width.</p>
  <p>h = height.</p>
  <p>x = X (horizontal) position the output should start at, from the left. AKA how many pixels to lose from the left.</p>
  <p>y = Y (vertical) position the output should start at, from the top. AKA how many pixels to lose from the top.</p>
  <p>As you can see, width and height support &quot;iw&quot; and &quot;ih&quot; respectively to keep those values from the input file. And, you can perform math on those within the command. That's where the &quot;iw-30&quot; comes from in WYSIWYG's answer.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-16T09:17:59.653Z
Answers.Text: Thank you so much! This one works and is the correct answer!
Answers.UserDisplayName: Harry McKenzie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-16T09:25:08.897Z
Answers.Text: I love how you break down the different components now you can easily and flexibly set which sides to crop.
Answers.UserDisplayName: Harry McKenzie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-28T21:15:48.803Z
Answers.LastActivityDate: 2023-08-28T21:19:36.863Z
Answers.LastEditDate: 2023-08-28T21:19:36.863Z
Answers.UserDisplayName: TDGalea
Answers.Body: <p>Based on <a href="https://ffmpeg.org/ffmpeg-filters.html#toc-crop" rel="nofollow noreferrer">https://ffmpeg.org/ffmpeg-filters.html#toc-crop</a></p>
  <p>should it be <code>crop=in_w:in_h-70:0:40</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-10T12:32:05.110Z
Answers.Text: can you please explain how you came to that solution.
Answers.UserDisplayName: paperskyline
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-10T11:23:22.770Z
Answers.LastActivityDate: 2021-12-10T11:23:22.770Z
Answers.UserDisplayName: xer-rex
Answers.Body: <p>After two days of looking for an answer to this question, I found out the logic behind it and I'll share it here, because this topic looks as the best place for it, I hope it helps people understand it more easily through my explanation than through all the other explanations I found with Google on many sites and forums.</p>
  <p>So I wanted to crop different number of rows - 20 from the top and 10 from the bottom - of a video file, and I used this command:</p>
  <pre><code>ffmpeg -i input.file -vf crop=iw:ih-30:0:10 -c:v av1_nvenc -c:a copy output.file
  </code></pre>
  <p>The logic of the <code>crop=iw:ih-30:0:10</code> is as follows:</p>
  <ul>
  <li><p><code>iw</code> - input width of the video, which stays the same as the original</p>
  </li>
  <li><p><code>ih</code> - input height of the video, which we want to cut</p>
  </li>
  <li><p><code>30</code> - the total number of rows we want to remove</p>
  </li>
  <li><p><code>0 </code>- I don't know why we have to input this, but we just have to</p>
  </li>
  <li><p><code>10</code> - the number of rows, which we want to cut from the bottom</p>
  </li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-01T10:48:11.667Z
Answers.LastActivityDate: 2022-12-01T21:11:43.287Z
Answers.LastEditDate: 2022-12-01T21:11:43.287Z
Answers.UserDisplayName: WYSIWYG
Body: <p>i have a mkv file and its resolution is 1280x720. when i calculated the crop using Handbrake, it shows that i need to crop <strong>40 from top</strong> and <strong>30 from bottom</strong>.
  So far i know how to crop equal amount from top and bottom, but i cannot understand how to specify that the crop values for top and bottom are different</p>
  <p>so far i tried <code>crop=in_w:in_h-80</code> which cuts 40 from top and 40 from bottom, but i want to cut only 30 from bottom</p>
  <p>thank you</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-16T09:19:53.900Z
Comments.Text: I find it weird that you marked the answer by WYSIWYG as the right answer when it should have been https://video.stackexchange.com/a/36794/38948 by TDGalea which works and is easier to understand as well.
Comments.UserDisplayName: Harry McKenzie
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-11-22T13:39:59.057Z
Comments.Text: @HarryMcKenzie I disagree and feel that the accepted answer adequately explains the solution. Also, the other answer provided 1) uses Perl so makes assumptions about language and 2) explains the answer similarly, albeit with less information.
Comments.UserDisplayName: Dan Atkinson
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-11-23T16:08:11.037Z
Comments.Text: @HarryMcKenzie - the OP accepted WYSIWYG's answer, which means it is the best one for them. You may prefer the other one, but it isn't your call to make
Comments.UserDisplayName: Dr Mayhem
Tags: <ffmpeg>
Title: ffmpeg - how do i crop different values from top and bottom
UserDisplayName: paperskyline
ThreadText: # ffmpeg - how do i crop different values from top and bottom
  
  (Asked by: username_0 on 2021-12-10)
  
  i have a mkv file and its resolution is 1280x720. when i calculated the crop using Handbrake, it shows that i need to crop **40 from top** and **30 from bottom**.
  So far i know how to crop equal amount from top and bottom, but i cannot understand how to specify that the crop values for top and bottom are different
  
  so far i tried `crop=in_w:in_h-80` which cuts 40 from top and 40 from bottom, but i want to cut only 30 from bottom
  
  thank you
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: I find it weird that you marked the answer by username_6 as the right answer when it should have been https://video.stackexchange.com/a/36794/38948 by username_4 which works and is easier to understand as well.  
  > **username_2**: @username_1 I disagree and feel that the accepted answer adequately explains the solution. Also, the other answer provided 1) uses Perl so makes assumptions about language and 2) explains the answer similarly, albeit with less information.  
  > **username_3**: @username_1 - the OP accepted username_6's answer, which means it is the best one for them. You may prefer the other one, but it isn't your call to make  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_6 on 2022-12-01. Score: 4 | Accepted answer
  
  After two days of looking for an answer to this question, I found out the logic behind it and I'll share it here, because this topic looks as the best place for it, I hope it helps people understand it more easily through my explanation than through all the other explanations I found with Google on many sites and forums.
  
  So I wanted to crop different number of rows - 20 from the top and 10 from the bottom - of a video file, and I used this command:
  
  ```
  ffmpeg -i input.file -vf crop=iw:ih-30:0:10 -c:v av1_nvenc -c:a copy output.file
  
  ```
  
  The logic of the `crop=iw:ih-30:0:10` is as follows:
  
  * `iw` - input width of the video, which stays the same as the original
  * `ih` - input height of the video, which we want to cut
  * `30` - the total number of rows we want to remove
  * `0` - I don't know why we have to input this, but we just have to
  * `10` - the number of rows, which we want to cut from the bottom
  
  
  ---
  
  ### Answer by username_4 on 2023-08-28. Score: 1
  
  This being the first result I got from searching, I decided to use username_6 answer and write a bash script that simplifies this significantly (at least for me):
  
  ```bash
  #!/bin/bash
  if [[ -z $6 ]];then
          printf "Usage:\n"
          printf "        $0 [input file] [output file] [top crop] [bottom crop] [left crop] [right crop]\n"
          printf "Any edges you do not want to crop, enter 0.\n"
          printf "For example, to crop 10 pixels from the top, 11 from the botom, none from the left and 8 from the right:\n"
          printf "        $0 input-file.jpg output-file.jpg 10 11 0 8\n"
          exit 2
  fi
  
  inpFile=$1
  outFile=$2
  tCrop=$3
  bCrop=$4
  lCrop=$5
  rCrop=$6
  let xCrop=$lCrop+$rCrop
  let yCrop=$tCrop+$bCrop
  
  ffmpeg -i $inpFile -vf crop=iw-$xCrop:ih-$yCrop:$lCrop:$tCrop $outFile
  exit $?
  
  ```
  
  Run this script without any arguments to get a how-to printout.
  
  When you specify your crop values for each edge, it does the math for you. Saves you from having to add up your top & bottom / left & right crops.
  
  A full explanation for the ffmpeg's `crop` formatting is below. Each of these values represent what they should be in the *output* file.
  
  `crop=w:h:x:y`
  
  w = width.
  
  h = height.
  
  x = X (horizontal) position the output should start at, from the left. AKA how many pixels to lose from the left.
  
  y = Y (vertical) position the output should start at, from the top. AKA how many pixels to lose from the top.
  
  As you can see, width and height support "iw" and "ih" respectively to keep those values from the input file. And, you can perform math on those within the command. That's where the "iw-30" comes from in username_6's answer.
  
  > **Comments:**
  > **username_1**: Thank you so much! This one works and is the correct answer!  
  > **username_1**: I love how you break down the different components now you can easily and flexibly set which sides to crop.  
  
  ---
  
  ### Answer by username_5 on 2021-12-10. Score: 0
  
  Based on <https://ffmpeg.org/ffmpeg-filters.html#toc-crop>
  
  should it be `crop=in_w:in_h-70:0:40`
  
  > **Comments:**
  > **username_0**: can you please explain how you came to that solution.  
  
  ---
  
  